Skip to content

Commit 9d15d5d

Browse files
committed
Add basic tests
1 parent 7d42fec commit 9d15d5d

File tree

3 files changed

+124
-0
lines changed

3 files changed

+124
-0
lines changed
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
using Microsoft.Build.Framework;
5+
using Microsoft.Build.Utilities;
6+
using Moq;
7+
using System.Collections.Generic;
8+
using System.IO;
9+
using Xunit;
10+
11+
namespace Microsoft.NET.Sdk.WebAssembly.Tests
12+
{
13+
public class ConvertDllsToWebCilTests
14+
{
15+
private ConvertDllsToWebCil task = new ConvertDllsToWebCil();
16+
private List<BuildErrorEventArgs> errors = new List<BuildErrorEventArgs>();
17+
18+
public ConvertDllsToWebCilTests()
19+
{
20+
var buildEngine = new Mock<IBuildEngine>();
21+
buildEngine.Setup(x => x.LogErrorEvent(It.IsAny<BuildErrorEventArgs>())).Callback<BuildErrorEventArgs>(e => errors.Add(e));
22+
task.BuildEngine = buildEngine.Object;
23+
}
24+
25+
[Fact]
26+
public void TestEmptyInput()
27+
{
28+
string input = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName() + ".dll");
29+
30+
try
31+
{
32+
File.Create(input).Dispose();
33+
34+
task.Candidates = new ITaskItem[] { new TaskItem(input) };
35+
task.IsEnabled = true;
36+
task.OutputPath = task.IntermediateOutputPath = Path.GetTempPath();
37+
38+
bool result = task.Execute();
39+
40+
Assert.False(result);
41+
Assert.Single(errors);
42+
Assert.Contains(input, errors[0].Message);
43+
}
44+
finally
45+
{
46+
File.Delete(input);
47+
}
48+
}
49+
50+
[Fact]
51+
public void TestInvalidDirectoryInput()
52+
{
53+
string input = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName() + ".dll");
54+
55+
try
56+
{
57+
Directory.CreateDirectory(input);
58+
59+
task.Candidates = new ITaskItem[] { new TaskItem(input) };
60+
task.IsEnabled = true;
61+
task.OutputPath = task.IntermediateOutputPath = Path.GetTempPath();
62+
63+
bool result = task.Execute();
64+
65+
Assert.False(result);
66+
Assert.Single(errors);
67+
Assert.Contains(input, errors[0].Message);
68+
}
69+
finally
70+
{
71+
Directory.Delete(input);
72+
}
73+
}
74+
}
75+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>$(NetCoreAppToolCurrent)</TargetFramework>
5+
<Nullable>enable</Nullable>
6+
<IsTestProject>true</IsTestProject>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<PackageReference Include="Microsoft.Build.Utilities.Core" Version="$(MicrosoftBuildFrameworkVersion)" />
11+
<PackageReference Include="Moq" Version="$(MoqVersion)" />
12+
</ItemGroup>
13+
14+
<ItemGroup>
15+
<ProjectReference Include="..\Microsoft.NET.Sdk.WebAssembly.Pack.Tasks\Microsoft.NET.Sdk.WebAssembly.Pack.Tasks.csproj" />
16+
</ItemGroup>
17+
18+
</Project>

src/tasks/tests/tests.sln

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.11.34815.271
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.NET.Sdk.WebAssembly.Pack.Tasks.Tests", "Microsoft.NET.Sdk.WebAssembly.Pack.Tasks.Tests.csproj", "{035240F3-31CE-409E-8D55-2A89ADE522D6}"
7+
EndProject
8+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.NET.Sdk.WebAssembly.Pack.Tasks", "..\Microsoft.NET.Sdk.WebAssembly.Pack.Tasks\Microsoft.NET.Sdk.WebAssembly.Pack.Tasks.csproj", "{4C68406D-BBFC-4637-A634-917C0621A883}"
9+
EndProject
10+
Global
11+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
12+
Debug|Any CPU = Debug|Any CPU
13+
Release|Any CPU = Release|Any CPU
14+
EndGlobalSection
15+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
16+
{035240F3-31CE-409E-8D55-2A89ADE522D6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
17+
{035240F3-31CE-409E-8D55-2A89ADE522D6}.Debug|Any CPU.Build.0 = Debug|Any CPU
18+
{035240F3-31CE-409E-8D55-2A89ADE522D6}.Release|Any CPU.ActiveCfg = Release|Any CPU
19+
{035240F3-31CE-409E-8D55-2A89ADE522D6}.Release|Any CPU.Build.0 = Release|Any CPU
20+
{4C68406D-BBFC-4637-A634-917C0621A883}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
21+
{4C68406D-BBFC-4637-A634-917C0621A883}.Debug|Any CPU.Build.0 = Debug|Any CPU
22+
{4C68406D-BBFC-4637-A634-917C0621A883}.Release|Any CPU.ActiveCfg = Release|Any CPU
23+
{4C68406D-BBFC-4637-A634-917C0621A883}.Release|Any CPU.Build.0 = Release|Any CPU
24+
EndGlobalSection
25+
GlobalSection(SolutionProperties) = preSolution
26+
HideSolutionNode = FALSE
27+
EndGlobalSection
28+
GlobalSection(ExtensibilityGlobals) = postSolution
29+
SolutionGuid = {15EFCF6A-C86C-474F-BBAD-F2DB4B3DBAA3}
30+
EndGlobalSection
31+
EndGlobal

0 commit comments

Comments
 (0)