Skip to content

Commit

Permalink
Test the producer registry merge edge cases; #3073
Browse files Browse the repository at this point in the history
  • Loading branch information
iancooper committed May 8, 2024
1 parent 7f0584c commit bf9d4a6
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ public static class ProducerRegistryExtensions
{
public static IAmAProducerRegistry Merge(this IAmAProducerRegistry lhs, IAmAProducerRegistry rhs)
{
if (rhs == null)
return lhs;

if (lhs == null)
return rhs;

var producers =
lhs
.KeyedProducers.Concat(rhs.KeyedProducers)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,72 @@ public void When_Merging_Two_Producer_Registries()
producerRegistry.LookupBy("TestTwo").Should().NotBeNull();

}

[Fact]
public void When_Merging_With_A_Null__Rhs_Registry()
{
var producerRegistryOne = new ProducerRegistry(
new Dictionary<string, IAmAMessageProducer>{{"TestOne", new FakeMessageProducer()}}
);

//act
var producerRegistry = producerRegistryOne.Merge(null);

//assert
producerRegistry.LookupBy("TestOne").Should().NotBeNull();

}

[Fact]
public void When_Merging_With_A_Null__Lhs_Registry()
{
//arrange
var producerRegistryTwo = new ProducerRegistry(
new Dictionary<string, IAmAMessageProducer>{{"TestTwo", new FakeMessageProducer()}}
);

//act
var producerRegistry =ProducerRegistryExtensions.Merge(null, producerRegistryTwo);

//assert
producerRegistry.LookupBy("TestTwo").Should().NotBeNull();

}

[Fact]
public void When_Merging_With_An_Empty_Rhs_Registry()
{
//arrange
var producerRegistryOne = new ProducerRegistry(
new Dictionary<string, IAmAMessageProducer>{{"TestOne", new FakeMessageProducer()}}
);

var producerRegistryTwo = new ProducerRegistry(new Dictionary<string, IAmAMessageProducer>());

//act
var producerRegistry = producerRegistryOne.Merge(producerRegistryTwo);

//assert
producerRegistry.LookupBy("TestOne").Should().NotBeNull();

}

[Fact]
public void When_Merging_With_An_Empty_Lhs_Registry()
{
//arrange
var producerRegistryOne = new ProducerRegistry(new Dictionary<string, IAmAMessageProducer>());

var producerRegistryTwo = new ProducerRegistry(
new Dictionary<string, IAmAMessageProducer>{{"TestTwo", new FakeMessageProducer()}}
);

//act
var producerRegistry = producerRegistryOne.Merge(producerRegistryTwo);

//assert
producerRegistry.LookupBy("TestTwo").Should().NotBeNull();

}

}

0 comments on commit bf9d4a6

Please sign in to comment.