Skip to content

Commit

Permalink
Add a couple of tests around loading assembly dependencies
Browse files Browse the repository at this point in the history
Related to dotnet#658.

This change introduced a couple of basic tests to verify that we can find a
task assembly's dependencies when they are located in the same directory. In
order to do this, it adds a couple of projects to produce assemblies just for
this test: TaskWithDependency.dll, and Dependency.dll.
  • Loading branch information
tmeschter committed Aug 3, 2016
1 parent f59dcfb commit 3628b26
Show file tree
Hide file tree
Showing 14 changed files with 499 additions and 7 deletions.
4 changes: 2 additions & 2 deletions Samples/TaskUsageLogger/TaskUsageLogger.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<RootNamespace>TaskUsageLogger</RootNamespace>
<AssemblyName>TaskUsageLogger</AssemblyName>
<FileAlignment>512</FileAlignment>
<CopyNuGetImplementations>false</CopyNuGetImplementations>
<CopyNuGetImplementations>false</CopyNuGetImplementations>
</PropertyGroup>
<!-- Default configurations to help VS understand the configurations -->
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' " />
Expand All @@ -33,7 +33,7 @@
</ProjectReference>
<ProjectReference Include="..\..\src\Utilities\Microsoft.Build.Utilities.csproj">
<Project>{828566EE-6F6A-4EF4-98B0-513F7DF9C628}</Project>
<Name>Microsoft.Build.Utilities.Core</Name>
<Name>Microsoft.Build.Utilities</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
Expand Down
119 changes: 119 additions & 0 deletions src/MSBuild.sln
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,14 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "nuget", "nuget", "{144F834D
nuget\Microsoft.Build.Utilities.Core.nuspec = nuget\Microsoft.Build.Utilities.Core.nuspec
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Test", "Test", "{B6FB6ADC-98C7-4AFB-9BBF-CB3679DF86B9}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Projects", "Projects", "{1EFEE954-8884-41A2-9B12-AA77F23278E5}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Dependency", "Test\Projects\Dependency\Dependency.csproj", "{9EAE36C3-50CD-49A6-9CA2-94649125DCD1}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TaskWithDependency", "Test\Projects\TaskWithDependency\TaskWithDependency.csproj", "{09EEB69D-817E-4B33-9F61-24FC9DA5B3D4}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -766,6 +774,114 @@ Global
{11B5D53E-90E4-4BD5-9883-B5921F7DE854}.Release-NetCore-Ubuntu|x64.Build.0 = Release|Any CPU
{11B5D53E-90E4-4BD5-9883-B5921F7DE854}.Release-NetCore-Ubuntu|x86.ActiveCfg = Release|Any CPU
{11B5D53E-90E4-4BD5-9883-B5921F7DE854}.Release-NetCore-Ubuntu|x86.Build.0 = Release|Any CPU
{9EAE36C3-50CD-49A6-9CA2-94649125DCD1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9EAE36C3-50CD-49A6-9CA2-94649125DCD1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9EAE36C3-50CD-49A6-9CA2-94649125DCD1}.Debug|x64.ActiveCfg = Debug|Any CPU
{9EAE36C3-50CD-49A6-9CA2-94649125DCD1}.Debug|x64.Build.0 = Debug|Any CPU
{9EAE36C3-50CD-49A6-9CA2-94649125DCD1}.Debug|x86.ActiveCfg = Debug|Any CPU
{9EAE36C3-50CD-49A6-9CA2-94649125DCD1}.Debug|x86.Build.0 = Debug|Any CPU
{9EAE36C3-50CD-49A6-9CA2-94649125DCD1}.Debug-MONO|Any CPU.ActiveCfg = Debug-MONO|Any CPU
{9EAE36C3-50CD-49A6-9CA2-94649125DCD1}.Debug-MONO|Any CPU.Build.0 = Debug-MONO|Any CPU
{9EAE36C3-50CD-49A6-9CA2-94649125DCD1}.Debug-MONO|x64.ActiveCfg = Debug-MONO|Any CPU
{9EAE36C3-50CD-49A6-9CA2-94649125DCD1}.Debug-MONO|x64.Build.0 = Debug-MONO|Any CPU
{9EAE36C3-50CD-49A6-9CA2-94649125DCD1}.Debug-MONO|x86.ActiveCfg = Debug-MONO|Any CPU
{9EAE36C3-50CD-49A6-9CA2-94649125DCD1}.Debug-MONO|x86.Build.0 = Debug-MONO|Any CPU
{9EAE36C3-50CD-49A6-9CA2-94649125DCD1}.Debug-NetCore|Any CPU.ActiveCfg = Debug-NetCore|Any CPU
{9EAE36C3-50CD-49A6-9CA2-94649125DCD1}.Debug-NetCore|Any CPU.Build.0 = Debug-NetCore|Any CPU
{9EAE36C3-50CD-49A6-9CA2-94649125DCD1}.Debug-NetCore|x64.ActiveCfg = Debug-NetCore|Any CPU
{9EAE36C3-50CD-49A6-9CA2-94649125DCD1}.Debug-NetCore|x64.Build.0 = Debug-NetCore|Any CPU
{9EAE36C3-50CD-49A6-9CA2-94649125DCD1}.Debug-NetCore|x86.ActiveCfg = Debug-NetCore|Any CPU
{9EAE36C3-50CD-49A6-9CA2-94649125DCD1}.Debug-NetCore|x86.Build.0 = Debug-NetCore|Any CPU
{9EAE36C3-50CD-49A6-9CA2-94649125DCD1}.Debug-NetCore-Ubuntu|Any CPU.ActiveCfg = Debug-NetCore|Any CPU
{9EAE36C3-50CD-49A6-9CA2-94649125DCD1}.Debug-NetCore-Ubuntu|Any CPU.Build.0 = Debug-NetCore|Any CPU
{9EAE36C3-50CD-49A6-9CA2-94649125DCD1}.Debug-NetCore-Ubuntu|x64.ActiveCfg = Debug-NetCore|Any CPU
{9EAE36C3-50CD-49A6-9CA2-94649125DCD1}.Debug-NetCore-Ubuntu|x64.Build.0 = Debug-NetCore|Any CPU
{9EAE36C3-50CD-49A6-9CA2-94649125DCD1}.Debug-NetCore-Ubuntu|x86.ActiveCfg = Debug-NetCore|Any CPU
{9EAE36C3-50CD-49A6-9CA2-94649125DCD1}.Debug-NetCore-Ubuntu|x86.Build.0 = Debug-NetCore|Any CPU
{9EAE36C3-50CD-49A6-9CA2-94649125DCD1}.Port-Progress|Any CPU.ActiveCfg = Port-Progress|Any CPU
{9EAE36C3-50CD-49A6-9CA2-94649125DCD1}.Port-Progress|Any CPU.Build.0 = Port-Progress|Any CPU
{9EAE36C3-50CD-49A6-9CA2-94649125DCD1}.Port-Progress|x64.ActiveCfg = Port-Progress|Any CPU
{9EAE36C3-50CD-49A6-9CA2-94649125DCD1}.Port-Progress|x64.Build.0 = Port-Progress|Any CPU
{9EAE36C3-50CD-49A6-9CA2-94649125DCD1}.Port-Progress|x86.ActiveCfg = Port-Progress|Any CPU
{9EAE36C3-50CD-49A6-9CA2-94649125DCD1}.Port-Progress|x86.Build.0 = Port-Progress|Any CPU
{9EAE36C3-50CD-49A6-9CA2-94649125DCD1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9EAE36C3-50CD-49A6-9CA2-94649125DCD1}.Release|Any CPU.Build.0 = Release|Any CPU
{9EAE36C3-50CD-49A6-9CA2-94649125DCD1}.Release|x64.ActiveCfg = Release|Any CPU
{9EAE36C3-50CD-49A6-9CA2-94649125DCD1}.Release|x64.Build.0 = Release|Any CPU
{9EAE36C3-50CD-49A6-9CA2-94649125DCD1}.Release|x86.ActiveCfg = Release|Any CPU
{9EAE36C3-50CD-49A6-9CA2-94649125DCD1}.Release|x86.Build.0 = Release|Any CPU
{9EAE36C3-50CD-49A6-9CA2-94649125DCD1}.Release-MONO|Any CPU.ActiveCfg = Release-MONO|Any CPU
{9EAE36C3-50CD-49A6-9CA2-94649125DCD1}.Release-MONO|Any CPU.Build.0 = Release-MONO|Any CPU
{9EAE36C3-50CD-49A6-9CA2-94649125DCD1}.Release-MONO|x64.ActiveCfg = Release-MONO|Any CPU
{9EAE36C3-50CD-49A6-9CA2-94649125DCD1}.Release-MONO|x64.Build.0 = Release-MONO|Any CPU
{9EAE36C3-50CD-49A6-9CA2-94649125DCD1}.Release-MONO|x86.ActiveCfg = Release-MONO|Any CPU
{9EAE36C3-50CD-49A6-9CA2-94649125DCD1}.Release-MONO|x86.Build.0 = Release-MONO|Any CPU
{9EAE36C3-50CD-49A6-9CA2-94649125DCD1}.Release-NetCore|Any CPU.ActiveCfg = Release-NetCore|Any CPU
{9EAE36C3-50CD-49A6-9CA2-94649125DCD1}.Release-NetCore|Any CPU.Build.0 = Release-NetCore|Any CPU
{9EAE36C3-50CD-49A6-9CA2-94649125DCD1}.Release-NetCore|x64.ActiveCfg = Release-NetCore|Any CPU
{9EAE36C3-50CD-49A6-9CA2-94649125DCD1}.Release-NetCore|x64.Build.0 = Release-NetCore|Any CPU
{9EAE36C3-50CD-49A6-9CA2-94649125DCD1}.Release-NetCore|x86.ActiveCfg = Release-NetCore|Any CPU
{9EAE36C3-50CD-49A6-9CA2-94649125DCD1}.Release-NetCore|x86.Build.0 = Release-NetCore|Any CPU
{9EAE36C3-50CD-49A6-9CA2-94649125DCD1}.Release-NetCore-Ubuntu|Any CPU.ActiveCfg = Release-NetCore|Any CPU
{9EAE36C3-50CD-49A6-9CA2-94649125DCD1}.Release-NetCore-Ubuntu|Any CPU.Build.0 = Release-NetCore|Any CPU
{9EAE36C3-50CD-49A6-9CA2-94649125DCD1}.Release-NetCore-Ubuntu|x64.ActiveCfg = Release-NetCore|Any CPU
{9EAE36C3-50CD-49A6-9CA2-94649125DCD1}.Release-NetCore-Ubuntu|x64.Build.0 = Release-NetCore|Any CPU
{9EAE36C3-50CD-49A6-9CA2-94649125DCD1}.Release-NetCore-Ubuntu|x86.ActiveCfg = Release-NetCore|Any CPU
{9EAE36C3-50CD-49A6-9CA2-94649125DCD1}.Release-NetCore-Ubuntu|x86.Build.0 = Release-NetCore|Any CPU
{09EEB69D-817E-4B33-9F61-24FC9DA5B3D4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{09EEB69D-817E-4B33-9F61-24FC9DA5B3D4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{09EEB69D-817E-4B33-9F61-24FC9DA5B3D4}.Debug|x64.ActiveCfg = Debug|Any CPU
{09EEB69D-817E-4B33-9F61-24FC9DA5B3D4}.Debug|x64.Build.0 = Debug|Any CPU
{09EEB69D-817E-4B33-9F61-24FC9DA5B3D4}.Debug|x86.ActiveCfg = Debug|Any CPU
{09EEB69D-817E-4B33-9F61-24FC9DA5B3D4}.Debug|x86.Build.0 = Debug|Any CPU
{09EEB69D-817E-4B33-9F61-24FC9DA5B3D4}.Debug-MONO|Any CPU.ActiveCfg = Debug-MONO|Any CPU
{09EEB69D-817E-4B33-9F61-24FC9DA5B3D4}.Debug-MONO|Any CPU.Build.0 = Debug-MONO|Any CPU
{09EEB69D-817E-4B33-9F61-24FC9DA5B3D4}.Debug-MONO|x64.ActiveCfg = Debug-MONO|Any CPU
{09EEB69D-817E-4B33-9F61-24FC9DA5B3D4}.Debug-MONO|x64.Build.0 = Debug-MONO|Any CPU
{09EEB69D-817E-4B33-9F61-24FC9DA5B3D4}.Debug-MONO|x86.ActiveCfg = Debug-MONO|Any CPU
{09EEB69D-817E-4B33-9F61-24FC9DA5B3D4}.Debug-MONO|x86.Build.0 = Debug-MONO|Any CPU
{09EEB69D-817E-4B33-9F61-24FC9DA5B3D4}.Debug-NetCore|Any CPU.ActiveCfg = Debug-NetCore|Any CPU
{09EEB69D-817E-4B33-9F61-24FC9DA5B3D4}.Debug-NetCore|Any CPU.Build.0 = Debug-NetCore|Any CPU
{09EEB69D-817E-4B33-9F61-24FC9DA5B3D4}.Debug-NetCore|x64.ActiveCfg = Debug-NetCore|Any CPU
{09EEB69D-817E-4B33-9F61-24FC9DA5B3D4}.Debug-NetCore|x64.Build.0 = Debug-NetCore|Any CPU
{09EEB69D-817E-4B33-9F61-24FC9DA5B3D4}.Debug-NetCore|x86.ActiveCfg = Debug-NetCore|Any CPU
{09EEB69D-817E-4B33-9F61-24FC9DA5B3D4}.Debug-NetCore|x86.Build.0 = Debug-NetCore|Any CPU
{09EEB69D-817E-4B33-9F61-24FC9DA5B3D4}.Debug-NetCore-Ubuntu|Any CPU.ActiveCfg = Debug-NetCore|Any CPU
{09EEB69D-817E-4B33-9F61-24FC9DA5B3D4}.Debug-NetCore-Ubuntu|Any CPU.Build.0 = Debug-NetCore|Any CPU
{09EEB69D-817E-4B33-9F61-24FC9DA5B3D4}.Debug-NetCore-Ubuntu|x64.ActiveCfg = Debug-NetCore|Any CPU
{09EEB69D-817E-4B33-9F61-24FC9DA5B3D4}.Debug-NetCore-Ubuntu|x64.Build.0 = Debug-NetCore|Any CPU
{09EEB69D-817E-4B33-9F61-24FC9DA5B3D4}.Debug-NetCore-Ubuntu|x86.ActiveCfg = Debug-NetCore|Any CPU
{09EEB69D-817E-4B33-9F61-24FC9DA5B3D4}.Debug-NetCore-Ubuntu|x86.Build.0 = Debug-NetCore|Any CPU
{09EEB69D-817E-4B33-9F61-24FC9DA5B3D4}.Port-Progress|Any CPU.ActiveCfg = Port-Progress|Any CPU
{09EEB69D-817E-4B33-9F61-24FC9DA5B3D4}.Port-Progress|Any CPU.Build.0 = Port-Progress|Any CPU
{09EEB69D-817E-4B33-9F61-24FC9DA5B3D4}.Port-Progress|x64.ActiveCfg = Port-Progress|Any CPU
{09EEB69D-817E-4B33-9F61-24FC9DA5B3D4}.Port-Progress|x64.Build.0 = Port-Progress|Any CPU
{09EEB69D-817E-4B33-9F61-24FC9DA5B3D4}.Port-Progress|x86.ActiveCfg = Port-Progress|Any CPU
{09EEB69D-817E-4B33-9F61-24FC9DA5B3D4}.Port-Progress|x86.Build.0 = Port-Progress|Any CPU
{09EEB69D-817E-4B33-9F61-24FC9DA5B3D4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{09EEB69D-817E-4B33-9F61-24FC9DA5B3D4}.Release|Any CPU.Build.0 = Release|Any CPU
{09EEB69D-817E-4B33-9F61-24FC9DA5B3D4}.Release|x64.ActiveCfg = Release|Any CPU
{09EEB69D-817E-4B33-9F61-24FC9DA5B3D4}.Release|x64.Build.0 = Release|Any CPU
{09EEB69D-817E-4B33-9F61-24FC9DA5B3D4}.Release|x86.ActiveCfg = Release|Any CPU
{09EEB69D-817E-4B33-9F61-24FC9DA5B3D4}.Release|x86.Build.0 = Release|Any CPU
{09EEB69D-817E-4B33-9F61-24FC9DA5B3D4}.Release-MONO|Any CPU.ActiveCfg = Release-MONO|Any CPU
{09EEB69D-817E-4B33-9F61-24FC9DA5B3D4}.Release-MONO|Any CPU.Build.0 = Release-MONO|Any CPU
{09EEB69D-817E-4B33-9F61-24FC9DA5B3D4}.Release-MONO|x64.ActiveCfg = Release-MONO|Any CPU
{09EEB69D-817E-4B33-9F61-24FC9DA5B3D4}.Release-MONO|x64.Build.0 = Release-MONO|Any CPU
{09EEB69D-817E-4B33-9F61-24FC9DA5B3D4}.Release-MONO|x86.ActiveCfg = Release-MONO|Any CPU
{09EEB69D-817E-4B33-9F61-24FC9DA5B3D4}.Release-MONO|x86.Build.0 = Release-MONO|Any CPU
{09EEB69D-817E-4B33-9F61-24FC9DA5B3D4}.Release-NetCore|Any CPU.ActiveCfg = Release-NetCore|Any CPU
{09EEB69D-817E-4B33-9F61-24FC9DA5B3D4}.Release-NetCore|Any CPU.Build.0 = Release-NetCore|Any CPU
{09EEB69D-817E-4B33-9F61-24FC9DA5B3D4}.Release-NetCore|x64.ActiveCfg = Release-NetCore|Any CPU
{09EEB69D-817E-4B33-9F61-24FC9DA5B3D4}.Release-NetCore|x64.Build.0 = Release-NetCore|Any CPU
{09EEB69D-817E-4B33-9F61-24FC9DA5B3D4}.Release-NetCore|x86.ActiveCfg = Release-NetCore|Any CPU
{09EEB69D-817E-4B33-9F61-24FC9DA5B3D4}.Release-NetCore|x86.Build.0 = Release-NetCore|Any CPU
{09EEB69D-817E-4B33-9F61-24FC9DA5B3D4}.Release-NetCore-Ubuntu|Any CPU.ActiveCfg = Release-NetCore|Any CPU
{09EEB69D-817E-4B33-9F61-24FC9DA5B3D4}.Release-NetCore-Ubuntu|Any CPU.Build.0 = Release-NetCore|Any CPU
{09EEB69D-817E-4B33-9F61-24FC9DA5B3D4}.Release-NetCore-Ubuntu|x64.ActiveCfg = Release-NetCore|Any CPU
{09EEB69D-817E-4B33-9F61-24FC9DA5B3D4}.Release-NetCore-Ubuntu|x64.Build.0 = Release-NetCore|Any CPU
{09EEB69D-817E-4B33-9F61-24FC9DA5B3D4}.Release-NetCore-Ubuntu|x86.ActiveCfg = Release-NetCore|Any CPU
{09EEB69D-817E-4B33-9F61-24FC9DA5B3D4}.Release-NetCore-Ubuntu|x86.Build.0 = Release-NetCore|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -774,5 +890,8 @@ Global
{2A0E81B1-9E7A-4F9F-81B2-AB180833F754} = {760FF85D-8BEB-4992-8095-A9678F88FD47}
{FC1C02BB-1585-4322-840F-B002E25AEAD6} = {760FF85D-8BEB-4992-8095-A9678F88FD47}
{11B5D53E-90E4-4BD5-9883-B5921F7DE854} = {760FF85D-8BEB-4992-8095-A9678F88FD47}
{1EFEE954-8884-41A2-9B12-AA77F23278E5} = {B6FB6ADC-98C7-4AFB-9BBF-CB3679DF86B9}
{9EAE36C3-50CD-49A6-9CA2-94649125DCD1} = {1EFEE954-8884-41A2-9B12-AA77F23278E5}
{09EEB69D-817E-4B33-9F61-24FC9DA5B3D4} = {1EFEE954-8884-41A2-9B12-AA77F23278E5}
EndGlobalSection
EndGlobal
138 changes: 138 additions & 0 deletions src/Shared/UnitTests/TypeLoader_Dependencies_Tests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.


using System;
using System.IO;
using Microsoft.Build.Shared;
using Microsoft.Build.SharedUtilities;
using Xunit;

namespace Microsoft.Build.UnitTests
{
public class TypeLoader_Dependencies_Tests
{
private static readonly string ProjectFilePath = Path.Combine(FileUtilities.CurrentExecutableDirectory, "TaskWithDependencyTest.proj");
private static readonly string TaskDllFileName = "TaskWithDependency.dll";
private static readonly string OriginalTaskDllPath = Path.Combine(FileUtilities.CurrentExecutableDirectory, TaskDllFileName);
private static readonly string DependencyDllFileName = "Dependency.dll";
private static readonly string OriginalDependencyDllPath = Path.Combine(FileUtilities.CurrentExecutableDirectory, DependencyDllFileName);

[Fact]
public void LoadAssemblyAndDependency_Inside()
{
bool successfulExit;
string output = RunnerUtilities.ExecMSBuild(ProjectFilePath + " /v:diag", out successfulExit);
Assert.True(successfulExit);

CheckIfCorrectAssemblyLoaded(output, OriginalTaskDllPath);
}

[Fact]
public void LoadAssemblyAndDependency_Outside()
{
string tempDir = MoveOrCopyDllsToTempDir(copy: false);
var newTaskDllPath = Path.Combine(tempDir, TaskDllFileName);

try
{
bool successfulExit;
string output = RunnerUtilities.ExecMSBuild(ProjectFilePath + " /v:diag /p:AssemblyPath=" + newTaskDllPath, out successfulExit);
Assert.True(successfulExit);

CheckIfCorrectAssemblyLoaded(output, newTaskDllPath);
}
finally
{
UndoDLLOperations(tempDir, moveBack: true);
}
}

/// <summary>
/// </summary>
/// <param name="copy"></param>
/// <returns>Path to temporary directory</returns>
private string MoveOrCopyDllsToTempDir(bool copy)
{
var temporaryDirectory = FileUtilities.GetTemporaryDirectory();

var newTaskDllPath = Path.Combine(temporaryDirectory, TaskDllFileName);
var newDependencyDllPath = Path.Combine(temporaryDirectory, DependencyDllFileName);

Assert.True(File.Exists(OriginalTaskDllPath));
Assert.True(File.Exists(OriginalDependencyDllPath));

if (copy)
{
File.Copy(OriginalTaskDllPath, newTaskDllPath);
File.Copy(OriginalDependencyDllPath, newDependencyDllPath);

Assert.True(File.Exists(newTaskDllPath));
Assert.True(File.Exists(newDependencyDllPath));
}
else
{
File.Move(OriginalTaskDllPath, newTaskDllPath);
File.Move(OriginalDependencyDllPath, newDependencyDllPath);


Assert.True(File.Exists(newTaskDllPath));
Assert.True(File.Exists(newDependencyDllPath));
Assert.False(File.Exists(OriginalTaskDllPath));
Assert.False(File.Exists(OriginalDependencyDllPath));
}

return temporaryDirectory;
}

/// <summary>
/// Move / Delete newDllPath and delete temp directory
/// </summary>
/// <param name="newDllPath"></param>
/// <param name="moveBack">If true, move newDllPath back to bin. If false, delete it</param>
private void UndoDLLOperations(string tempDirectoryPath, bool moveBack)
{
var currentTaskDllPath = Path.Combine(tempDirectoryPath, TaskDllFileName);
var currentDependencyDllPath = Path.Combine(tempDirectoryPath, DependencyDllFileName);

if (moveBack)
{
File.Move(currentTaskDllPath, OriginalTaskDllPath);
File.Move(currentDependencyDllPath, OriginalDependencyDllPath);
}
else
{
File.Delete(currentTaskDllPath);
File.Delete(currentDependencyDllPath);

}

Assert.True(File.Exists(OriginalTaskDllPath));
Assert.True(File.Exists(OriginalDependencyDllPath));


Assert.False(File.Exists(currentTaskDllPath));
Assert.False(File.Exists(currentDependencyDllPath));

Assert.Empty(Directory.EnumerateFiles(tempDirectoryPath));

Directory.Delete(tempDirectoryPath);
Assert.False(Directory.Exists(tempDirectoryPath));
}

private void CheckIfCorrectAssemblyLoaded(string scriptOutput, string expectedAssemblyPath, bool expectedSuccess = true)
{
var successfulMessage = @"Using ""LogStringFromDependency"" task from assembly """ + expectedAssemblyPath + @""".";

if (expectedSuccess)
{
Assert.Contains(successfulMessage, scriptOutput, StringComparison.OrdinalIgnoreCase);
}
else
{
Assert.DoesNotContain(successfulMessage, scriptOutput, StringComparison.OrdinalIgnoreCase);
}
}
}
}

19 changes: 19 additions & 0 deletions src/Test/Projects/Dependency/Alpha.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Dependency
{
public class Alpha
{
public static string GetString()
{
return nameof(Alpha) + "." + nameof(GetString);
}
}
}
36 changes: 36 additions & 0 deletions src/Test/Projects/Dependency/Dependency.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\..\..\dir.props" />
<PropertyGroup>
<MinimumVisualStudioVersion>14.0</MinimumVisualStudioVersion>
<ProjectGuid>{9EAE36C3-50CD-49A6-9CA2-94649125DCD1}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Dependency</RootNamespace>
<AssemblyName>Dependency</AssemblyName>
<DefaultLanguage>en-US</DefaultLanguage>
<UseProductOutputPath>true</UseProductOutputPath>
<CopyNuGetImplementations>false</CopyNuGetImplementations>
</PropertyGroup>
<PropertyGroup Condition="'$(NetCoreBuild)' == 'true'">
<StartAction Condition="'$(StartAction)'==''">Program</StartAction>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
</PropertyGroup>
<ItemGroup>
<None Include="project.json" />
<!-- A reference to the entire .NET Framework is automatically included -->
</ItemGroup>
<ItemGroup>
<Compile Include="Alpha.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<Reference Include="System" />
</ItemGroup>
<Import Project="..\..\..\dir.targets" />
<!-- OSS sign assembly after compile runs. -->
<Import Condition="Exists('$(ToolsDir)\sign.targets')" Project="$(ToolsDir)\sign.targets" />
</Project>
Loading

0 comments on commit 3628b26

Please sign in to comment.