コード例 #1
0
        public PeekLockMessageControlFacts()
        {
            _mockMessagePeekLockControl = new Mock <IMessagePeekLockControl>();

            _mockMessagePeekLockControlProvider = new Mock <IMessagePeekLockControlProvider>();
            _mockMessagePeekLockControlProvider.Setup(mplcp => mplcp.GetMessagePeekLockControl <TestMessage>(It.IsAny <TestMessage>()))
            .Returns(_mockMessagePeekLockControl.Object);

            MessagePeekLockControlProvider.Use(_mockMessagePeekLockControlProvider.Object);
        }
コード例 #2
0
            public async Task CompletingPeekLockMessageCompletesTheAssociatedBrokeredMessage()
            {
                Mock <IMessageDeserializer <TestPeekLockMessage> > mockTestPeekLockMessageDeserializer = new Mock <IMessageDeserializer <TestPeekLockMessage> >();

                mockTestPeekLockMessageDeserializer.Setup(md => md.GetTypeName())
                .Returns(typeof(TestPeekLockMessage).Name);

                TestPeekLockMessage testPeekLockMessage = new TestPeekLockMessage();

                mockTestPeekLockMessageDeserializer.Setup(md => md.Deserialize(It.IsAny <Stream>()))
                .Returns(testPeekLockMessage);

                IObservable <BrokeredMessage> brokeredMessages = Observable.Create <BrokeredMessage>(o =>
                {
                    o.OnNext(new BrokeredMessage
                    {
                        Properties =
                        {
                            { MessagePropertyNames.TypeName, typeof(TestPeekLockMessage).Name }
                        }
                    });

                    o.OnCompleted();

                    return(Disposable.Empty);
                });

                Mock <IMessagePeekLockControl> mockBrokeredMessagePeekLockControl = new Mock <IMessagePeekLockControl>();

                Mock <IMessagePeekLockControlProvider> mockPeekLockControlProvider = new Mock <IMessagePeekLockControlProvider>();

                mockPeekLockControlProvider.Setup(bmplcp => bmplcp.GetMessagePeekLockControl(testPeekLockMessage))
                .Returns(mockBrokeredMessagePeekLockControl.Object);

                MessagePeekLockControlProvider.Use(mockPeekLockControlProvider.Object);

                MessageSource <TestPeekLockMessage> messageSource = new MessageSource <TestPeekLockMessage>(brokeredMessages, new[] { mockTestPeekLockMessageDeserializer.Object }, Mock.Of <IMessageBrokeredMessageTable>());

                TestPeekLockMessage message = await messageSource.Messages.SingleOrDefaultAsync();

                IMessagePeekLockControl messagePeekLockControl = message.GetPeekLockControl();

                messagePeekLockControl.Should().NotBeNull();

                await messagePeekLockControl.CompleteAsync();

                mockBrokeredMessagePeekLockControl.Verify(bmplc => bmplc.CompleteAsync(), Times.Once());
            }