|
| 1 | +// Copyright (c) Microsoft Corporation. All rights reserved. |
| 2 | +// Licensed under the MIT license. See LICENSE file in the project root for full license information. |
| 3 | + |
| 4 | +using Microsoft.Testing.Platform.Acceptance.IntegrationTests; |
| 5 | +using Microsoft.Testing.Platform.Acceptance.IntegrationTests.Helpers; |
| 6 | +using Microsoft.Testing.Platform.Helpers; |
| 7 | + |
| 8 | +namespace MSTest.Acceptance.IntegrationTests; |
| 9 | + |
| 10 | +[TestClass] |
| 11 | +public class DeploymentItemTests : AcceptanceTestBase<DeploymentItemTests.TestAssetFixture> |
| 12 | +{ |
| 13 | + private const string AssetName = nameof(DeploymentItemTests); |
| 14 | + |
| 15 | + [TestMethod] |
| 16 | + [OSCondition(OperatingSystems.Windows)] |
| 17 | + public async Task AssemblyIsLoadedOnceFromDeploymentDirectory() |
| 18 | + { |
| 19 | + var testHost = TestHost.LocateFrom(AssetFixture.TargetAssetPath, AssetName, TargetFrameworks.NetFramework[0]); |
| 20 | + TestHostResult testHostResult = await testHost.ExecuteAsync(cancellationToken: TestContext.CancellationToken); |
| 21 | + testHostResult.AssertOutputContainsSummary(failed: 0, passed: 1, skipped: 0); |
| 22 | + testHostResult.AssertExitCodeIs(ExitCodes.Success); |
| 23 | + } |
| 24 | + |
| 25 | + public sealed class TestAssetFixture() : TestAssetFixtureBase(AcceptanceFixture.NuGetGlobalPackagesFolder) |
| 26 | + { |
| 27 | + private const string Sources = """ |
| 28 | +#file DeploymentItemTests.csproj |
| 29 | +<Project Sdk="Microsoft.NET.Sdk"> |
| 30 | +
|
| 31 | + <PropertyGroup> |
| 32 | + <TargetFrameworks>$TargetFrameworks$</TargetFrameworks> |
| 33 | + <EnableMSTestRunner>true</EnableMSTestRunner> |
| 34 | + <OutputType>Exe</OutputType> |
| 35 | + </PropertyGroup> |
| 36 | +
|
| 37 | + <ItemGroup> |
| 38 | + <PackageReference Include="MSTest.TestFramework" Version="$MSTestVersion$" /> |
| 39 | + <PackageReference Include="MSTest.TestAdapter" Version="$MSTestVersion$" /> |
| 40 | + </ItemGroup> |
| 41 | +
|
| 42 | + <ItemGroup> |
| 43 | + <None Update="TestDeploymentItem.xml"> |
| 44 | + <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> |
| 45 | + </None> |
| 46 | + </ItemGroup> |
| 47 | +
|
| 48 | +</Project> |
| 49 | +
|
| 50 | +#file TestDeploymentItem.xml |
| 51 | +<?xml version="1.0" encoding="utf-8" ?> |
| 52 | +<Root /> |
| 53 | +
|
| 54 | +#file TestClass1.cs |
| 55 | +using System; |
| 56 | +using System.Collections.Generic; |
| 57 | +using SYstem.IO; |
| 58 | +using Microsoft.VisualStudio.TestTools.UnitTesting; |
| 59 | +
|
| 60 | +[TestClass] |
| 61 | +public sealed class Test1 |
| 62 | +{ |
| 63 | + public TestContext TestContext { get; set; } |
| 64 | +
|
| 65 | + [TestMethod] |
| 66 | + [DeploymentItem("TestDeploymentItem.xml")] |
| 67 | + public void TestMethod1() |
| 68 | + { |
| 69 | + var asm = Assert.ContainsSingle(AppDomain.CurrentDomain.GetAssemblies().Where(a => a.GetName().Name == "DeploymentItemTests")); |
| 70 | + var path = asm.Location; |
| 71 | + Assert.AreEqual(TestContext.DeploymentDirectory, Path.GetDirectoryName(path)); |
| 72 | + } |
| 73 | +} |
| 74 | +"""; |
| 75 | + |
| 76 | + public string TargetAssetPath => GetAssetPath(AssetName); |
| 77 | + |
| 78 | + public override IEnumerable<(string ID, string Name, string Code)> GetAssetsToGenerate() |
| 79 | + { |
| 80 | + yield return (AssetName, AssetName, |
| 81 | + Sources |
| 82 | + .PatchTargetFrameworks(TargetFrameworks.NetFramework[0]) |
| 83 | + .PatchCodeWithReplace("$MSTestVersion$", MSTestVersion)); |
| 84 | + } |
| 85 | + } |
| 86 | + |
| 87 | + public TestContext TestContext { get; set; } |
| 88 | +} |
0 commit comments