Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit ac61c3a

Browse files
committedApr 17, 2024·
Add basic test
1 parent 195efeb commit ac61c3a

File tree

3 files changed

+102
-0
lines changed

3 files changed

+102
-0
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
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 static class ConvertDllsToWebCilTests
14+
{
15+
private static ConvertDllsToWebCil task;
16+
private static List<BuildErrorEventArgs> errors;
17+
18+
static ConvertDllsToWebCilTests()
19+
{
20+
task = new ConvertDllsToWebCil();
21+
var buildEngine = new Mock<IBuildEngine>();
22+
errors = new List<BuildErrorEventArgs>();
23+
buildEngine.Setup(x => x.LogErrorEvent(It.IsAny<BuildErrorEventArgs>())).Callback<BuildErrorEventArgs>(e => errors.Add(e));
24+
task.BuildEngine = buildEngine.Object;
25+
}
26+
27+
[Fact]
28+
public static void TestEmptyInput()
29+
{
30+
string input = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName() + ".dll");
31+
32+
try
33+
{
34+
File.Create(input).Dispose();
35+
36+
task.Candidates = new ITaskItem[] { new TaskItem(input) };
37+
task.IsEnabled = true;
38+
task.OutputPath = task.IntermediateOutputPath = Path.GetTempPath();
39+
40+
bool result = task.Execute();
41+
42+
Assert.False(result);
43+
Assert.Single(errors);
44+
Assert.Contains(input, errors[0].Message);
45+
}
46+
finally
47+
{
48+
File.Delete(input);
49+
}
50+
}
51+
52+
}
53+
}
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

+31
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)
Please sign in to comment.