// This unit test verifies that a message based on a POCO class can be serialized/deserialized. // This was not working in v1.3.0 and was fixed in v1.4.0 public void Add_and_get_POCO_message() { // Arrange var queueName = "myqueue"; var mockQueue = Misc.GetMockQueue(queueName); var mockQueueClient = Misc.GetMockQueueClient(mockQueue); var mockBlobContainer = Misc.GetMockBlobContainer(); var mockBlobClient = Misc.GetMockBlobClient(mockBlobContainer); var storageAccount = Misc.GetMockStorageAccount(mockBlobClient, mockQueueClient); var queuedMessage = (CloudQueueMessage)null; var sampleMessage = new SampleMessageType { DateProp = new DateTime(2016, 10, 8, 1, 2, 3, DateTimeKind.Utc), GuidProp = Guid.NewGuid(), IntProp = 123, StringProp = "Hello World" }; mockQueue .Setup(c => c.AddMessageAsync(It.IsAny <CloudQueueMessage>(), It.IsAny <TimeSpan?>(), It.IsAny <TimeSpan?>(), It.IsAny <QueueRequestOptions>(), It.IsAny <OperationContext>(), It.IsAny <CancellationToken>())) .Callback((CloudQueueMessage m, TimeSpan? ttl, TimeSpan? v, QueueRequestOptions o, OperationContext c, CancellationToken t) => { queuedMessage = m; }) .Returns(Task.FromResult(true)) .Verifiable(); mockQueue .Setup(c => c.GetMessageAsync(It.IsAny <TimeSpan?>(), It.IsAny <QueueRequestOptions>(), It.IsAny <OperationContext>(), It.IsAny <CancellationToken>())) .Returns(() => { return(Task.FromResult(queuedMessage)); }) .Verifiable(); // Act var queueManager = new QueueManager(queueName, storageAccount.Object); queueManager.AddMessageAsync(sampleMessage).Wait(); var result = queueManager.GetMessageAsync().Result; // Assert mockQueue.Verify(); mockQueueClient.Verify(); mockBlobContainer.Verify(); mockBlobClient.Verify(); result.ShouldNotBeNull(); result.Content.GetType().ShouldBe(typeof(SampleMessageType)); var content = (SampleMessageType)result.Content; content.DateProp.ShouldBe(sampleMessage.DateProp); content.GuidProp.ShouldBe(sampleMessage.GuidProp); content.IntProp.ShouldBe(sampleMessage.IntProp); content.StringProp.ShouldBe(sampleMessage.StringProp); }
// Serializing and deserializing an instance of an internal class didn't work in MessagePack version 1.7.0 until 1.7.3. // It was resolved in 1.7.3.1 (see: https://github.com/neuecc/MessagePack-CSharp/issues/187) // This unit test validates was used to demonstrate the issue. public void Serialize_Internal_Type() { var sampleMessage = new SampleMessageType { DateProp = new DateTime(2016, 10, 8, 1, 2, 3, DateTimeKind.Utc), GuidProp = Guid.NewGuid(), IntProp = 123, StringProp = "Hello World" }; var serializedMessage = LZ4MessagePackSerializer.Typeless.Serialize(sampleMessage); var deserializedMessage = LZ4MessagePackSerializer.Typeless.Deserialize(serializedMessage); }