public void LeaveMutable() { var accessor = new MessageHeaderAccessor(); accessor.SetHeader("foo", "bar"); accessor.LeaveMutable = true; var headers = accessor.MessageHeaders; var message = MessageBuilder <string> .CreateMessage("payload", headers); accessor.SetHeader("foo", "baz"); Assert.Equal("baz", headers.Get <string>("foo")); Assert.Same(accessor, MessageHeaderAccessor.GetAccessor <MessageHeaderAccessor>(message, typeof(MessageHeaderAccessor))); }
public void LeaveMutableDefaultBehavior() { var accessor = new MessageHeaderAccessor(); accessor.SetHeader("foo", "bar"); var headers = accessor.MessageHeaders; var message = MessageBuilder <string> .CreateMessage("payload", headers); Assert.Throws <InvalidOperationException>(() => accessor.LeaveMutable = true); Assert.Throws <InvalidOperationException>(() => accessor.SetHeader("foo", "baz")); Assert.Equal("bar", headers.Get <string>("foo")); Assert.Same(accessor, MessageHeaderAccessor.GetAccessor <MessageHeaderAccessor>(message, typeof(MessageHeaderAccessor))); }
public void SendWithTimeoutMutable() { IMessage sent = null; var chanMock = new Mock <ISubscribableChannel>(); var channel = chanMock.Object; chanMock.Setup( chan => chan.Send(It.IsAny <IMessage>(), It.Is <int>(i => i == 30000))) .Callback <IMessage, int>((m, t) => sent = m) .Returns(true); var accessor = new MessageHeaderAccessor { LeaveMutable = true }; var message = Message.Create <string>("request", accessor.MessageHeaders); accessor.SetHeader(MessageChannelTemplate.DEFAULT_SEND_TIMEOUT_HEADER, 30000); Template.Send(channel, message); chanMock.Verify(chan => chan.Send(It.IsAny <IMessage>(), It.Is <int>(i => i == 30000))); Assert.NotNull(sent); Assert.False(sent.Headers.ContainsKey(MessageChannelTemplate.DEFAULT_SEND_TIMEOUT_HEADER)); Assert.False(sent.Headers.ContainsKey(MessageChannelTemplate.DEFAULT_RECEIVE_TIMEOUT_HEADER)); }
public async Task SendAsyncWithTimeoutMutable() { IMessage sent = null; var chanMock = new Mock <ISubscribableChannel>(); var channel = chanMock.Object; chanMock.Setup( chan => chan.SendAsync(It.IsAny <IMessage>(), It.Is <CancellationToken>(t => t.IsCancellationRequested == false))) .Callback <IMessage, CancellationToken>((m, t) => sent = m) .Returns(new ValueTask <bool>(true)); var accessor = new MessageHeaderAccessor { LeaveMutable = true }; var message = Message.Create <string>("request", accessor.MessageHeaders); accessor.SetHeader(MessageChannelTemplate.DEFAULT_SEND_TIMEOUT_HEADER, 30000); await Template.SendAsync(channel, message); chanMock.Verify(chan => chan.SendAsync(It.IsAny <IMessage>(), It.Is <CancellationToken>(t => t.IsCancellationRequested == false))); Assert.NotNull(sent); Assert.False(sent.Headers.ContainsKey(MessageChannelTemplate.DEFAULT_SEND_TIMEOUT_HEADER)); Assert.False(sent.Headers.ContainsKey(MessageChannelTemplate.DEFAULT_RECEIVE_TIMEOUT_HEADER)); }
public void TestBuildMultipleIMessages() { var headerAccessor = new MessageHeaderAccessor(); var messageBuilder = MessageBuilder.WithPayload("payload").SetHeaders(headerAccessor); headerAccessor.SetHeader("foo", "bar1"); var message1 = messageBuilder.Build(); headerAccessor.SetHeader("foo", "bar2"); var message2 = messageBuilder.Build(); headerAccessor.SetHeader("foo", "bar3"); var message3 = messageBuilder.Build(); Assert.Equal("bar1", message1.Headers.Get <string>("foo")); Assert.Equal("bar2", message2.Headers.Get <string>("foo")); Assert.Equal("bar3", message3.Headers.Get <string>("foo")); }
public void TestBuildIMessageWithDefaultMutability() { var accessor = new MessageHeaderAccessor(); var headers = accessor.MessageHeaders; var message = MessageBuilder.CreateMessage("foo", headers); Assert.Throws <InvalidOperationException>(() => accessor.SetHeader("foo", "bar")); Assert.Equal(accessor, MessageHeaderAccessor.GetAccessor(message, typeof(MessageHeaderAccessor))); }
public void ToDictionary() { var accessor = new MessageHeaderAccessor(); accessor.SetHeader("foo", "bar1"); var map1 = accessor.ToDictionary(); accessor.SetHeader("foo", "bar2"); var map2 = accessor.ToDictionary(); accessor.SetHeader("foo", "bar3"); var map3 = accessor.ToDictionary(); Assert.Equal(1, map1.Count); Assert.Equal(1, map2.Count); Assert.Equal(1, map3.Count); Assert.Equal("bar1", map1["foo"]); Assert.Equal("bar2", map2["foo"]); Assert.Equal("bar3", map3["foo"]); }
public void TestBuildIMessageWithMutableHeaders() { var accessor = new MessageHeaderAccessor { LeaveMutable = true }; var headers = accessor.MessageHeaders; var message = MessageBuilder.CreateMessage("payload", headers); accessor.SetHeader("foo", "bar"); Assert.Equal("bar", headers.Get <string>("foo")); Assert.Equal(accessor, MessageHeaderAccessor.GetAccessor(message, typeof(MessageHeaderAccessor))); }
public void ToMessageWithPayloadAndMutableHeaders() { var accessor = new MessageHeaderAccessor(); accessor.SetHeader("foo", "bar"); accessor.LeaveMutable = true; var headers = accessor.MessageHeaders; var converter = new SimpleMessageConverter(); var message = converter.ToMessage("payload", headers); Assert.Equal("payload", message.Payload); Assert.Same(headers, message.Headers); Assert.Equal("bar", message.Headers["foo"]); }
public void ToMessageWithMutableMessageHeaders() { var accessor = new MessageHeaderAccessor(); accessor.SetHeader("foo", "bar"); accessor.LeaveMutable = true; var headers = accessor.MessageHeaders; var converter = new TestMessageConverter(); var message = converter.ToMessage("ABC", headers); Assert.Same(headers, message.Headers); Assert.Null(message.Headers.Id); Assert.Null(message.Headers.Timestamp); Assert.Equal(MimeTypeUtils.TEXT_PLAIN, message.Headers[MessageHeaders.CONTENT_TYPE]); }
public void ConvertAndSendPayloadAndMutableHeadersToDestination() { var accessor = new MessageHeaderAccessor(); accessor.SetHeader("foo", "bar"); accessor.LeaveMutable = true; var messageHeaders = accessor.MessageHeaders; _template.MessageConverter = new StringMessageConverter(); _template.ConvertAndSend("somewhere", "payload", messageHeaders); var actual = _template.Message.Headers; Assert.Same(messageHeaders, actual); Assert.Equal(new MimeType("text", "plain", Encoding.UTF8), actual[MessageHeaders.CONTENT_TYPE]); Assert.Equal("bar", actual["foo"]); }
public void ExistingHeadersModification() { IDictionary <string, object> map = new Dictionary <string, object>(); map.Add("foo", "bar"); map.Add("bar", "baz"); var message = new GenericMessage <string>("payload", map); Thread.Sleep(50); var accessor = new MessageHeaderAccessor(message); accessor.SetHeader("foo", "BAR"); var actual = accessor.MessageHeaders; Assert.Equal(3, actual.Count); Assert.NotEqual(message.Headers.Id, actual.Id); Assert.Equal("BAR", actual.Get <string>("foo")); Assert.Equal("baz", actual.Get <string>("bar")); }
public void ExistingHeadersModification() { IDictionary <string, object> map = new Dictionary <string, object> { { "foo", "bar" }, { "bar", "baz" } }; var message = Message.Create <string>("payload", map); Thread.Sleep(50); var accessor = new MessageHeaderAccessor(message); accessor.SetHeader("foo", "BAR"); var actual = accessor.MessageHeaders; Assert.Equal(3, ((HeadersDictionary)actual).Count); Assert.NotEqual(message.Headers.Id, actual.Id); Assert.Equal("BAR", actual.Get <string>("foo")); Assert.Equal("baz", actual.Get <string>("bar")); }