@@ -32,13 +32,14 @@ public MessageProcessorTest()
3232 consumerMethodMock = new Mock < ConsumerMethod > ( ) ;
3333 consumerInvokerMock . SetupGet ( x => x . ConsumerMethod ) . Returns ( consumerMethodMock . Object ) ;
3434
35- responseProducerMock = new Mock < IResponseProducer > ( ) ;
36- messageProviderMock = new Mock < MessageProvider < SomeMessage > > ( ) ;
37-
38- consumerBuilder = new ConsumerBuilder < SomeMessage > ( new MessageBusSettings ( ) ) ;
39-
40- subject = new Lazy < MessageProcessor < SomeMessage > > (
41- ( ) => new MessageProcessor < SomeMessage > (
35+ responseProducerMock = new Mock < IResponseProducer > ( ) ;
36+ messageProviderMock = new Mock < MessageProvider < SomeMessage > > ( ) ;
37+
38+ consumerBuilder = new ConsumerBuilder < SomeMessage > ( new MessageBusSettings ( ) ) ;
39+ consumerBuilder . WithConsumer < SomeMessageConsumer > ( ) ;
40+
41+ subject = new Lazy < MessageProcessor < SomeMessage > > (
42+ ( ) => new MessageProcessor < SomeMessage > (
4243 consumerSettings : [ consumerBuilder . ConsumerSettings ] ,
4344 messageBus : busMock . Bus ,
4445 messageProvider : messageProviderMock . Object ,
@@ -71,13 +72,61 @@ public async Task When_ProcessMessage_Given_MessagePayloadCannotDeserialize_Then
7172 messageProviderMock . VerifyNoOtherCalls ( ) ;
7273
7374 result . Should ( ) . NotBeNull ( ) ;
74- result . Result . Should ( ) . Be ( ProcessResult . Failure ) ;
75- result . Exception . Should ( ) . NotBeNull ( ) ;
76- }
77-
78- [ Theory ]
79- [ InlineData ( null , "UnknownMessage" ) ]
80- [ InlineData ( true , "UnknownMessage" ) ]
75+ result . Result . Should ( ) . Be ( ProcessResult . Failure ) ;
76+ result . Exception . Should ( ) . NotBeNull ( ) ;
77+ }
78+
79+ [ Fact ]
80+ public async Task When_ProcessMessage_Given_RequestPayloadCannotDeserialize_Then_ErrorResponseIsSent ( )
81+ {
82+ // arrange
83+ var transportMessageMock = new Mock < SomeMessage > ( ) ;
84+ var headers = new Dictionary < string , object >
85+ {
86+ { MessageHeaders . MessageType , typeof ( SomeRequest ) . AssemblyQualifiedName } ,
87+ { ReqRespMessageHeaders . RequestId , "request-id" } ,
88+ { ReqRespMessageHeaders . ReplyTo , "reply-to" }
89+ } ;
90+
91+ var deserializationException = new InvalidOperationException ( "Deserialization failed" ) ;
92+ var handlerBuilder = new HandlerBuilder < SomeRequest , SomeResponse > ( new MessageBusSettings ( ) ) ;
93+ handlerBuilder . WithHandler < SomeRequestMessageHandler > ( ) ;
94+
95+ var subject = new MessageProcessor < SomeMessage > (
96+ consumerSettings : [ handlerBuilder . ConsumerSettings ] ,
97+ messageBus : busMock . Bus ,
98+ messageProvider : messageProviderMock . Object ,
99+ path : "topic1" ,
100+ responseProducer : responseProducerMock . Object ) ;
101+
102+ messageProviderMock
103+ . Setup ( x => x . Invoke ( typeof ( SomeRequest ) , headers , transportMessageMock . Object ) )
104+ . Throws ( deserializationException ) ;
105+
106+ // act
107+ var result = await subject . ProcessMessage ( transportMessageMock . Object , headers ) ;
108+
109+ // assert
110+ messageProviderMock . Verify ( x => x ( typeof ( SomeRequest ) , headers , transportMessageMock . Object ) , Times . Once ) ;
111+ responseProducerMock . Verify (
112+ x => x . ProduceResponse (
113+ "request-id" ,
114+ null ,
115+ headers ,
116+ null ,
117+ deserializationException ,
118+ handlerBuilder . ConsumerSettings ,
119+ It . IsAny < CancellationToken > ( ) ) ,
120+ Times . Once ) ;
121+
122+ result . Should ( ) . NotBeNull ( ) ;
123+ result . Result . Should ( ) . Be ( ProcessResult . Failure ) ;
124+ result . Exception . Should ( ) . BeNull ( ) ;
125+ }
126+
127+ [ Theory ]
128+ [ InlineData ( null , "UnknownMessage" ) ]
129+ [ InlineData ( true , "UnknownMessage" ) ]
81130 [ InlineData ( false , "UnknownMessage" ) ]
82131 [ InlineData ( null , nameof ( SomeMessage2 ) ) ]
83132 [ InlineData ( true , nameof ( SomeMessage2 ) ) ]
@@ -119,4 +168,4 @@ public async Task When_ProcessMessage_Given_MessageTypeHeaderValueUnknown_Then_R
119168
120169 messageProviderMock . VerifyNoOtherCalls ( ) ;
121170 }
122- }
171+ }
0 commit comments