Skip to content

Commit

Permalink
set MessageHeader.CurrentProgramName at test fixture level
Browse files Browse the repository at this point in the history
  • Loading branch information
rkm committed Oct 10, 2024
1 parent 373e9a1 commit a09d8dd
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ public class ExtractImagesHostTests
public void OneTimeSetUp()
{
TestLogger.Setup();
MessageHeader.CurrentProgramName = nameof(ExtractImagesHostTests);
}

[OneTimeTearDown]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ public class HeaderPreservationTest
public void OneTimeSetUp()
{
TestLogger.Setup();
MessageHeader.CurrentProgramName = nameof(HeaderPreservationTest);
}

[Test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ public void OneTimeSetUp()

_mockConsumer = Mock.Of<Consumer<IMessage>>();
_tester = new MicroserviceTester(_testOptions.RabbitOptions!, _testConsumerOptions);

MessageHeader.CurrentProgramName = nameof(RabbitMQBrokerTests);
}

[OneTimeTearDown]
Expand Down
14 changes: 14 additions & 0 deletions tests/SmiServices.IntegrationTests/FixtureSetup.cs
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ public class CohortPackagerHostTest
public void OneTimeSetUp()
{
TestLogger.Setup();
MessageHeader.CurrentProgramName = nameof(CohortPackagerHostTest);
}

[OneTimeTearDown]
Expand Down
14 changes: 11 additions & 3 deletions tests/SmiServices.UnitTests/Common/Messages/MessageHeaderTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ public void OneTimeTearDown() { }
[SetUp]
public void SetUp()
{
MessageHeader.CurrentProgramName = nameof(MessageHeaderTest);
}

[TearDown]
Expand Down Expand Up @@ -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<Exception>(() => new MessageHeader());
Assert.That(exc.Message, Is.EqualTo("Value must be set before use"));
try
{
var exc = Assert.Throws<Exception>(() => new MessageHeader());

Assert.That(exc.Message, Is.EqualTo("Value must be set before use"));
}
finally
{
MessageHeader.CurrentProgramName = original;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ public class MongoDocumentHeadersTests
[OneTimeSetUp]
public void OneTimeSetUp()
{
MessageHeader.CurrentProgramName = nameof(MongoDocumentHeadersTests);
}

[Test]
Expand Down
14 changes: 14 additions & 0 deletions tests/SmiServices.UnitTests/FixtureSetup.cs
Original file line number Diff line number Diff line change
@@ -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);
}
}

0 comments on commit a09d8dd

Please sign in to comment.