private static ConsumeResult <string, string> BuildFakeConsumeResult(FakeMessage fakeMessage)
 {
     return(new ConsumeResult <string, string>
     {
         Message = new Message <string, string>
         {
             Value = JsonConvert.SerializeObject(fakeMessage),
             Headers = new Headers
             {
                 { "message-type", Encoding.UTF8.GetBytes(fakeMessage.GetType().AssemblyQualifiedName) }
             }
         }
     });
 }
예제 #2
0
 private static ConsumeResult <string, FakeAvro> BuildFakeConsumeResult(FakeMessage fakeMessage)
 {
     return(new ConsumeResult <string, FakeAvro>
     {
         Message = new Message <string, FakeAvro>
         {
             Value = fakeMessage,
             Headers = new Headers
             {
                 { "message-type", Encoding.UTF8.GetBytes(fakeMessage.GetType().AssemblyQualifiedName) }
             }
         }
     });
 }
예제 #3
0
        public async Task ProcessMessagesAsync_Message_VerifyVerison()
        {
            // assert
            const int testVersion         = 1;
            Message   testMesage          = new Message();
            var       deserializedMessage = new FakeMessage(testVersion);
            var       handlerMock         = new Mock <IMessageHandler>();
            var       messageSerialzier   = new Mock <IMessageSerializer>();

            messageSerialzier.Setup(x => x.Deserialize <IMessage>(It.IsAny <Message>()))
            .Returns(deserializedMessage);
            var versionChecker = new Mock <IVersionChecker>();

            versionChecker.Setup(x => x.Check(It.IsAny <int>(), It.IsAny <Type>())).Callback <int, Type>((y, t) =>
            {
            });
            var handler = new MessageProcessor(handlerMock.Object, versionChecker.Object, messageSerialzier.Object);

            // act
            await handler.ProcessMessagesAsync(testMesage, CancellationToken.None);

            // arrange
            versionChecker.Verify(x => x.Check(It.Is <int>(ver => ver == testVersion), It.Is <Type>(type => type == deserializedMessage.GetType())), Times.Once);
            messageSerialzier.Verify(x => x.Deserialize <IMessage>(It.Is <Message>(msg => msg == testMesage)), Times.Once);
        }
예제 #4
0
        public void Serialize_Message_ReturnsConfiguratedMessage()
        {
            // arrange
            var serializer = new MessageSerializer();
            var message    = new FakeMessage(1);

            // act
            var brokeredMessage = serializer.Serialize(message);
            var body            = new MemoryStream(brokeredMessage.Body);

            // assert
            Assert.Equal(brokeredMessage.UserProperties[CustomMessageProperties.MessageTypeProperty], message.GetType().FullName);
            Assert.NotNull(body);
        }