From e6d275bc76bb1a704a42ca7b6d517f7ca4420a79 Mon Sep 17 00:00:00 2001 From: Stuart Ferguson Date: Tue, 30 Apr 2024 10:43:31 +0100 Subject: [PATCH] move integration tests to nunit --- .../AssemblyInfo.cs | 20 ++++++ .../Common/Setup.cs | 15 ++-- .../Email/SendEmail.feature.cs | 71 ++++++------------- .../MessagingService.IntegrationTests.csproj | 26 ++----- .../SMS/SendSMS.feature.cs | 66 +++++------------ 5 files changed, 74 insertions(+), 124 deletions(-) create mode 100644 MessagingService.IntegrationTests/AssemblyInfo.cs diff --git a/MessagingService.IntegrationTests/AssemblyInfo.cs b/MessagingService.IntegrationTests/AssemblyInfo.cs new file mode 100644 index 0000000..c2a40fb --- /dev/null +++ b/MessagingService.IntegrationTests/AssemblyInfo.cs @@ -0,0 +1,20 @@ +using NUnit.Framework; +using System.Runtime.InteropServices; + +// In SDK-style projects such as this one, several assembly attributes that were historically +// defined in this file are now automatically added during build and populated with +// values defined in project properties. For details of which attributes are included +// and how to customise this process see: https://aka.ms/assembly-info-properties + + +// Setting ComVisible to false makes the types in this assembly not visible to COM +// components. If you need to access a type in this assembly from COM, set the ComVisible +// attribute to true on that type. + +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM. + +[assembly: Guid("70c8d747-842f-4d4d-8c60-f7c46bf81088")] +[assembly: LevelOfParallelism(2)] +[assembly: Parallelizable(ParallelScope.Fixtures)] diff --git a/MessagingService.IntegrationTests/Common/Setup.cs b/MessagingService.IntegrationTests/Common/Setup.cs index c2d1529..3986eea 100644 --- a/MessagingService.IntegrationTests/Common/Setup.cs +++ b/MessagingService.IntegrationTests/Common/Setup.cs @@ -18,7 +18,8 @@ public class Setup public static INetworkService DatabaseServerNetwork; public static (String usename, String password) SqlCredentials = ("sa", "thisisalongpassword123!"); public static (String url, String username, String password) DockerCredentials = ("https://www.docker.com", "stuartferguson", "Sc0tland"); - + static object padLock = new object(); // Object to lock on + public static async Task GlobalSetup(DockerHelper dockerHelper) { ShouldlyConfiguration.DefaultTaskTimeout = TimeSpan.FromMinutes(1); @@ -26,10 +27,14 @@ public static async Task GlobalSetup(DockerHelper dockerHelper) dockerHelper.DockerCredentials = Setup.DockerCredentials; dockerHelper.SqlServerContainerName = "sharedsqlserver"; - await Retry.For(async () => { - Setup.DatabaseServerNetwork = dockerHelper.SetupTestNetwork("sharednetwork", true); - Setup.DatabaseServerContainer = await dockerHelper.SetupSqlServerContainer(Setup.DatabaseServerNetwork); - },TimeSpan.FromSeconds(60)); + // Only one thread can execute this block at a time + lock (Setup.padLock) + { + Setup.DatabaseServerNetwork = dockerHelper.SetupTestNetwork("sharednetwork"); + + dockerHelper.Logger.LogInformation("in start SetupSqlServerContainer"); + Setup.DatabaseServerContainer = dockerHelper.SetupSqlServerContainer(Setup.DatabaseServerNetwork).Result; + } } public static String GetConnectionString(String databaseName) diff --git a/MessagingService.IntegrationTests/Email/SendEmail.feature.cs b/MessagingService.IntegrationTests/Email/SendEmail.feature.cs index 8b896c4..d7136b2 100644 --- a/MessagingService.IntegrationTests/Email/SendEmail.feature.cs +++ b/MessagingService.IntegrationTests/Email/SendEmail.feature.cs @@ -19,48 +19,45 @@ namespace MessagingService.IntegrationTests.Email [System.CodeDom.Compiler.GeneratedCodeAttribute("Reqnroll", "1.0.0.0")] [System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - [Xunit.TraitAttribute("Category", "base")] - [Xunit.TraitAttribute("Category", "shared")] - [Xunit.TraitAttribute("Category", "email")] - public partial class SendEmailFeature : object, Xunit.IClassFixture, Xunit.IAsyncLifetime + [NUnit.Framework.TestFixtureAttribute()] + [NUnit.Framework.DescriptionAttribute("SendEmail")] + [NUnit.Framework.CategoryAttribute("base")] + [NUnit.Framework.CategoryAttribute("shared")] + [NUnit.Framework.CategoryAttribute("email")] + public partial class SendEmailFeature { - private static Reqnroll.ITestRunner testRunner; + private Reqnroll.ITestRunner testRunner; private static string[] featureTags = new string[] { "base", "shared", "email"}; - private Xunit.Abstractions.ITestOutputHelper _testOutputHelper; - #line 1 "SendEmail.feature" #line hidden - public SendEmailFeature(SendEmailFeature.FixtureData fixtureData, Xunit.Abstractions.ITestOutputHelper testOutputHelper) + [NUnit.Framework.OneTimeSetUpAttribute()] + public virtual async System.Threading.Tasks.Task FeatureSetupAsync() { - this._testOutputHelper = testOutputHelper; - } - - public static async System.Threading.Tasks.Task FeatureSetupAsync() - { - testRunner = Reqnroll.TestRunnerManager.GetTestRunnerForAssembly(null, Reqnroll.xUnit.ReqnrollPlugin.XUnitParallelWorkerTracker.Instance.GetWorkerId()); + testRunner = Reqnroll.TestRunnerManager.GetTestRunnerForAssembly(null, NUnit.Framework.TestContext.CurrentContext.WorkerId); Reqnroll.FeatureInfo featureInfo = new Reqnroll.FeatureInfo(new System.Globalization.CultureInfo("en-US"), "Email", "SendEmail", null, ProgrammingLanguage.CSharp, featureTags); await testRunner.OnFeatureStartAsync(featureInfo); } - public static async System.Threading.Tasks.Task FeatureTearDownAsync() + [NUnit.Framework.OneTimeTearDownAttribute()] + public virtual async System.Threading.Tasks.Task FeatureTearDownAsync() { - string testWorkerId = testRunner.TestWorkerId; await testRunner.OnFeatureEndAsync(); testRunner = null; - Reqnroll.xUnit.ReqnrollPlugin.XUnitParallelWorkerTracker.Instance.ReleaseWorker(testWorkerId); } + [NUnit.Framework.SetUpAttribute()] public async System.Threading.Tasks.Task TestInitializeAsync() { } + [NUnit.Framework.TearDownAttribute()] public async System.Threading.Tasks.Task TestTearDownAsync() { await testRunner.OnScenarioEndAsync(); @@ -69,7 +66,7 @@ public async System.Threading.Tasks.Task TestTearDownAsync() public void ScenarioInitialize(Reqnroll.ScenarioInfo scenarioInfo) { testRunner.OnScenarioInitialize(scenarioInfo); - testRunner.ScenarioContext.ScenarioContainer.RegisterInstanceAs(_testOutputHelper); + testRunner.ScenarioContext.ScenarioContainer.RegisterInstanceAs(NUnit.Framework.TestContext.CurrentContext); } public async System.Threading.Tasks.Task ScenarioStartAsync() @@ -136,19 +133,8 @@ public virtual async System.Threading.Tasks.Task FeatureBackgroundAsync() #line hidden } - async System.Threading.Tasks.Task Xunit.IAsyncLifetime.InitializeAsync() - { - await this.TestInitializeAsync(); - } - - async System.Threading.Tasks.Task Xunit.IAsyncLifetime.DisposeAsync() - { - await this.TestTearDownAsync(); - } - - [Xunit.SkippableFactAttribute(DisplayName="Send Email")] - [Xunit.TraitAttribute("FeatureTitle", "SendEmail")] - [Xunit.TraitAttribute("Description", "Send Email")] + [NUnit.Framework.TestAttribute()] + [NUnit.Framework.DescriptionAttribute("Send Email")] public async System.Threading.Tasks.Task SendEmail() { string[] tagsOfScenario = ((string[])(null)); @@ -192,10 +178,9 @@ public async System.Threading.Tasks.Task SendEmail() await this.ScenarioCleanupAsync(); } - [Xunit.SkippableFactAttribute(DisplayName="Resend Email")] - [Xunit.TraitAttribute("FeatureTitle", "SendEmail")] - [Xunit.TraitAttribute("Description", "Resend Email")] - [Xunit.TraitAttribute("Category", "PRTest")] + [NUnit.Framework.TestAttribute()] + [NUnit.Framework.DescriptionAttribute("Resend Email")] + [NUnit.Framework.CategoryAttribute("PRTest")] public async System.Threading.Tasks.Task ResendEmail() { string[] tagsOfScenario = new string[] { @@ -248,22 +233,6 @@ public async System.Threading.Tasks.Task ResendEmail() } await this.ScenarioCleanupAsync(); } - - [System.CodeDom.Compiler.GeneratedCodeAttribute("Reqnroll", "1.0.0.0")] - [System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - public class FixtureData : object, Xunit.IAsyncLifetime - { - - async System.Threading.Tasks.Task Xunit.IAsyncLifetime.InitializeAsync() - { - await SendEmailFeature.FeatureSetupAsync(); - } - - async System.Threading.Tasks.Task Xunit.IAsyncLifetime.DisposeAsync() - { - await SendEmailFeature.FeatureTearDownAsync(); - } - } } } #pragma warning restore diff --git a/MessagingService.IntegrationTests/MessagingService.IntegrationTests.csproj b/MessagingService.IntegrationTests/MessagingService.IntegrationTests.csproj index a51f34e..5a268df 100644 --- a/MessagingService.IntegrationTests/MessagingService.IntegrationTests.csproj +++ b/MessagingService.IntegrationTests/MessagingService.IntegrationTests.csproj @@ -6,20 +6,18 @@ - + - + + + + - + - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - all runtime; build; native; contentfiles; analyzers; buildtransitive @@ -32,18 +30,6 @@ - - True diff --git a/MessagingService.IntegrationTests/SMS/SendSMS.feature.cs b/MessagingService.IntegrationTests/SMS/SendSMS.feature.cs index 82ba072..3ba5771 100644 --- a/MessagingService.IntegrationTests/SMS/SendSMS.feature.cs +++ b/MessagingService.IntegrationTests/SMS/SendSMS.feature.cs @@ -19,48 +19,45 @@ namespace MessagingService.IntegrationTests.SMS [System.CodeDom.Compiler.GeneratedCodeAttribute("Reqnroll", "1.0.0.0")] [System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - [Xunit.TraitAttribute("Category", "base")] - [Xunit.TraitAttribute("Category", "shared")] - [Xunit.TraitAttribute("Category", "sms")] - public partial class SendSMSFeature : object, Xunit.IClassFixture, Xunit.IAsyncLifetime + [NUnit.Framework.TestFixtureAttribute()] + [NUnit.Framework.DescriptionAttribute("SendSMS")] + [NUnit.Framework.CategoryAttribute("base")] + [NUnit.Framework.CategoryAttribute("shared")] + [NUnit.Framework.CategoryAttribute("sms")] + public partial class SendSMSFeature { - private static Reqnroll.ITestRunner testRunner; + private Reqnroll.ITestRunner testRunner; private static string[] featureTags = new string[] { "base", "shared", "sms"}; - private Xunit.Abstractions.ITestOutputHelper _testOutputHelper; - #line 1 "SendSMS.feature" #line hidden - public SendSMSFeature(SendSMSFeature.FixtureData fixtureData, Xunit.Abstractions.ITestOutputHelper testOutputHelper) + [NUnit.Framework.OneTimeSetUpAttribute()] + public virtual async System.Threading.Tasks.Task FeatureSetupAsync() { - this._testOutputHelper = testOutputHelper; - } - - public static async System.Threading.Tasks.Task FeatureSetupAsync() - { - testRunner = Reqnroll.TestRunnerManager.GetTestRunnerForAssembly(null, Reqnroll.xUnit.ReqnrollPlugin.XUnitParallelWorkerTracker.Instance.GetWorkerId()); + testRunner = Reqnroll.TestRunnerManager.GetTestRunnerForAssembly(null, NUnit.Framework.TestContext.CurrentContext.WorkerId); Reqnroll.FeatureInfo featureInfo = new Reqnroll.FeatureInfo(new System.Globalization.CultureInfo("en-US"), "SMS", "SendSMS", null, ProgrammingLanguage.CSharp, featureTags); await testRunner.OnFeatureStartAsync(featureInfo); } - public static async System.Threading.Tasks.Task FeatureTearDownAsync() + [NUnit.Framework.OneTimeTearDownAttribute()] + public virtual async System.Threading.Tasks.Task FeatureTearDownAsync() { - string testWorkerId = testRunner.TestWorkerId; await testRunner.OnFeatureEndAsync(); testRunner = null; - Reqnroll.xUnit.ReqnrollPlugin.XUnitParallelWorkerTracker.Instance.ReleaseWorker(testWorkerId); } + [NUnit.Framework.SetUpAttribute()] public async System.Threading.Tasks.Task TestInitializeAsync() { } + [NUnit.Framework.TearDownAttribute()] public async System.Threading.Tasks.Task TestTearDownAsync() { await testRunner.OnScenarioEndAsync(); @@ -69,7 +66,7 @@ public async System.Threading.Tasks.Task TestTearDownAsync() public void ScenarioInitialize(Reqnroll.ScenarioInfo scenarioInfo) { testRunner.OnScenarioInitialize(scenarioInfo); - testRunner.ScenarioContext.ScenarioContainer.RegisterInstanceAs(_testOutputHelper); + testRunner.ScenarioContext.ScenarioContainer.RegisterInstanceAs(NUnit.Framework.TestContext.CurrentContext); } public async System.Threading.Tasks.Task ScenarioStartAsync() @@ -136,20 +133,9 @@ public virtual async System.Threading.Tasks.Task FeatureBackgroundAsync() #line hidden } - async System.Threading.Tasks.Task Xunit.IAsyncLifetime.InitializeAsync() - { - await this.TestInitializeAsync(); - } - - async System.Threading.Tasks.Task Xunit.IAsyncLifetime.DisposeAsync() - { - await this.TestTearDownAsync(); - } - - [Xunit.SkippableFactAttribute(DisplayName="Send SMS")] - [Xunit.TraitAttribute("FeatureTitle", "SendSMS")] - [Xunit.TraitAttribute("Description", "Send SMS")] - [Xunit.TraitAttribute("Category", "PRTest")] + [NUnit.Framework.TestAttribute()] + [NUnit.Framework.DescriptionAttribute("Send SMS")] + [NUnit.Framework.CategoryAttribute("PRTest")] public async System.Threading.Tasks.Task SendSMS() { string[] tagsOfScenario = new string[] { @@ -183,22 +169,6 @@ public async System.Threading.Tasks.Task SendSMS() } await this.ScenarioCleanupAsync(); } - - [System.CodeDom.Compiler.GeneratedCodeAttribute("Reqnroll", "1.0.0.0")] - [System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - public class FixtureData : object, Xunit.IAsyncLifetime - { - - async System.Threading.Tasks.Task Xunit.IAsyncLifetime.InitializeAsync() - { - await SendSMSFeature.FeatureSetupAsync(); - } - - async System.Threading.Tasks.Task Xunit.IAsyncLifetime.DisposeAsync() - { - await SendSMSFeature.FeatureTearDownAsync(); - } - } } } #pragma warning restore