public void TestMessageHeaderIsSerializable() { var payload = new object(); var uuid = Guid.NewGuid(); var timestamp = DateTimeOffset.Now.ToUnixTimeMilliseconds(); // UUID as string; timestamp as string var headerDictionarystrings = new Dictionary <string, object>(); headerDictionarystrings.Add(MessageHeaders.ID, uuid.ToString()); headerDictionarystrings.Add(MessageHeaders.TIMESTAMP, timestamp.ToString()); var mutableMessagestrings = new MutableMessage <object>(payload, headerDictionarystrings); Assert.Equal(uuid, mutableMessagestrings.Headers.Id); Assert.Equal(timestamp, mutableMessagestrings.Headers.Timestamp); // UUID as byte[]; timestamp as Long var headerDictionaryByte = new Dictionary <string, object>(); var uuidAsBytes = uuid.ToByteArray(); headerDictionaryByte.Add(MessageHeaders.ID, uuidAsBytes); headerDictionaryByte.Add(MessageHeaders.TIMESTAMP, timestamp); var mutableMessageBytes = new MutableMessage <object>(payload, headerDictionaryByte); Assert.Equal(uuid, mutableMessageBytes.Headers.Id); Assert.Equal(timestamp, mutableMessageBytes.Headers.Timestamp); }
public void Deserialize_restores_mutable_message_correctly() { // Arrange var sut = new JsonMessageSerializer(); MutableMessage message = fixture.Create <MutableMessage>(); string serialized = sut.Serialize(message); TestContext.WriteLine(serialized); // Act object actual = sut.Deserialize(serialized); // Assert actual.Should().BeOfType <MutableMessage>(); actual.Should().BeEquivalentTo(message); }
public void TestMessageHeaderIsSettable() { var payload = new object(); var headerDictionary = new Dictionary <string, object>(); var additional = new Dictionary <string, object>(); var mutableMessage = new MutableMessage <object>(payload, headerDictionary); var headers = mutableMessage.Headers as MutableMessageHeaders; // Should not throw an UnsupportedOperationException headers.Add("foo", "bar"); headers.Add("eep", "bar"); headers.Remove("eep"); headers.AddRange(additional); Assert.Equal("bar", headers.RawHeaders["foo"]); }
public void TestMessageIdTimestampRemains() { var uuid = Guid.NewGuid(); var timestamp = DateTimeOffset.Now.ToUnixTimeMilliseconds(); var payload = new object(); var headerDictionary = new Dictionary <string, object>(); headerDictionary.Add(MessageHeaders.ID, uuid); headerDictionary.Add(MessageHeaders.TIMESTAMP, timestamp); var mutableMessage = new MutableMessage <object>(payload, headerDictionary); var headers = mutableMessage.Headers as MutableMessageHeaders; Assert.Equal(uuid, headers.RawHeaders[MessageHeaders.ID]); Assert.Equal(timestamp, headers.RawHeaders[MessageHeaders.TIMESTAMP]); }