public async Task ReceivesAndDeserializesSingleMessage() { Mock <IMessageDeserializer <TestMessage> > mockTestMessageDeserializer = new Mock <IMessageDeserializer <TestMessage> >(); mockTestMessageDeserializer.Setup(md => md.GetTypeName()) .Returns(typeof(TestMessage).Name); TestMessage testMessage = new TestMessage(); mockTestMessageDeserializer.Setup(md => md.Deserialize(It.IsAny <Stream>())) .Returns(testMessage); BrokeredMessage testBrokeredMessage = new BrokeredMessage() { Properties = { { MessagePropertyNames.TypeName, typeof(TestMessage).Name } } }; IObservable <BrokeredMessage> brokeredMessages = Observable.Create <BrokeredMessage>(o => { o.OnNext(testBrokeredMessage); o.OnCompleted(); return(Disposable.Empty); }); MessageSource <TestMessage> messageSource = new MessageSource <TestMessage>(brokeredMessages, new[] { mockTestMessageDeserializer.Object }, Mock.Of <IMessageBrokeredMessageTable>()); TestMessage message = await messageSource.Messages.SingleOrDefaultAsync(); message.ShouldBeEquivalentTo(testMessage); // NOTE: Would be great to be able to verify that testBrokeredMessage.CompleteAsync() was called here, but I would have to build abstraction around BrokeredMessage for that because it can't be mocked (since it's sealed) mockTestMessageDeserializer.Verify(md => md.Deserialize(It.IsAny <Stream>()), Times.Once()); }