Skip to content

Commit

Permalink
Add basic test
Browse files Browse the repository at this point in the history
  • Loading branch information
danmoseley committed Apr 17, 2024
1 parent cb0eae4 commit f0a7f3f
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 0 deletions.
53 changes: 53 additions & 0 deletions src/tasks/tests/ConvertDllsToWebCilTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;
using Moq;
using System.Collections.Generic;
using System.IO;
using Xunit;

namespace Microsoft.NET.Sdk.WebAssembly.Tests
{
public static class ConvertDllsToWebCilTests
{
private static ConvertDllsToWebCil task;
private static List<BuildErrorEventArgs> errors;

static ConvertDllsToWebCilTests()
{
task = new ConvertDllsToWebCil();
var buildEngine = new Mock<IBuildEngine>();
errors = new List<BuildErrorEventArgs>();
buildEngine.Setup(x => x.LogErrorEvent(It.IsAny<BuildErrorEventArgs>())).Callback<BuildErrorEventArgs>(e => errors.Add(e));
task.BuildEngine = buildEngine.Object;
}

[Fact]
public static void TestEmptyInput()
{
string input = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName() + ".dll");

try
{
File.Create(input).Dispose();

task.Candidates = new ITaskItem[] { new TaskItem(input) };
task.IsEnabled = true;
task.OutputPath = task.IntermediateOutputPath = Path.GetTempPath();

bool result = task.Execute();

Assert.False(result);
Assert.Single(errors);
Assert.Contains(input, errors[0].Message);
}
finally
{
File.Delete(input);
}
}

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>$(NetCoreAppToolCurrent)</TargetFramework>
<Nullable>enable</Nullable>
<IsTestProject>true</IsTestProject>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Build.Utilities.Core" Version="$(MicrosoftBuildFrameworkVersion)" />
<PackageReference Include="Moq" Version="$(MoqVersion)" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Microsoft.NET.Sdk.WebAssembly.Pack.Tasks\Microsoft.NET.Sdk.WebAssembly.Pack.Tasks.csproj" />
</ItemGroup>

</Project>

0 comments on commit f0a7f3f

Please sign in to comment.