diff --git a/tests/SmiServices.IntegrationTests/Applications/DicomLoader/DicomLoaderTests.cs b/tests/SmiServices.IntegrationTests/Applications/DicomLoader/DicomLoaderTests.cs index 2e4ac0ae0..1ce771895 100644 --- a/tests/SmiServices.IntegrationTests/Applications/DicomLoader/DicomLoaderTests.cs +++ b/tests/SmiServices.IntegrationTests/Applications/DicomLoader/DicomLoaderTests.cs @@ -44,8 +44,6 @@ public void Setup() helper.SetupSuite(db, RepositoryLocator, _gOptions, typeof(DicomDatasetCollectionSource)); Debug.Assert(helper.LoadMetadata != null, "helper.LoadMetadata != null"); _gOptions.DicomRelationalMapperOptions!.LoadMetadataId = helper.LoadMetadata?.ID ?? throw new Exception("No LoadMetadataId"); - - MessageHeader.CurrentProgramName = nameof(DicomLoaderTests); } [Test] diff --git a/tests/SmiServices.IntegrationTests/Applications/ExtractImages/ExtractImagesHostTests.cs b/tests/SmiServices.IntegrationTests/Applications/ExtractImages/ExtractImagesHostTests.cs index 9673044b0..12a92b3e1 100644 --- a/tests/SmiServices.IntegrationTests/Applications/ExtractImages/ExtractImagesHostTests.cs +++ b/tests/SmiServices.IntegrationTests/Applications/ExtractImages/ExtractImagesHostTests.cs @@ -24,7 +24,6 @@ public class ExtractImagesHostTests public void OneTimeSetUp() { TestLogger.Setup(); - MessageHeader.CurrentProgramName = nameof(ExtractImagesHostTests); } [OneTimeTearDown] diff --git a/tests/SmiServices.IntegrationTests/Applications/TriggerUpdates/MapperSourceIntegrationTest.cs b/tests/SmiServices.IntegrationTests/Applications/TriggerUpdates/MapperSourceIntegrationTest.cs index d1dd09d27..3c34cb835 100644 --- a/tests/SmiServices.IntegrationTests/Applications/TriggerUpdates/MapperSourceIntegrationTest.cs +++ b/tests/SmiServices.IntegrationTests/Applications/TriggerUpdates/MapperSourceIntegrationTest.cs @@ -31,8 +31,6 @@ class MapperSourceIntegrationTest : DatabaseTests [TestCase(DatabaseType.MySql)] public void MapperSource_IntegrationTest(DatabaseType dbType) { - MessageHeader.CurrentProgramName = nameof(MapperSourceIntegrationTest); - var db = GetCleanedServer(dbType); DataTable dt = new(); diff --git a/tests/SmiServices.IntegrationTests/Common/HeaderPreservationTest.cs b/tests/SmiServices.IntegrationTests/Common/HeaderPreservationTest.cs index 3c113f43b..488070bdd 100644 --- a/tests/SmiServices.IntegrationTests/Common/HeaderPreservationTest.cs +++ b/tests/SmiServices.IntegrationTests/Common/HeaderPreservationTest.cs @@ -16,7 +16,6 @@ public class HeaderPreservationTest public void OneTimeSetUp() { TestLogger.Setup(); - MessageHeader.CurrentProgramName = nameof(HeaderPreservationTest); } [Test] diff --git a/tests/SmiServices.IntegrationTests/Common/Messaging/RabbitMQBrokerTests.cs b/tests/SmiServices.IntegrationTests/Common/Messaging/RabbitMQBrokerTests.cs index 9348ca6ec..dc790f0cc 100644 --- a/tests/SmiServices.IntegrationTests/Common/Messaging/RabbitMQBrokerTests.cs +++ b/tests/SmiServices.IntegrationTests/Common/Messaging/RabbitMQBrokerTests.cs @@ -48,8 +48,6 @@ public void OneTimeSetUp() _mockConsumer = Mock.Of>(); _tester = new MicroserviceTester(_testOptions.RabbitOptions!, _testConsumerOptions); - - MessageHeader.CurrentProgramName = nameof(RabbitMQBrokerTests); } [OneTimeTearDown] diff --git a/tests/SmiServices.IntegrationTests/FixtureSetup.cs b/tests/SmiServices.IntegrationTests/FixtureSetup.cs new file mode 100644 index 000000000..9bd482432 --- /dev/null +++ b/tests/SmiServices.IntegrationTests/FixtureSetup.cs @@ -0,0 +1,14 @@ +using NUnit.Framework; +using SmiServices.Common.Messages; + +namespace SmiServices.IntegrationTests; + +[SetUpFixture] +internal class FixtureSetup +{ + [OneTimeSetUp] + public void OneTimeSetUp() + { + MessageHeader.CurrentProgramName = nameof(IntegrationTests); + } +} diff --git a/tests/SmiServices.IntegrationTests/Microservices/CohortPackager/CohortPackagerHostTest.cs b/tests/SmiServices.IntegrationTests/Microservices/CohortPackager/CohortPackagerHostTest.cs index afb952684..0ea1c9d12 100644 --- a/tests/SmiServices.IntegrationTests/Microservices/CohortPackager/CohortPackagerHostTest.cs +++ b/tests/SmiServices.IntegrationTests/Microservices/CohortPackager/CohortPackagerHostTest.cs @@ -32,7 +32,6 @@ public class CohortPackagerHostTest public void OneTimeSetUp() { TestLogger.Setup(); - MessageHeader.CurrentProgramName = nameof(CohortPackagerHostTest); } [OneTimeTearDown] diff --git a/tests/SmiServices.UnitTests/Common/Messages/MessageHeaderTest.cs b/tests/SmiServices.UnitTests/Common/Messages/MessageHeaderTest.cs index 34e884778..1bc9792ae 100644 --- a/tests/SmiServices.UnitTests/Common/Messages/MessageHeaderTest.cs +++ b/tests/SmiServices.UnitTests/Common/Messages/MessageHeaderTest.cs @@ -36,7 +36,6 @@ public void OneTimeTearDown() { } [SetUp] public void SetUp() { - MessageHeader.CurrentProgramName = nameof(MessageHeaderTest); } [TearDown] @@ -80,10 +79,19 @@ public void TestMessageHeader_GetHashCode() [Test] public void CurrentProgramName_Unset_ThrowsException() { + var original = MessageHeader.CurrentProgramName; MessageHeader.CurrentProgramName = null!; - var exc = Assert.Throws(() => new MessageHeader()); - Assert.That(exc.Message, Is.EqualTo("Value must be set before use")); + try + { + var exc = Assert.Throws(() => new MessageHeader()); + + Assert.That(exc.Message, Is.EqualTo("Value must be set before use")); + } + finally + { + MessageHeader.CurrentProgramName = original; + } } } } diff --git a/tests/SmiServices.UnitTests/Common/MongoDB/MongoDocumentHeadersTests.cs b/tests/SmiServices.UnitTests/Common/MongoDB/MongoDocumentHeadersTests.cs index f899a6608..8e5bc5087 100644 --- a/tests/SmiServices.UnitTests/Common/MongoDB/MongoDocumentHeadersTests.cs +++ b/tests/SmiServices.UnitTests/Common/MongoDB/MongoDocumentHeadersTests.cs @@ -15,7 +15,6 @@ public class MongoDocumentHeadersTests [OneTimeSetUp] public void OneTimeSetUp() { - MessageHeader.CurrentProgramName = nameof(MongoDocumentHeadersTests); } [Test] diff --git a/tests/SmiServices.UnitTests/FixtureSetup.cs b/tests/SmiServices.UnitTests/FixtureSetup.cs new file mode 100644 index 000000000..a45bbde5e --- /dev/null +++ b/tests/SmiServices.UnitTests/FixtureSetup.cs @@ -0,0 +1,14 @@ +using NUnit.Framework; +using SmiServices.Common.Messages; + +namespace SmiServices.UnitTests; + +[SetUpFixture] +internal class FixtureSetup +{ + [OneTimeSetUp] + public void OneTimeSetUp() + { + MessageHeader.CurrentProgramName = nameof(UnitTests); + } +} diff --git a/tests/SmiServices.UnitTests/Microservices/CohortExtractor/Messaging/ExtractionRequestQueueConsumerTest.cs b/tests/SmiServices.UnitTests/Microservices/CohortExtractor/Messaging/ExtractionRequestQueueConsumerTest.cs index 23084e10a..2c44c37a4 100644 --- a/tests/SmiServices.UnitTests/Microservices/CohortExtractor/Messaging/ExtractionRequestQueueConsumerTest.cs +++ b/tests/SmiServices.UnitTests/Microservices/CohortExtractor/Messaging/ExtractionRequestQueueConsumerTest.cs @@ -28,7 +28,6 @@ public class ExtractionRequestQueueConsumerTest public void OneTimeSetUp() { TestLogger.Setup(); - MessageHeader.CurrentProgramName = nameof(ExtractionRequestQueueConsumerTest); } [OneTimeTearDown]