From e5b5740f6e5e502f349274b14571ff30d4cb05b4 Mon Sep 17 00:00:00 2001 From: Engy Date: Tue, 13 Dec 2022 09:35:53 +0200 Subject: [PATCH] add tests --- .../Smoke.E2E.Tests/SuiteLifeCycleTests.cs | 243 +++++++++++++++++- ...pEndOfAssemblyAndBeforeEachDerivedClass.cs | 71 +++++ ...feCycleClassCleanupEndOfAssemblyAndNone.cs | 71 +++++ ...anupEndOfClassAndBeforeEachDerivedClass.cs | 71 +++++ .../LifeCycleClassCleanupEndOfClassAndNone.cs | 71 +++++ ...pEndOfAssemblyAndBeforeEachDerivedClass.cs | 50 ++++ ...DerivedClassCleanupEndOfAssemblyAndNone.cs | 50 ++++ ...anupEndOfClassAndBeforeEachDerivedClass.cs | 50 ++++ ...cleDerivedClassCleanupEndOfClassAndNone.cs | 50 ++++ 9 files changed, 724 insertions(+), 3 deletions(-) create mode 100644 test/E2ETests/TestAssets/SuiteLifeCycleTestProject/LifeCycleClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.cs create mode 100644 test/E2ETests/TestAssets/SuiteLifeCycleTestProject/LifeCycleClassCleanupEndOfAssemblyAndNone.cs create mode 100644 test/E2ETests/TestAssets/SuiteLifeCycleTestProject/LifeCycleClassCleanupEndOfClassAndBeforeEachDerivedClass.cs create mode 100644 test/E2ETests/TestAssets/SuiteLifeCycleTestProject/LifeCycleClassCleanupEndOfClassAndNone.cs create mode 100644 test/E2ETests/TestAssets/SuiteLifeCycleTestProject/LifeCycleDerivedClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.cs create mode 100644 test/E2ETests/TestAssets/SuiteLifeCycleTestProject/LifeCycleDerivedClassCleanupEndOfAssemblyAndNone.cs create mode 100644 test/E2ETests/TestAssets/SuiteLifeCycleTestProject/LifeCycleDerivedClassCleanupEndOfClassAndBeforeEachDerivedClass.cs create mode 100644 test/E2ETests/TestAssets/SuiteLifeCycleTestProject/LifeCycleDerivedClassCleanupEndOfClassAndNone.cs diff --git a/test/E2ETests/Smoke.E2E.Tests/SuiteLifeCycleTests.cs b/test/E2ETests/Smoke.E2E.Tests/SuiteLifeCycleTests.cs index d54894e98d..8ace517fbd 100644 --- a/test/E2ETests/Smoke.E2E.Tests/SuiteLifeCycleTests.cs +++ b/test/E2ETests/Smoke.E2E.Tests/SuiteLifeCycleTests.cs @@ -25,7 +25,7 @@ public void ValidateTestRunLifecycle_net462() private void ValidateTestRunLifecycle(string targetFramework) { InvokeVsTestForExecution(new[] { targetFramework + "\\" + Assembly }, targetFramework: targetFramework); - RunEventsHandler.PassedTests.Should().HaveCount(15); // The inherit class tests are called twice. + RunEventsHandler.PassedTests.Should().HaveCount(27); // The inherit class tests are called twice. var caseClassCleanup = RunEventsHandler.PassedTests.Single(x => x.TestCase.FullyQualifiedName.Contains("LifeCycleClassCleanup.TestMethod")); caseClassCleanup.Outcome.Should().Be(Microsoft.VisualStudio.TestPlatform.ObjectModel.TestOutcome.Passed); @@ -46,7 +46,7 @@ LifeCycleClassCleanup.TestCleanup was called """); - var caseClassCleanupEndOfAssembly = RunEventsHandler.PassedTests.Single(x => x.TestCase.FullyQualifiedName.Contains("LifeCycleClassCleanupEndOfAssembly")); + var caseClassCleanupEndOfAssembly = RunEventsHandler.PassedTests.Single(x => x.TestCase.FullyQualifiedName.Contains("LifeCycleClassCleanupEndOfAssembly.TestMethod")); caseClassCleanupEndOfAssembly.Outcome.Should().Be(Microsoft.VisualStudio.TestPlatform.ObjectModel.TestOutcome.Passed); // We don't see "LifeCycleClassCleanupEndOfAssembly.ClassCleanup was called" because it will be attached to the @@ -67,7 +67,7 @@ LifeCycleClassCleanupEndOfAssembly.TestCleanup was called """); - var caseClassCleanupEndOfClass = RunEventsHandler.PassedTests.Single(x => x.TestCase.FullyQualifiedName.Contains("LifeCycleClassCleanupEndOfClass")); + var caseClassCleanupEndOfClass = RunEventsHandler.PassedTests.Single(x => x.TestCase.FullyQualifiedName.Contains("LifeCycleClassCleanupEndOfClass.TestMethod")); caseClassCleanupEndOfClass.Outcome.Should().Be(Microsoft.VisualStudio.TestPlatform.ObjectModel.TestOutcome.Passed); caseClassCleanupEndOfClass.Messages.Single().Text.Should().Be( $""" @@ -307,6 +307,243 @@ LifeCycleClassInitializeNoneAndClassCleanupBeforeEachDerivedClass.TestCleanup wa """); + var caseClassCleanupEndOfAssemblyAndBeforeEachDerivedClass = RunEventsHandler.PassedTests.Single(x => x.TestCase.FullyQualifiedName.Contains("LifeCycleClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.TestMethod")); + caseClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.Outcome.Should().Be(Microsoft.VisualStudio.TestPlatform.ObjectModel.TestOutcome.Passed); + caseClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.Messages.Single().Text.Should().Be( + $""" + + + TestContext Messages: + LifeCycleClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.ClassInitialize was called + LifeCycleClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.ctor was called + LifeCycleClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.TestInitialize was called + LifeCycleClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.TestMethod was called + LifeCycleClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.TestCleanup was called + {(targetFramework == "net6.0" + ? "LifeCycleClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.DisposeAsync was called\r\nLifeCycleClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.Dispose was called" + : "LifeCycleClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.Dispose was called")} + + """); + + var caseClassCleanupEndOfAssemblyAndNone = RunEventsHandler.PassedTests.Single(x => x.TestCase.FullyQualifiedName.Contains("LifeCycleClassCleanupEndOfAssemblyAndNone.TestMethod")); + caseClassCleanupEndOfAssemblyAndNone.Outcome.Should().Be(Microsoft.VisualStudio.TestPlatform.ObjectModel.TestOutcome.Passed); + caseClassCleanupEndOfAssemblyAndNone.Messages.Single().Text.Should().Be( + $""" + + + TestContext Messages: + LifeCycleClassCleanupEndOfAssemblyAndNone.ClassInitialize was called + LifeCycleClassCleanupEndOfAssemblyAndNone.ctor was called + LifeCycleClassCleanupEndOfAssemblyAndNone.TestInitialize was called + LifeCycleClassCleanupEndOfAssemblyAndNone.TestMethod was called + LifeCycleClassCleanupEndOfAssemblyAndNone.TestCleanup was called + {(targetFramework == "net6.0" + ? "LifeCycleClassCleanupEndOfAssemblyAndNone.DisposeAsync was called\r\nLifeCycleClassCleanupEndOfAssemblyAndNone.Dispose was called" + : "LifeCycleClassCleanupEndOfAssemblyAndNone.Dispose was called")} + + """); + + // Class cleanup with EndOfClass will appear in the parent logs in case of any inheritance behavior. + var caseClassCleanupEndOfClassAndBeforeEachDerivedClass = RunEventsHandler.PassedTests.Single(x => x.TestCase.FullyQualifiedName.Contains("LifeCycleClassCleanupEndOfClassAndBeforeEachDerivedClass.TestMethod")); + caseClassCleanupEndOfClassAndBeforeEachDerivedClass.Outcome.Should().Be(Microsoft.VisualStudio.TestPlatform.ObjectModel.TestOutcome.Passed); + caseClassCleanupEndOfClassAndBeforeEachDerivedClass.Messages.Single().Text.Should().Be( + $""" + + + TestContext Messages: + LifeCycleClassCleanupEndOfClassAndBeforeEachDerivedClass.ClassInitialize was called + LifeCycleClassCleanupEndOfClassAndBeforeEachDerivedClass.ctor was called + LifeCycleClassCleanupEndOfClassAndBeforeEachDerivedClass.TestInitialize was called + LifeCycleClassCleanupEndOfClassAndBeforeEachDerivedClass.TestMethod was called + LifeCycleClassCleanupEndOfClassAndBeforeEachDerivedClass.TestCleanup was called + {(targetFramework == "net6.0" + ? "LifeCycleClassCleanupEndOfClassAndBeforeEachDerivedClass.DisposeAsync was called\r\nLifeCycleClassCleanupEndOfClassAndBeforeEachDerivedClass.Dispose was called" + : "LifeCycleClassCleanupEndOfClassAndBeforeEachDerivedClass.Dispose was called")} + LifeCycleClassCleanupEndOfClassAndBeforeEachDerivedClass.ClassCleanup was called + + """); + + var caseClassCleanupEndOfClassAndNone = RunEventsHandler.PassedTests.Single(x => x.TestCase.FullyQualifiedName.Contains("LifeCycleClassCleanupEndOfClassAndNone.TestMethod")); + caseClassCleanupEndOfClassAndNone.Outcome.Should().Be(Microsoft.VisualStudio.TestPlatform.ObjectModel.TestOutcome.Passed); + caseClassCleanupEndOfClassAndNone.Messages.Single().Text.Should().Be( + $""" + + + TestContext Messages: + LifeCycleClassCleanupEndOfClassAndNone.ClassInitialize was called + LifeCycleClassCleanupEndOfClassAndNone.ctor was called + LifeCycleClassCleanupEndOfClassAndNone.TestInitialize was called + LifeCycleClassCleanupEndOfClassAndNone.TestMethod was called + LifeCycleClassCleanupEndOfClassAndNone.TestCleanup was called + {(targetFramework == "net6.0" + ? "LifeCycleClassCleanupEndOfClassAndNone.DisposeAsync was called\r\nLifeCycleClassCleanupEndOfClassAndNone.Dispose was called" + : "LifeCycleClassCleanupEndOfClassAndNone.Dispose was called")} + LifeCycleClassCleanupEndOfClassAndNone.ClassCleanup was called + + """); + + var caseDerivedClassCleanupEndOfAssemblyAndBeforeEachDerivedClass = RunEventsHandler.PassedTests.Single(x => x.TestCase.FullyQualifiedName.Contains("LifeCycleDerivedClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.DerivedClassTestMethod")); + caseDerivedClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.Outcome.Should().Be(Microsoft.VisualStudio.TestPlatform.ObjectModel.TestOutcome.Passed); + caseDerivedClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.Messages.Single().Text.Should().Be( + $""" + + + TestContext Messages: + LifeCycleDerivedClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.ClassInitialize was called + LifeCycleClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.ctor was called + LifeCycleDerivedClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.ctor was called + LifeCycleClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.TestInitialize was called + LifeCycleDerivedClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.TestInitialize was called + LifeCycleDerivedClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.TestMethod was called + LifeCycleDerivedClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.TestCleanup was called + LifeCycleClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.TestCleanup was called + {(targetFramework == "net6.0" + ? "LifeCycleClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.DisposeAsync was called\r\nLifeCycleClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.Dispose was called" + : "LifeCycleClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.Dispose was called")} + + """); + + var caseDerivedClassCleanupEndOfAssemblyAndNone = RunEventsHandler.PassedTests.Single(x => x.TestCase.FullyQualifiedName.Contains("LifeCycleDerivedClassCleanupEndOfAssemblyAndNone.DerivedClassTestMethod")); + caseDerivedClassCleanupEndOfAssemblyAndNone.Outcome.Should().Be(Microsoft.VisualStudio.TestPlatform.ObjectModel.TestOutcome.Passed); + caseDerivedClassCleanupEndOfAssemblyAndNone.Messages.Single().Text.Should().Be( + $""" + + + TestContext Messages: + LifeCycleDerivedClassCleanupEndOfAssemblyAndNone.ClassInitialize was called + LifeCycleClassCleanupEndOfAssemblyAndNone.ctor was called + LifeCycleDerivedClassCleanupEndOfAssemblyAndNone.ctor was called + LifeCycleClassCleanupEndOfAssemblyAndNone.TestInitialize was called + LifeCycleDerivedClassCleanupEndOfAssemblyAndNone.TestInitialize was called + LifeCycleDerivedClassCleanupEndOfAssemblyAndNone.TestMethod was called + LifeCycleDerivedClassCleanupEndOfAssemblyAndNone.TestCleanup was called + LifeCycleClassCleanupEndOfAssemblyAndNone.TestCleanup was called + {(targetFramework == "net6.0" + ? "LifeCycleClassCleanupEndOfAssemblyAndNone.DisposeAsync was called\r\nLifeCycleClassCleanupEndOfAssemblyAndNone.Dispose was called" + : "LifeCycleClassCleanupEndOfAssemblyAndNone.Dispose was called")} + + """); + var caseDerivedClassCleanupEndOfClassAndBeforeEachDerivedClass = RunEventsHandler.PassedTests.Single(x => x.TestCase.FullyQualifiedName.Contains("LifeCycleDerivedClassCleanupEndOfClassAndBeforeEachDerivedClass.DerivedClassTestMethod")); + caseDerivedClassCleanupEndOfClassAndBeforeEachDerivedClass.Outcome.Should().Be(Microsoft.VisualStudio.TestPlatform.ObjectModel.TestOutcome.Passed); + caseDerivedClassCleanupEndOfClassAndBeforeEachDerivedClass.Messages.Single().Text.Should().Be( + $""" + + + TestContext Messages: + LifeCycleDerivedClassCleanupEndOfClassAndBeforeEachDerivedClass.ClassInitialize was called + LifeCycleClassCleanupEndOfClassAndBeforeEachDerivedClass.ctor was called + LifeCycleDerivedClassCleanupEndOfClassAndBeforeEachDerivedClass.ctor was called + LifeCycleClassCleanupEndOfClassAndBeforeEachDerivedClass.TestInitialize was called + LifeCycleDerivedClassCleanupEndOfClassAndBeforeEachDerivedClass.TestInitialize was called + LifeCycleDerivedClassCleanupEndOfClassAndBeforeEachDerivedClass.TestMethod was called + LifeCycleDerivedClassCleanupEndOfClassAndBeforeEachDerivedClass.TestCleanup was called + LifeCycleClassCleanupEndOfClassAndBeforeEachDerivedClass.TestCleanup was called + {(targetFramework == "net6.0" + ? "LifeCycleClassCleanupEndOfClassAndBeforeEachDerivedClass.DisposeAsync was called\r\nLifeCycleClassCleanupEndOfClassAndBeforeEachDerivedClass.Dispose was called" + : "LifeCycleClassCleanupEndOfClassAndBeforeEachDerivedClass.Dispose was called")} + + """); + + var caseDerivedClassCleanupEndOfClassAndNone = RunEventsHandler.PassedTests.Single(x => x.TestCase.FullyQualifiedName.Contains("LifeCycleDerivedClassCleanupEndOfClassAndNone.DerivedClassTestMethod")); + caseDerivedClassCleanupEndOfClassAndNone.Outcome.Should().Be(Microsoft.VisualStudio.TestPlatform.ObjectModel.TestOutcome.Passed); + caseDerivedClassCleanupEndOfClassAndNone.Messages.Single().Text.Should().Be( + $""" + + + TestContext Messages: + LifeCycleDerivedClassCleanupEndOfClassAndNone.ClassInitialize was called + LifeCycleClassCleanupEndOfClassAndNone.ctor was called + LifeCycleDerivedClassCleanupEndOfClassAndNone.ctor was called + LifeCycleClassCleanupEndOfClassAndNone.TestInitialize was called + LifeCycleDerivedClassCleanupEndOfClassAndNone.TestInitialize was called + LifeCycleDerivedClassCleanupEndOfClassAndNone.TestMethod was called + LifeCycleDerivedClassCleanupEndOfClassAndNone.TestCleanup was called + LifeCycleClassCleanupEndOfClassAndNone.TestCleanup was called + {(targetFramework == "net6.0" + ? "LifeCycleClassCleanupEndOfClassAndNone.DisposeAsync was called\r\nLifeCycleClassCleanupEndOfClassAndNone.Dispose was called" + : "LifeCycleClassCleanupEndOfClassAndNone.Dispose was called")} + + """); + + var caseDerivedClassCleanupEndOfAssemblyAndBeforeEachDerivedClassParentTestMethod = RunEventsHandler.PassedTests.Single(x => x.TestCase.FullyQualifiedName.Contains("LifeCycleDerivedClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.TestMethod")); + caseDerivedClassCleanupEndOfAssemblyAndBeforeEachDerivedClassParentTestMethod.Outcome.Should().Be(Microsoft.VisualStudio.TestPlatform.ObjectModel.TestOutcome.Passed); + caseDerivedClassCleanupEndOfAssemblyAndBeforeEachDerivedClassParentTestMethod.Messages.Single().Text.Should().Be( + $""" + + + TestContext Messages: + LifeCycleClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.ctor was called + LifeCycleDerivedClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.ctor was called + LifeCycleClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.TestInitialize was called + LifeCycleDerivedClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.TestInitialize was called + LifeCycleClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.TestMethod was called + LifeCycleDerivedClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.TestCleanup was called + LifeCycleClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.TestCleanup was called + {(targetFramework == "net6.0" + ? "LifeCycleClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.DisposeAsync was called\r\nLifeCycleClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.Dispose was called" + : "LifeCycleClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.Dispose was called")} + + """); + + var caseDerivedClassCleanupEndOfAssemblyAndNoneParentTestMethod = RunEventsHandler.PassedTests.Single(x => x.TestCase.FullyQualifiedName.Contains("LifeCycleDerivedClassCleanupEndOfAssemblyAndNone.TestMethod")); + caseDerivedClassCleanupEndOfAssemblyAndNoneParentTestMethod.Outcome.Should().Be(Microsoft.VisualStudio.TestPlatform.ObjectModel.TestOutcome.Passed); + caseDerivedClassCleanupEndOfAssemblyAndNoneParentTestMethod.Messages.Single().Text.Should().Be( + $""" + + + TestContext Messages: + LifeCycleClassCleanupEndOfAssemblyAndNone.ctor was called + LifeCycleDerivedClassCleanupEndOfAssemblyAndNone.ctor was called + LifeCycleClassCleanupEndOfAssemblyAndNone.TestInitialize was called + LifeCycleDerivedClassCleanupEndOfAssemblyAndNone.TestInitialize was called + LifeCycleClassCleanupEndOfAssemblyAndNone.TestMethod was called + LifeCycleDerivedClassCleanupEndOfAssemblyAndNone.TestCleanup was called + LifeCycleClassCleanupEndOfAssemblyAndNone.TestCleanup was called + {(targetFramework == "net6.0" + ? "LifeCycleClassCleanupEndOfAssemblyAndNone.DisposeAsync was called\r\nLifeCycleClassCleanupEndOfAssemblyAndNone.Dispose was called" + : "LifeCycleClassCleanupEndOfAssemblyAndNone.Dispose was called")} + + """); + var caseDerivedClassCleanupEndOfClassAndBeforeEachDerivedClassParentTestMethod = RunEventsHandler.PassedTests.Single(x => x.TestCase.FullyQualifiedName.Contains("LifeCycleDerivedClassCleanupEndOfClassAndBeforeEachDerivedClass.TestMethod")); + caseDerivedClassCleanupEndOfClassAndBeforeEachDerivedClassParentTestMethod.Outcome.Should().Be(Microsoft.VisualStudio.TestPlatform.ObjectModel.TestOutcome.Passed); + caseDerivedClassCleanupEndOfClassAndBeforeEachDerivedClassParentTestMethod.Messages.Single().Text.Should().Be( + $""" + + + TestContext Messages: + LifeCycleClassCleanupEndOfClassAndBeforeEachDerivedClass.ctor was called + LifeCycleDerivedClassCleanupEndOfClassAndBeforeEachDerivedClass.ctor was called + LifeCycleClassCleanupEndOfClassAndBeforeEachDerivedClass.TestInitialize was called + LifeCycleDerivedClassCleanupEndOfClassAndBeforeEachDerivedClass.TestInitialize was called + LifeCycleClassCleanupEndOfClassAndBeforeEachDerivedClass.TestMethod was called + LifeCycleDerivedClassCleanupEndOfClassAndBeforeEachDerivedClass.TestCleanup was called + LifeCycleClassCleanupEndOfClassAndBeforeEachDerivedClass.TestCleanup was called + {(targetFramework == "net6.0" + ? "LifeCycleClassCleanupEndOfClassAndBeforeEachDerivedClass.DisposeAsync was called\r\nLifeCycleClassCleanupEndOfClassAndBeforeEachDerivedClass.Dispose was called" + : "LifeCycleClassCleanupEndOfClassAndBeforeEachDerivedClass.Dispose was called")} + + """); + + var caseDerivedClassCleanupEndOfClassAndNoneParentTestMethod = RunEventsHandler.PassedTests.Single(x => x.TestCase.FullyQualifiedName.Contains("LifeCycleDerivedClassCleanupEndOfClassAndNone.TestMethod")); + caseDerivedClassCleanupEndOfClassAndNoneParentTestMethod.Outcome.Should().Be(Microsoft.VisualStudio.TestPlatform.ObjectModel.TestOutcome.Passed); + caseDerivedClassCleanupEndOfClassAndNoneParentTestMethod.Messages.Single().Text.Should().Be( + $""" + + + TestContext Messages: + LifeCycleClassCleanupEndOfClassAndNone.ctor was called + LifeCycleDerivedClassCleanupEndOfClassAndNone.ctor was called + LifeCycleClassCleanupEndOfClassAndNone.TestInitialize was called + LifeCycleDerivedClassCleanupEndOfClassAndNone.TestInitialize was called + LifeCycleClassCleanupEndOfClassAndNone.TestMethod was called + LifeCycleDerivedClassCleanupEndOfClassAndNone.TestCleanup was called + LifeCycleClassCleanupEndOfClassAndNone.TestCleanup was called + {(targetFramework == "net6.0" + ? "LifeCycleClassCleanupEndOfClassAndNone.DisposeAsync was called\r\nLifeCycleClassCleanupEndOfClassAndNone.Dispose was called" + : "LifeCycleClassCleanupEndOfClassAndNone.Dispose was called")} + + """); + // Test the parent test method. // We are seeing all the ClassCleanup EndOfAssembly (or nothing set - as it's the default) being reported // here as this is the last test to run. diff --git a/test/E2ETests/TestAssets/SuiteLifeCycleTestProject/LifeCycleClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.cs b/test/E2ETests/TestAssets/SuiteLifeCycleTestProject/LifeCycleClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.cs new file mode 100644 index 0000000000..57c3c7c30f --- /dev/null +++ b/test/E2ETests/TestAssets/SuiteLifeCycleTestProject/LifeCycleClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.cs @@ -0,0 +1,71 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using System; +#if NET6_0_OR_GREATER +using System.Threading.Tasks; +#endif + +using Microsoft.VisualStudio.TestTools.UnitTesting; + +namespace SuiteLifeCycleTestProject; + +[TestClass] +public class LifeCycleClassCleanupEndOfAssemblyAndBeforeEachDerivedClass : IDisposable +#if NET6_0_OR_GREATER + , IAsyncDisposable +#endif +{ + private static TestContext s_testContext; + + public TestContext TestContext { get; set; } + + public LifeCycleClassCleanupEndOfAssemblyAndBeforeEachDerivedClass() + { + s_testContext.WriteLine("LifeCycleClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.ctor was called"); + } + + [ClassInitialize] + public static void ClassInitialize(TestContext testContext) + { + s_testContext = testContext; + s_testContext.WriteLine("LifeCycleClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.ClassInitialize was called"); + } + + [TestInitialize] + public void TestInitialize() + { + TestContext.WriteLine("LifeCycleClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.TestInitialize was called"); + } + + [TestMethod] + public void TestMethod() + { + TestContext.WriteLine("LifeCycleClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.TestMethod was called"); + } + + [TestCleanup] + public void TestCleanup() + { + TestContext.WriteLine("LifeCycleClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.TestCleanup was called"); + } + + public void Dispose() + { + TestContext.WriteLine("LifeCycleClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.Dispose was called"); + } + +#if NET6_0_OR_GREATER + public ValueTask DisposeAsync() + { + TestContext.WriteLine("LifeCycleClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.DisposeAsync was called"); + return ValueTask.CompletedTask; + } +#endif + + [ClassCleanup(InheritanceBehavior.BeforeEachDerivedClass, ClassCleanupBehavior.EndOfAssembly)] + public static void ClassCleanup() + { + s_testContext.WriteLine("LifeCycleClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.ClassCleanup was called"); + } +} diff --git a/test/E2ETests/TestAssets/SuiteLifeCycleTestProject/LifeCycleClassCleanupEndOfAssemblyAndNone.cs b/test/E2ETests/TestAssets/SuiteLifeCycleTestProject/LifeCycleClassCleanupEndOfAssemblyAndNone.cs new file mode 100644 index 0000000000..699163e489 --- /dev/null +++ b/test/E2ETests/TestAssets/SuiteLifeCycleTestProject/LifeCycleClassCleanupEndOfAssemblyAndNone.cs @@ -0,0 +1,71 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using System; +#if NET6_0_OR_GREATER +using System.Threading.Tasks; +#endif + +using Microsoft.VisualStudio.TestTools.UnitTesting; + +namespace SuiteLifeCycleTestProject; + +[TestClass] +public class LifeCycleClassCleanupEndOfAssemblyAndNone : IDisposable +#if NET6_0_OR_GREATER + , IAsyncDisposable +#endif +{ + private static TestContext s_testContext; + + public TestContext TestContext { get; set; } + + public LifeCycleClassCleanupEndOfAssemblyAndNone() + { + s_testContext.WriteLine("LifeCycleClassCleanupEndOfAssemblyAndNone.ctor was called"); + } + + [ClassInitialize] + public static void ClassInitialize(TestContext testContext) + { + s_testContext = testContext; + s_testContext.WriteLine("LifeCycleClassCleanupEndOfAssemblyAndNone.ClassInitialize was called"); + } + + [TestInitialize] + public void TestInitialize() + { + TestContext.WriteLine("LifeCycleClassCleanupEndOfAssemblyAndNone.TestInitialize was called"); + } + + [TestMethod] + public void TestMethod() + { + TestContext.WriteLine("LifeCycleClassCleanupEndOfAssemblyAndNone.TestMethod was called"); + } + + [TestCleanup] + public void TestCleanup() + { + TestContext.WriteLine("LifeCycleClassCleanupEndOfAssemblyAndNone.TestCleanup was called"); + } + + public void Dispose() + { + TestContext.WriteLine("LifeCycleClassCleanupEndOfAssemblyAndNone.Dispose was called"); + } + +#if NET6_0_OR_GREATER + public ValueTask DisposeAsync() + { + TestContext.WriteLine("LifeCycleClassCleanupEndOfAssemblyAndNone.DisposeAsync was called"); + return ValueTask.CompletedTask; + } +#endif + + [ClassCleanup(ClassCleanupBehavior.EndOfAssembly)] + public static void ClassCleanup() + { + s_testContext.WriteLine("LifeCycleClassCleanupEndOfAssemblyAndNone.ClassCleanup was called"); + } +} diff --git a/test/E2ETests/TestAssets/SuiteLifeCycleTestProject/LifeCycleClassCleanupEndOfClassAndBeforeEachDerivedClass.cs b/test/E2ETests/TestAssets/SuiteLifeCycleTestProject/LifeCycleClassCleanupEndOfClassAndBeforeEachDerivedClass.cs new file mode 100644 index 0000000000..be60722f19 --- /dev/null +++ b/test/E2ETests/TestAssets/SuiteLifeCycleTestProject/LifeCycleClassCleanupEndOfClassAndBeforeEachDerivedClass.cs @@ -0,0 +1,71 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using System; +#if NET6_0_OR_GREATER +using System.Threading.Tasks; +#endif + +using Microsoft.VisualStudio.TestTools.UnitTesting; + +namespace SuiteLifeCycleTestProject; + +[TestClass] +public class LifeCycleClassCleanupEndOfClassAndBeforeEachDerivedClass : IDisposable +#if NET6_0_OR_GREATER + , IAsyncDisposable +#endif +{ + private static TestContext s_testContext; + + public TestContext TestContext { get; set; } + + public LifeCycleClassCleanupEndOfClassAndBeforeEachDerivedClass() + { + s_testContext.WriteLine("LifeCycleClassCleanupEndOfClassAndBeforeEachDerivedClass.ctor was called"); + } + + [ClassInitialize] + public static void ClassInitialize(TestContext testContext) + { + s_testContext = testContext; + s_testContext.WriteLine("LifeCycleClassCleanupEndOfClassAndBeforeEachDerivedClass.ClassInitialize was called"); + } + + [TestInitialize] + public void TestInitialize() + { + TestContext.WriteLine("LifeCycleClassCleanupEndOfClassAndBeforeEachDerivedClass.TestInitialize was called"); + } + + [TestMethod] + public void TestMethod() + { + TestContext.WriteLine("LifeCycleClassCleanupEndOfClassAndBeforeEachDerivedClass.TestMethod was called"); + } + + [TestCleanup] + public void TestCleanup() + { + TestContext.WriteLine("LifeCycleClassCleanupEndOfClassAndBeforeEachDerivedClass.TestCleanup was called"); + } + + public void Dispose() + { + TestContext.WriteLine("LifeCycleClassCleanupEndOfClassAndBeforeEachDerivedClass.Dispose was called"); + } + +#if NET6_0_OR_GREATER + public ValueTask DisposeAsync() + { + TestContext.WriteLine("LifeCycleClassCleanupEndOfClassAndBeforeEachDerivedClass.DisposeAsync was called"); + return ValueTask.CompletedTask; + } +#endif + + [ClassCleanup(InheritanceBehavior.BeforeEachDerivedClass, ClassCleanupBehavior.EndOfClass)] + public static void ClassCleanup() + { + s_testContext.WriteLine("LifeCycleClassCleanupEndOfClassAndBeforeEachDerivedClass.ClassCleanup was called"); + } +} diff --git a/test/E2ETests/TestAssets/SuiteLifeCycleTestProject/LifeCycleClassCleanupEndOfClassAndNone.cs b/test/E2ETests/TestAssets/SuiteLifeCycleTestProject/LifeCycleClassCleanupEndOfClassAndNone.cs new file mode 100644 index 0000000000..bfbc140a90 --- /dev/null +++ b/test/E2ETests/TestAssets/SuiteLifeCycleTestProject/LifeCycleClassCleanupEndOfClassAndNone.cs @@ -0,0 +1,71 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using System; +#if NET6_0_OR_GREATER +using System.Threading.Tasks; +#endif + +using Microsoft.VisualStudio.TestTools.UnitTesting; + +namespace SuiteLifeCycleTestProject; + +[TestClass] +public class LifeCycleClassCleanupEndOfClassAndNone : IDisposable +#if NET6_0_OR_GREATER + , IAsyncDisposable +#endif +{ + private static TestContext s_testContext; + + public TestContext TestContext { get; set; } + + public LifeCycleClassCleanupEndOfClassAndNone() + { + s_testContext.WriteLine("LifeCycleClassCleanupEndOfClassAndNone.ctor was called"); + } + + [ClassInitialize] + public static void ClassInitialize(TestContext testContext) + { + s_testContext = testContext; + s_testContext.WriteLine("LifeCycleClassCleanupEndOfClassAndNone.ClassInitialize was called"); + } + + [TestInitialize] + public void TestInitialize() + { + TestContext.WriteLine("LifeCycleClassCleanupEndOfClassAndNone.TestInitialize was called"); + } + + [TestMethod] + public void TestMethod() + { + TestContext.WriteLine("LifeCycleClassCleanupEndOfClassAndNone.TestMethod was called"); + } + + [TestCleanup] + public void TestCleanup() + { + TestContext.WriteLine("LifeCycleClassCleanupEndOfClassAndNone.TestCleanup was called"); + } + + public void Dispose() + { + TestContext.WriteLine("LifeCycleClassCleanupEndOfClassAndNone.Dispose was called"); + } + +#if NET6_0_OR_GREATER + public ValueTask DisposeAsync() + { + TestContext.WriteLine("LifeCycleClassCleanupEndOfClassAndNone.DisposeAsync was called"); + return ValueTask.CompletedTask; + } +#endif + + [ClassCleanup(ClassCleanupBehavior.EndOfClass)] + public static void ClassCleanup() + { + s_testContext.WriteLine("LifeCycleClassCleanupEndOfClassAndNone.ClassCleanup was called"); + } +} diff --git a/test/E2ETests/TestAssets/SuiteLifeCycleTestProject/LifeCycleDerivedClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.cs b/test/E2ETests/TestAssets/SuiteLifeCycleTestProject/LifeCycleDerivedClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.cs new file mode 100644 index 0000000000..15a9d3071f --- /dev/null +++ b/test/E2ETests/TestAssets/SuiteLifeCycleTestProject/LifeCycleDerivedClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.cs @@ -0,0 +1,50 @@ +// 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.VisualStudio.TestTools.UnitTesting; + +namespace SuiteLifeCycleTestProject; + +[TestClass] +public sealed class LifeCycleDerivedClassCleanupEndOfAssemblyAndBeforeEachDerivedClass : LifeCycleClassCleanupEndOfAssemblyAndBeforeEachDerivedClass +{ + private static TestContext s_testContext; + + public TestContext DerivedClassTestContext { get; set; } + + public LifeCycleDerivedClassCleanupEndOfAssemblyAndBeforeEachDerivedClass() + { + s_testContext.WriteLine("LifeCycleDerivedClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.ctor was called"); + } + + [ClassInitialize] + public static void DerivedClassInitialize(TestContext testContext) + { + s_testContext = testContext; + s_testContext.WriteLine("LifeCycleDerivedClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.ClassInitialize was called"); + } + + [TestInitialize] + public void DerivedClassTestInitialize() + { + TestContext.WriteLine("LifeCycleDerivedClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.TestInitialize was called"); + } + + [TestMethod] + public void DerivedClassTestMethod() + { + TestContext.WriteLine("LifeCycleDerivedClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.TestMethod was called"); + } + + [TestCleanup] + public void DerivedClassTestCleanup() + { + TestContext.WriteLine("LifeCycleDerivedClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.TestCleanup was called"); + } + + [ClassCleanup] + public static void DerivedClassCleanup() + { + s_testContext.WriteLine("LifeCycleDerivedClassCleanupEndOfAssemblyAndBeforeEachDerivedClass.ClassCleanup was called"); + } +} diff --git a/test/E2ETests/TestAssets/SuiteLifeCycleTestProject/LifeCycleDerivedClassCleanupEndOfAssemblyAndNone.cs b/test/E2ETests/TestAssets/SuiteLifeCycleTestProject/LifeCycleDerivedClassCleanupEndOfAssemblyAndNone.cs new file mode 100644 index 0000000000..710510b396 --- /dev/null +++ b/test/E2ETests/TestAssets/SuiteLifeCycleTestProject/LifeCycleDerivedClassCleanupEndOfAssemblyAndNone.cs @@ -0,0 +1,50 @@ +// 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.VisualStudio.TestTools.UnitTesting; + +namespace SuiteLifeCycleTestProject; + +[TestClass] +public sealed class LifeCycleDerivedClassCleanupEndOfAssemblyAndNone : LifeCycleClassCleanupEndOfAssemblyAndNone +{ + private static TestContext s_testContext; + + public TestContext DerivedClassTestContext { get; set; } + + public LifeCycleDerivedClassCleanupEndOfAssemblyAndNone() + { + s_testContext.WriteLine("LifeCycleDerivedClassCleanupEndOfAssemblyAndNone.ctor was called"); + } + + [ClassInitialize] + public static void DerivedClassInitialize(TestContext testContext) + { + s_testContext = testContext; + s_testContext.WriteLine("LifeCycleDerivedClassCleanupEndOfAssemblyAndNone.ClassInitialize was called"); + } + + [TestInitialize] + public void DerivedClassTestInitialize() + { + TestContext.WriteLine("LifeCycleDerivedClassCleanupEndOfAssemblyAndNone.TestInitialize was called"); + } + + [TestMethod] + public void DerivedClassTestMethod() + { + TestContext.WriteLine("LifeCycleDerivedClassCleanupEndOfAssemblyAndNone.TestMethod was called"); + } + + [TestCleanup] + public void DerivedClassTestCleanup() + { + TestContext.WriteLine("LifeCycleDerivedClassCleanupEndOfAssemblyAndNone.TestCleanup was called"); + } + + [ClassCleanup] + public static void DerivedClassCleanup() + { + s_testContext.WriteLine("LifeCycleDerivedClassCleanupEndOfAssemblyAndNone.ClassCleanup was called"); + } +} diff --git a/test/E2ETests/TestAssets/SuiteLifeCycleTestProject/LifeCycleDerivedClassCleanupEndOfClassAndBeforeEachDerivedClass.cs b/test/E2ETests/TestAssets/SuiteLifeCycleTestProject/LifeCycleDerivedClassCleanupEndOfClassAndBeforeEachDerivedClass.cs new file mode 100644 index 0000000000..145faeaa24 --- /dev/null +++ b/test/E2ETests/TestAssets/SuiteLifeCycleTestProject/LifeCycleDerivedClassCleanupEndOfClassAndBeforeEachDerivedClass.cs @@ -0,0 +1,50 @@ +// 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.VisualStudio.TestTools.UnitTesting; + +namespace SuiteLifeCycleTestProject; + +[TestClass] +public sealed class LifeCycleDerivedClassCleanupEndOfClassAndBeforeEachDerivedClass : LifeCycleClassCleanupEndOfClassAndBeforeEachDerivedClass +{ + private static TestContext s_testContext; + + public TestContext DerivedClassTestContext { get; set; } + + public LifeCycleDerivedClassCleanupEndOfClassAndBeforeEachDerivedClass() + { + s_testContext.WriteLine("LifeCycleDerivedClassCleanupEndOfClassAndBeforeEachDerivedClass.ctor was called"); + } + + [ClassInitialize] + public static void DerivedClassInitialize(TestContext testContext) + { + s_testContext = testContext; + s_testContext.WriteLine("LifeCycleDerivedClassCleanupEndOfClassAndBeforeEachDerivedClass.ClassInitialize was called"); + } + + [TestInitialize] + public void DerivedClassTestInitialize() + { + TestContext.WriteLine("LifeCycleDerivedClassCleanupEndOfClassAndBeforeEachDerivedClass.TestInitialize was called"); + } + + [TestMethod] + public void DerivedClassTestMethod() + { + TestContext.WriteLine("LifeCycleDerivedClassCleanupEndOfClassAndBeforeEachDerivedClass.TestMethod was called"); + } + + [TestCleanup] + public void DerivedClassTestCleanup() + { + TestContext.WriteLine("LifeCycleDerivedClassCleanupEndOfClassAndBeforeEachDerivedClass.TestCleanup was called"); + } + + [ClassCleanup] + public static void DerivedClassCleanup() + { + s_testContext.WriteLine("LifeCycleDerivedClassCleanupEndOfClassAndBeforeEachDerivedClass.ClassCleanup was called"); + } +} diff --git a/test/E2ETests/TestAssets/SuiteLifeCycleTestProject/LifeCycleDerivedClassCleanupEndOfClassAndNone.cs b/test/E2ETests/TestAssets/SuiteLifeCycleTestProject/LifeCycleDerivedClassCleanupEndOfClassAndNone.cs new file mode 100644 index 0000000000..083173a9e3 --- /dev/null +++ b/test/E2ETests/TestAssets/SuiteLifeCycleTestProject/LifeCycleDerivedClassCleanupEndOfClassAndNone.cs @@ -0,0 +1,50 @@ +// 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.VisualStudio.TestTools.UnitTesting; + +namespace SuiteLifeCycleTestProject; + +[TestClass] +public sealed class LifeCycleDerivedClassCleanupEndOfClassAndNone : LifeCycleClassCleanupEndOfClassAndNone +{ + private static TestContext s_testContext; + + public TestContext DerivedClassTestContext { get; set; } + + public LifeCycleDerivedClassCleanupEndOfClassAndNone() + { + s_testContext.WriteLine("LifeCycleDerivedClassCleanupEndOfClassAndNone.ctor was called"); + } + + [ClassInitialize] + public static void DerivedClassInitialize(TestContext testContext) + { + s_testContext = testContext; + s_testContext.WriteLine("LifeCycleDerivedClassCleanupEndOfClassAndNone.ClassInitialize was called"); + } + + [TestInitialize] + public void DerivedClassTestInitialize() + { + TestContext.WriteLine("LifeCycleDerivedClassCleanupEndOfClassAndNone.TestInitialize was called"); + } + + [TestMethod] + public void DerivedClassTestMethod() + { + TestContext.WriteLine("LifeCycleDerivedClassCleanupEndOfClassAndNone.TestMethod was called"); + } + + [TestCleanup] + public void DerivedClassTestCleanup() + { + TestContext.WriteLine("LifeCycleDerivedClassCleanupEndOfClassAndNone.TestCleanup was called"); + } + + [ClassCleanup] + public static void DerivedClassCleanup() + { + s_testContext.WriteLine("LifeCycleDerivedClassCleanupEndOfClassAndNone.ClassCleanup was called"); + } +}