From 25c4f573b525f70dcd789a80ef9637ca28ff2d96 Mon Sep 17 00:00:00 2001 From: Vlada Shubina Date: Thu, 24 Jun 2021 12:07:55 +0300 Subject: [PATCH] tests for dotnet/templating#3325 --- .../DotnetNewInstantiate.cs | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/test/dotnet-new3.UnitTests/DotnetNewInstantiate.cs b/test/dotnet-new3.UnitTests/DotnetNewInstantiate.cs index f66aac57e825..08347faf4d29 100644 --- a/test/dotnet-new3.UnitTests/DotnetNewInstantiate.cs +++ b/test/dotnet-new3.UnitTests/DotnetNewInstantiate.cs @@ -361,5 +361,59 @@ public void CanInstantiateTemplateWithSecondShortName() .And.NotHaveStdErr() .And.HaveStdOutContaining("The template \"ASP.NET Core Web App\" was created successfully."); } + + [Fact] + public void CanInstantiateTemplate_WithBinaryFile_FromFolder() + { + string workingDirectory = TestUtils.CreateTemporaryFolder(); + string home = TestUtils.CreateTemporaryFolder("Home"); + string templateLocation = TestUtils.GetTestTemplateLocation("TemplateWithBinaryFile"); + + Helpers.InstallTestTemplate(templateLocation, _log, workingDirectory, home); + + new DotnetNewCommand(_log, "TestAssets.TemplateWithBinaryFile") + .WithCustomHive(home) + .WithWorkingDirectory(workingDirectory) + .Execute() + .Should().Pass(); + + string sourceImage = Path.Combine(templateLocation, "image.png"); + string targetImage = Path.Combine(workingDirectory, "image.png"); + + Assert.True(File.Exists(targetImage)); + + Assert.Equal( + new FileInfo(sourceImage).Length, + new FileInfo(targetImage).Length); + Assert.True(TestUtils.CompareFiles(sourceImage, targetImage), $"The content of {sourceImage} and {targetImage} is not same."); + } + + [Fact] + public void CanInstantiateTemplate_WithBinaryFile_FromPackage() + { + string templateLocation = TestUtils.GetTestTemplateLocation("TemplateWithBinaryFile"); + string workingDirectory = TestUtils.CreateTemporaryFolder(); + string home = TestUtils.CreateTemporaryFolder("Home"); + + using var packageManager = new PackageManager(); + string packageLocation = packageManager.PackTestTemplatesNuGetPackage(); + Helpers.InstallNuGetTemplate(packageLocation, _log, workingDirectory, home); + + new DotnetNewCommand(_log, "TestAssets.TemplateWithBinaryFile") + .WithCustomHive(home) + .WithWorkingDirectory(workingDirectory) + .Execute() + .Should().Pass(); + + string sourceImage = Path.Combine(templateLocation, "image.png"); + string targetImage = Path.Combine(workingDirectory, "image.png"); + + Assert.True(File.Exists(targetImage)); + + Assert.Equal( + new FileInfo(sourceImage).Length, + new FileInfo(targetImage).Length); + Assert.True(TestUtils.CompareFiles(sourceImage, targetImage), $"The content of {sourceImage} and {targetImage} is not same."); + } } }