-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: preserve message context items when SetMessage is called
- Loading branch information
1 parent
dc0882f
commit 4f79c43
Showing
2 changed files
with
54 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
using System.Collections.Generic; | ||
using KafkaFlow.Consumers; | ||
using KafkaFlow.Producers; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using Moq; | ||
|
||
namespace KafkaFlow.UnitTests; | ||
|
||
[TestClass] | ||
public class MessageContextTests | ||
{ | ||
[TestMethod] | ||
public void SetMessage_ShouldSetMessageCorrectly() | ||
{ | ||
// Arrange | ||
var messageContext = new MessageContext( | ||
new Message("key", "value"), | ||
Mock.Of<IMessageHeaders>(), | ||
Mock.Of<IDependencyResolver>(), | ||
Mock.Of<IConsumerContext>(), | ||
Mock.Of<IProducerContext>(), | ||
Mock.Of<IReadOnlyCollection<string>>() | ||
); | ||
|
||
|
||
// Act | ||
var changedMessage = messageContext.SetMessage("changed-key", "changed-value"); | ||
|
||
// Assert | ||
Assert.AreEqual("changed-key", changedMessage.Message.Key); | ||
Assert.AreEqual("changed-value", changedMessage.Message.Value); | ||
Assert.AreSame(messageContext.ConsumerContext, changedMessage.ConsumerContext); | ||
Assert.AreSame(messageContext.DependencyResolver, changedMessage.DependencyResolver); | ||
Assert.AreSame(messageContext.Headers, changedMessage.Headers); | ||
Assert.AreSame(messageContext.ProducerContext, changedMessage.ProducerContext); | ||
Assert.AreSame(messageContext.Brokers, changedMessage.Brokers); | ||
Assert.AreSame(messageContext.Items, changedMessage.Items); | ||
} | ||
} |