Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
vlada-shubina committed Jun 30, 2021
1 parent 1a7ddb5 commit 79fc82a
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,4 @@
<Content Include="nupkg_templates\**" />
<None Include="nupkg_templates\**" CopyToOutputDirectory="Always" />
</ItemGroup>
<ItemGroup>
<None Remove="test_templates\PostActions\UnknownPostAction\.template.config\template.json" />
<None Remove="test_templates\PostActions\UnknownPostAction\Program.cs" />
<None Remove="test_templates\PostActions\RestoreNuGet\Invalid\.template.config\template.json" />
<None Remove="test_templates\PostActions\RestoreNuGet\Invalid\Invalid.csproj" />
<None Remove="test_templates\PostActions\RestoreNuGet\Invalid\Program.cs" />
<None Remove="test_templates\PostActions\UnknownPostAction\UnknownPostAction.csproj" />
<None Remove="test_templates\TemplateWithFileRenameDate\.template.config\template.json" />
<None Remove="test_templates\TemplateWithFileRenameDate\date_name.cs" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"author": "Test Asset",
"classifications": [ "Test Asset" ],
"name": "TemplateWithBinaryFile",
"generatorVersions": "[1.0.0.0-*)",
"groupIdentity": "TestAssets.TemplateWithBinaryFile",
"precedence": "100",
"identity": "TestAssets.TemplateWithBinaryFile",
"shortName": "TestAssets.TemplateWithBinaryFile"
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
54 changes: 54 additions & 0 deletions test/dotnet-new3.UnitTests/DotnetNewInstantiate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
}
}
}

0 comments on commit 79fc82a

Please sign in to comment.