예제 #1
0
        public FirestormMiddleware(OwinMiddleware next, IRequestInvoker invoker)
            : base(next)
        {
            _invoker = invoker;

            _invoker.Initialize(); // TODO check lifetime of this
        }
        public FirestormMiddleware(RequestDelegate next, IRequestInvoker invoker)
        {
            _next    = next;
            _invoker = invoker;

            // middlewares are singletons constructed during WebHostBuilder.Build(), we can initialize here
            invoker.Initialize();
        }
            public async Task ShouldInvokeAllReceivedMessagesThenCompleteTransactions(
                RequestMessage message1,
                RequestMessage message2,
                IScope scope1,
                IScope scope2,
                IRequestInvoker invoker1,
                IRequestInvoker invoker2,
                ITransaction transaction1,
                ITransaction transaction2,
                [Frozen] ITransactionFactory transactionFactory,
                [Frozen] IRequestMessageRelay relay,
                [Frozen] IScopeFactory scopeFactory,
                [Target] DefaultRequestWorker worker,
                CancellationToken cancellationToken
                )
            {
                transactionFactory.CreateTransaction().Returns(transaction1, transaction2);
                scope1.GetService <IRequestInvoker>().Returns(invoker1);
                scope2.GetService <IRequestInvoker>().Returns(invoker2);
                scopeFactory.CreateScope().Returns(scope1, scope2);

                relay.Receive(Any <CancellationToken>()).Returns(new[] { message1, message2 });
                await worker.Run(cancellationToken);

                Received.InOrder(async() =>
                {
                    transactionFactory.Received().CreateTransaction();
                    scopeFactory.Received().CreateScope();
                    scope1.Received().GetService <IRequestInvoker>();
                    await invoker1.Received().Invoke(Is(message1), Is(cancellationToken));
                    transaction1.Received().Complete();

                    transactionFactory.Received().CreateTransaction();
                    scopeFactory.Received().CreateScope();
                    scope2.Received().GetService <IRequestInvoker>();
                    await invoker2.Received().Invoke(Is(message2), Is(cancellationToken));
                    transaction2.Received().Complete();
                });
            }