-
Notifications
You must be signed in to change notification settings - Fork 293
Expand file tree
/
Copy pathDeploymentItemTests.cs
More file actions
113 lines (94 loc) · 3.66 KB
/
DeploymentItemTests.cs
File metadata and controls
113 lines (94 loc) · 3.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using Microsoft.Testing.Platform.Acceptance.IntegrationTests;
using Microsoft.Testing.Platform.Acceptance.IntegrationTests.Helpers;
using Microsoft.Testing.Platform.Helpers;
namespace MSTest.Acceptance.IntegrationTests;
[TestClass]
public class DeploymentItemTests : AcceptanceTestBase<DeploymentItemTests.TestAssetFixture>
{
private const string AssetName = nameof(DeploymentItemTests);
[TestMethod]
[OSCondition(OperatingSystems.Windows)]
[DataRow("AppDomainDisabled.runsettings")]
[DataRow("AppDomainEnabled.runsettings")]
public async Task AssemblyIsLoadedOnceFromDeploymentDirectory(string runsettings)
{
var testHost = TestHost.LocateFrom(AssetFixture.TargetAssetPath, AssetName, TargetFrameworks.NetFramework[0]);
TestHostResult testHostResult = await testHost.ExecuteAsync($"--settings {runsettings}", cancellationToken: TestContext.CancellationToken);
testHostResult.AssertOutputContainsSummary(failed: 0, passed: 1, skipped: 0);
testHostResult.AssertExitCodeIs(ExitCodes.Success);
}
public sealed class TestAssetFixture() : TestAssetFixtureBase()
{
private const string Sources = """
#file DeploymentItemTests.csproj
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>$TargetFrameworks$</TargetFrameworks>
<EnableMSTestRunner>true</EnableMSTestRunner>
<OutputType>Exe</OutputType>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="MSTest.TestFramework" Version="$MSTestVersion$" />
<PackageReference Include="MSTest.TestAdapter" Version="$MSTestVersion$" />
</ItemGroup>
<ItemGroup>
<None Update="TestDeploymentItem.xml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
<ItemGroup>
<None Update="AppDomainEnabled.runsettings">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="AppDomainDisabled.runsettings">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>
#file TestDeploymentItem.xml
<?xml version="1.0" encoding="utf-8" ?>
<Root />
#file AppDomainEnabled.runsettings
<?xml version="1.0" encoding="utf-8" ?>
<RunSettings>
<RunConfiguration>
<DisableAppDomain>false</DisableAppDomain>
</RunConfiguration>
</RunSettings>
#file AppDomainDisabled.runsettings
<?xml version="1.0" encoding="utf-8" ?>
<RunSettings>
<RunConfiguration>
<DisableAppDomain>true</DisableAppDomain>
</RunConfiguration>
</RunSettings>
#file TestClass1.cs
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
[TestClass]
public sealed class Test1
{
public TestContext TestContext { get; set; }
[TestMethod]
[DeploymentItem("TestDeploymentItem.xml")]
public void TestMethod1()
{
var asm = Assert.ContainsSingle(AppDomain.CurrentDomain.GetAssemblies().Where(a => a.GetName().Name == "DeploymentItemTests"));
var path = asm.Location;
Assert.AreEqual(TestContext.DeploymentDirectory, Path.GetDirectoryName(path));
}
}
""";
public string TargetAssetPath => GetAssetPath(AssetName);
public override (string ID, string Name, string Code) GetAssetsToGenerate() => (AssetName, AssetName,
Sources
.PatchTargetFrameworks(TargetFrameworks.NetFramework[0])
.PatchCodeWithReplace("$MSTestVersion$", MSTestVersion));
}
public TestContext TestContext { get; set; }
}