Exemple #1
0
        public async Task ManualDispatchTest()
        {
            var fixture = new Fixture().Customize(new AutoMoqCustomization {
                ConfigureMembers = true
            }).Customize(new SupportMutableValueTypesCustomization());
            var op         = fixture.Create <A>();
            var moqHandler = fixture.Freeze <Mock <IHandler <A, int, DefaultMessage> > >();
            var result     = fixture.Freeze <int>();
            var factory    = new Mock <IHandlerFactory>();

            factory.Setup(f => f.Create <A, int, DefaultMessage>(It.IsAny <RequestContext <DefaultMessage> >())).ReturnsUsingFixture(fixture);
            var model = new OperationRuntimeModel(new[]
            {
                new OperationDescription(0, typeof(A), typeof(int), Side.Server, DeliveryMode.Ordered, DeliveryMode.Ordered, true),
                new OperationDescription(1, typeof(B), typeof(float), Side.Server, DeliveryMode.Ordered, DeliveryMode.Ordered, true)
            });
            var dispatcher = new TestDispatcher(new MsgSerializer(), factory.Object, model, new NullLoggerFactory(), new DescriptionRuntimeModel());

            dispatcher.Subscribe(new Mock <IResponseReceiver <DefaultMessage> >().Object);
            var hasData     = true;
            var sessionMock = new Mock <Session>(Array.Empty <SessionProperty>());

            sessionMock.SetupGet(s => s.HasAvailableData).Returns(() => hasData);
            sessionMock.Setup(s => s.ReceiveMessageAsync()).ReturnsAsync(() =>
            {
                hasData = false;
                return(CreateRawMessage(0, op, TypeMessage.Request));
            });
            await dispatcher.DispatchAsync(sessionMock.Object);

            sessionMock.Verify(s => s.ReceiveMessageAsync(), Times.Once);
            moqHandler.Verify(handler => handler.Handle(op, It.IsAny <RequestContext <DefaultMessage> >(), It.IsAny <CancellationToken>()), Times.Once);
        }