///<inheritdoc /> public Task Handle(string topic, byte[] message, CancellationToken token) { if (topic == null) { throw new ArgumentNullException(nameof(topic)); } if (message == null) { throw new ArgumentNullException(nameof(message)); } var messageType = _typeTopicMap.Get(topic); if (messageType == null) { throw new InvalidOperationException( $"Topic '{topic}' has no message type registered with: {_typeTopicMap.GetType()}."); } var deserialized = _serializer.Deserialize(messageType, message); if (deserialized == null) { throw new InvalidOperationException( $"Serializer {_serializer.GetType()} returned null for the {message.Length}-byte message of type {messageType}."); } return(_messageHandlerInvoker.Invoke(deserialized, token)); }
public async Task Handle_TopicMapNotDefined_ThrowsInvalidOperation( string topic, [Frozen] IMessageTypeTopicMap messageTypeTopicMap, DispatchingRawMessageHandler sut) { messageTypeTopicMap.Get(topic).ReturnsNull(); var ex = await Assert.ThrowsAsync <InvalidOperationException>(() => sut.Handle(topic, new byte[0], None)); Assert.Equal($"Topic '{topic}' has no message type registered with: {messageTypeTopicMap.GetType()}.", ex.Message); }
public async Task Publish_TopicMapNotDefined_ThrowsInvalidOperation( string message, [Frozen] IMessageTypeTopicMap messageTypeTopicMap, SerializedMessagePublisher sut) { messageTypeTopicMap.Get(message.GetType()).ReturnsNull(); var ex = await Assert.ThrowsAsync <InvalidOperationException>(() => sut.Publish(message, None)); Assert.Equal($"Message type {message.GetType()} is not registered with: {messageTypeTopicMap.GetType()}.", ex.Message); }
///<inheritdoc /> public Task Publish <TMessage>(TMessage message, CancellationToken token) { if (message == null) { throw new ArgumentNullException(nameof(message)); } var topic = _typeTopicMap.Get(message.GetType()); if (topic == null) { throw new InvalidOperationException( $"Message type {message.GetType()} is not registered with: {_typeTopicMap.GetType()}."); } var serialized = _serializer.Serialize(message); if (serialized == null) { throw new InvalidOperationException( $"Serializer {_serializer.GetType()} returned null for message of type {message.GetType()}."); } return(_rawMessagePublisher.Publish(topic, serialized, token)); }