public void TestHelloDialogSendResponse() { using (MemoryStream stream = new MemoryStream()) { Mock <IMessageStreamReader> messageStreamReaderMock = new Mock <IMessageStreamReader>(); IMessageStreamWriter messageStreamWriter = new XmlMessageStreamWriter(stream); using (IStorageSystemDialogProvider dialogProvider = new StorageSystemDialogProvider()) { dialogProvider.Connect(new MessageTransmitter(messageStreamReaderMock.Object, messageStreamWriter, stream)); dialogProvider.HelloDialog.SendResponse(( HelloResponse )(TestData.HelloResponse.Object.Message)); stream.Position = 0; using (IMessageStreamReader messageStreamReader = new XmlMessageStreamReader(stream)) { Mock <IObserver <IMessageEnvelope> > observerMock = new Mock <IObserver <IMessageEnvelope> >(); observerMock.Setup(x => x.OnNext(It.IsAny <IMessageEnvelope>())).Callback <IMessageEnvelope>(( IMessageEnvelope value ) => { Assert.AreEqual(TestData.HelloResponse.Object.Message, value.Message); }); messageStreamReader.Subscribe(observerMock.Object); } } } }
public void TestSubscriptionOfSingleObserver() { using (IMessageStreamReader streamReader = new XmlMessageStreamReader(this.BaseStream)) { Mock <IObserver <IMessageEnvelope> > observerMock = new Mock <IObserver <IMessageEnvelope> >(); using (ManualResetEventSlim sync = new() ) { observerMock.Setup(x => x.OnCompleted()).Callback(() => { sync.Set(); }); using (IDisposable subscription = streamReader.Subscribe(observerMock.Object)) { sync.Wait(); observerMock.Verify(x => x.OnNext(It.IsAny <IMessageEnvelope>()), Times.Exactly(this.Messages.Count)); Assert.IsNotNull(subscription); } } } }