Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Confuser2.slnx
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
<Project Path="Tests/CompressorWithResx.Test/CompressorWithResx.Test.csproj" />
<Project Path="Tests/CompressorWithResx/CompressorWithResx.csproj" />
<Project Path="Tests/Confuser.Core.Test/Confuser.Core.Test.csproj" />
<Project Path="Tests/Confuser.MSBuild.Tasks.Tests/Confuser.MSBuild.Tasks.Tests.csproj" Id="a3483e80-7831-4877-bc65-e5b1738a9242" />
<Project Path="Tests/Confuser.Renamer.Test/Confuser.Renamer.Test.csproj" />
<Project Path="Tests/Confuser.UnitTest/Confuser.UnitTest.csproj" />
<Project Path="Tests/IncorrectRedirectToGac.Test/IncorrectRedirectToGac.Test.csproj" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net472</TargetFramework>
<IsPackable>false</IsPackable>
<OutputType>Exe</OutputType>
</PropertyGroup>

<ItemGroup>
<None Include="Resources\confuser-empty.expected.crproj">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="Resources\confuser.expected.crproj">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="Resources\confuser.src.crproj">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>

<ItemGroup Label="Nuget Dependencies">
<PackageReference Include="Moq" Version="4.20.72" />
<PackageReference Include="Microsoft.Build.Tasks.Core" Version="17.11.48" PrivateAssets="all" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Confuser.UnitTest\Confuser.UnitTest.csproj" />
<ProjectReference Include="..\..\Confuser.MSBuild.Tasks\Confuser.MSBuild.Tasks.csproj" />
</ItemGroup>

<ItemGroup Label="Nuget Dependencies">
<PackageReference Include="xunit.v3" Version="3.2.2" />
</ItemGroup>

</Project>
96 changes: 96 additions & 0 deletions Tests/Confuser.MSBuild.Tasks.Tests/CreateProjectTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Confuser.UnitTest;
using Microsoft.Build.Framework;
using Moq;
using Xunit;

namespace Confuser.MSBuild.Tasks.Tests {
public class CreateProjectTests {
private readonly ITestOutputHelper outputHelper;
private Mock<IBuildEngine> buildEngine;
private List<BuildErrorEventArgs> errors;

public CreateProjectTests(ITestOutputHelper outputHelper) {
this.outputHelper = outputHelper ?? throw new ArgumentNullException(nameof(outputHelper));
this.buildEngine = new Mock<IBuildEngine>();
this.errors = new List<BuildErrorEventArgs>();
this.buildEngine.Setup(x => x.LogErrorEvent(It.IsAny<BuildErrorEventArgs>())).Callback<BuildErrorEventArgs>(e => errors.Add(e));
}



[Fact]
[Trait("Category", "MSBuildIntegration")]
public void CreateNewProjectIfNoSourceProject() {
var assembly = new Mock<ITaskItem>();
assembly.SetupAllProperties();
assembly.Object.ItemSpec = $".\\bin\\debug\\test.dll";
var baseDirectory = new Mock<ITaskItem>();
baseDirectory.SetupAllProperties();
baseDirectory.Object.ItemSpec = $".";
var resultProject = new Mock<ITaskItem>();
resultProject.SetupAllProperties();
resultProject.Object.ItemSpec = $"result-empty.crproj";

var task = new CreateProjectTask();
task.AssemblyPath = assembly.Object;
task.BuildEngine = buildEngine.Object;
task.ResultProject = resultProject.Object;
task.References = Array.Empty<ITaskItem>();

//Act
var success = task.Execute();

//Assert
Assert.True(success);
Assert.Empty(errors);
Assert.True(File.Exists(task.ResultProject.ItemSpec));
Assert.Collection(
File.ReadLines(".\\Resources\\confuser-empty.expected.crproj"),
File.ReadLines(task.ResultProject.ItemSpec)
.Select<string, Action<string>>((string actual) => (string expected) => Assert.Equal(expected, actual))
.ToArray()
);
}

[Fact]
[Trait("Category", "MSBuildIntegration")]
public void BaseDirectoryOverridenTest() {
var sourceProject = new Mock<ITaskItem>();
sourceProject.SetupAllProperties();
sourceProject.Object.ItemSpec = $".\\Resources\\confuser.src.crproj";
var assembly = new Mock<ITaskItem>();
assembly.SetupAllProperties();
assembly.Object.ItemSpec = $".\\bin\\debug\\test.dll";
var baseDirectory = new Mock<ITaskItem>();
baseDirectory.SetupAllProperties();
baseDirectory.Object.ItemSpec = $".";
var resultProject = new Mock<ITaskItem>();
resultProject.SetupAllProperties();
resultProject.Object.ItemSpec = $"result.crproj";

var task = new CreateProjectTask();
task.AssemblyPath = assembly.Object;
task.SourceProject = sourceProject.Object;
task.BuildEngine = buildEngine.Object;
task.ResultProject = resultProject.Object;
task.References = Array.Empty<ITaskItem>();

//Act
var success = task.Execute();

//Assert
Assert.True(success);
Assert.Empty(errors);
Assert.True(File.Exists(task.ResultProject.ItemSpec));
Assert.Collection(File.ReadLines(task.ResultProject.ItemSpec),
File.ReadLines(".\\Resources\\confuser.expected.crproj")
.Select<string, Action<string>>((string actual) => (string expected) => Assert.Equal(expected, actual))
.ToArray()
);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<project outputDir="" baseDir=".\bin\debug" xmlns="http://confuser.codeplex.com">
<module path="test.dll" />
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<project outputDir="c:\obfuscation\output" baseDir=".\bin\debug" debug="true" xmlns="http://confuser.codeplex.com">
<module path="c:\obfuscation\input\test.dll" />
<module path="c:\obfuscation\input\test2.dll" />
<module path="test.dll" />
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<project outputDir="c:\obfuscation\output" baseDir="c:\obfuscation\input" debug="true" xmlns="http://confuser.codeplex.com">
<module path="c:\obfuscation\input\test.dll" />
<module path="c:\obfuscation\input\test2.dll" />
<probePath>c:\obfuscation\input\bin</probePath>
</project>
Loading