public async Task Should_support_pipe_configuration_on_the_result()
        {
            IPipe <RequestContext> pipe = CreateHandlerPipe();

            IRequestPipe <CheckInventory, CheckInventoryResult> requestPipe = pipe.CreateRequestPipe <CheckInventory, CheckInventoryResult>(x =>
            {
                x.UseFilter(new UpdateCacheFilter(_inventoryCache));
            });

            var checkInventory = new CheckInventory()
            {
                ItemNumber = "ABC123", Quantity = 2
            };

            var timer  = Stopwatch.StartNew();
            var result = await requestPipe.Send(checkInventory).Result();

            timer.Stop();

            Assert.That(result.ItemNumber, Is.EqualTo(checkInventory.ItemNumber));
            Assert.That(result.QuantityOnHand, Is.EqualTo(checkInventory.ItemNumber.GetHashCode() % 100));
            Assert.That(timer.Elapsed, Is.GreaterThan(TimeSpan.FromMilliseconds(200)));

            timer  = Stopwatch.StartNew();
            result = await requestPipe.Send(checkInventory).Result();

            timer.Stop();

            Assert.That(result.ItemNumber, Is.EqualTo(checkInventory.ItemNumber));
            Assert.That(result.QuantityOnHand, Is.EqualTo(checkInventory.ItemNumber.GetHashCode() % 100));
            Assert.That(timer.Elapsed, Is.LessThan(TimeSpan.FromMilliseconds(20)));
        }
示例#2
0
        public async Task Should_support_the_same_thing_a_different_way()
        {
            IPipe <RequestContext> pipe = CreateHandlerPipe();

            IRequestPipe <PurchaseTicket, TicketReceipt> requestPipe = pipe.CreateRequestPipe <PurchaseTicket, TicketReceipt>();

            var receipt = await requestPipe.Send(new PurchaseTicket { EventName = "The Big Party", Quantity = 2 }).Result();

            Assert.That(receipt.OrderNumber, Is.EqualTo("42"));
        }
示例#3
0
        public async Task Should_support_a_simple_request_response_conversation()
        {
            IPipe <RequestContext> pipe = CreateHandlerPipe();

            IRequestPipe <PurchaseTicket, TicketReceipt> requestPipe = pipe.CreateRequestPipe <PurchaseTicket, TicketReceipt>();

            var receipt = await requestPipe.Send(new PurchaseTicket { EventName = "The Big Party", Quantity = 2 }).Result();

            Assert.That(receipt.OrderNumber, Is.EqualTo("42"));
        }
示例#4
0
        public ExecuteActivityHost(ExecuteActivityFactory <TActivity, TArguments> activityFactory,
                                   IPipe <RequestContext> executePipe)
        {
            if (activityFactory == null)
            {
                throw new ArgumentNullException(nameof(activityFactory));
            }

            _activityFactory = activityFactory;
            _executePipe     = executePipe.CreateRequestPipe <ExecuteActivityContext <TActivity, TArguments>, ExecutionResult>();
        }
示例#5
0
        public async Task Should_support_pipe_configuration_on_the_result()
        {
            IPipe <RequestContext> pipe = CreateHandlerPipe();

            IRequestPipe <PurchaseTicket, TicketReceipt> requestPipe = pipe.CreateRequestPipe <PurchaseTicket, TicketReceipt>(x =>
            {
                x.UseExecute(context => context.Result.AuthorizationCode = "8675309");
            });

            var receipt = await requestPipe.Send(new PurchaseTicket { EventName = "The Big Party", Quantity = 2 }).Result();

            Assert.That(receipt.OrderNumber, Is.EqualTo("42"));
            Assert.That(receipt.AuthorizationCode, Is.EqualTo("8675309"));
        }
示例#6
0
        public async Task Should_support_multiple_result_types()
        {
            IPipe <RequestContext> pipe = CreateHandlerPipe();

            IRequestPipe <PurchaseTicket> requestPipe = pipe.CreateRequestPipe <PurchaseTicket>(
                x => x.Result <TicketReceipt>(),
                x => x.Result <EventSoldOut>());

            var resultContext = await requestPipe.Send(new PurchaseTicket { EventName = "Golden State Warriors", Quantity = 4 });

            TicketReceipt receipt;

            Assert.That(resultContext.TryGetResult(out receipt), Is.False);

            EventSoldOut soldOut;

            Assert.That(resultContext.TryGetResult(out soldOut), Is.True);

            Assert.That(soldOut.EventName, Is.EqualTo("Golden State Warriors"));
        }
        public async Task Should_support_awesome_caching_speed()
        {
            IPipe <RequestContext> pipe = CreateHandlerPipe();

            IRequestPipe <CheckInventory, CheckInventoryResult> requestPipe = pipe.CreateRequestPipe <CheckInventory, CheckInventoryResult>(x =>
            {
                x.UseFilter(new UpdateCacheFilter(_inventoryCache));
            });

            var checks = new CheckInventory[]
            {
                new CheckInventory()
                {
                    ItemNumber = "ABC123", Quantity = 2
                },
                new CheckInventory()
                {
                    ItemNumber = "DEF456", Quantity = 4
                },
                new CheckInventory()
                {
                    ItemNumber = "GHI789", Quantity = 6
                },
            };

            var timer = Stopwatch.StartNew();

            for (var i = 0; i < 100; i++)
            {
                await requestPipe.Send(checks[i % checks.Length]).Result();
            }

            timer.Stop();

            Console.WriteLine("Total time: {0}ms", timer.ElapsedMilliseconds);
            Console.WriteLine("Total calls: {0}", _totalCalls);

            Assert.That(timer.Elapsed, Is.LessThan(TimeSpan.FromMilliseconds(1000)));
        }
示例#8
0
 public CompensateActivityHost(CompensateActivityFactory <TActivity, TLog> activityFactory,
                               IPipe <RequestContext> compensatePipe)
 {
     _activityFactory = activityFactory;
     _compensatePipe  = compensatePipe.CreateRequestPipe <CompensateActivityContext <TActivity, TLog>, CompensationResult>();
 }