It is unclear to me looking at the unit tests how to identify a successful response vs an error response when using a temp queue. For instance, using the GenericService, if the ID was decided at run time, how do you handle both the ErrorResponse and the GenericResponseDto from the temporary queue?
Works if response is always an exception:
public class GenericService : IService
{
public GenericResponseDto Post(GenericRequest request)
{
if (request.Id % 2 == 0)
{
return new GenericResponseDto { RequestId = request.Id };
}
else
{
throw new Exception("Not divisible by 2");
}
}
}
using (var mqClient = MessageService.CreateMessageQueueClient())
{
string replyToMq = mqClient.GetTempQueueName();
var requestDto = new GenericRequest { Id = 1 };
mqClient.Publish(new Message<GenericRequest>(requestDto)
{
ReplyTo = replyToMq
});
IMessage<ErrorResponse> responseMsg = mqClient.Get<ErrorResponse>(replyToMq);
mqClient.Act(responseMsg);
}
Works if response is always successful (response dto):
using (var mqClient = MessageService.CreateMessageQueueClient())
{
string replyToMq = mqClient.GetTempQueueName();
var requestDto = new GenericRequest { Id = 2 };
mqClient.Publish(new Message<GenericRequest>(requestDto)
{
ReplyTo = replyToMq
});
IMessage<GenericResponseDto> responseMsg = mqClient.Get<GenericResponseDto>(replyToMq);
mqClient.Act(responseMsg);
}
What am I missing?