|
| 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 | +} |
0 commit comments