예제 #1
0
 public async Task Process_scenario_without_state_creates_it_on_start_message()
 {
     var personId       = "Andrey";
     var coffeMachineId = "Aulika Top";
     await ProcessScenario.New(new SoftwareProgrammingProcess(), new SoftwareProgrammingProcessStateFactory(coffeMachineId))
     .When(new GotTiredEvent(personId))
     .Then(new MakeCoffeCommand(personId, coffeMachineId))
     .Run()
     .CheckProducedCommands();
 }
예제 #2
0
        public async Task Given_paying_state_When_account_withdrawal_for_bad_order_Then_state_is_not_changed()
        {
            var scenario = ProcessScenario.New <BuyNowState>(new BuyNow(_inMemoryPriceCalculator), _buyNowProcessStateFactory);

            var state = scenario.NewState(nameof(BuyNow.Paying));

            await scenario.Given(state)
            .When(new AccountWithdrawal(state.AccountId, Guid.NewGuid(), new Money(100)))
            .Run()
            .CheckProducedCommands()
            .CheckOnlyStateNameChanged(nameof(BuyNow.Paying));
        }
예제 #3
0
        public async Task Given_paying_state_When_account_withdrawal_for_our_order_Then_state_is_taking_stock()
        {
            var scenario = ProcessScenario.New <BuyNowState>(new BuyNow(_inMemoryPriceCalculator), _buyNowProcessStateFactory);
            var state    = scenario.NewState(nameof(BuyNow.Paying));

            await scenario.Given(state)
            .When(new AccountWithdrawal(state.AccountId, state.OrderId, new Money(100)))
            .Then(new TakeReservedStockCommand(state.StockId, state.ReserveId))
            .Run()
            .CheckProducedCommands()
            .CheckOnlyStateNameChanged(nameof(BuyNow.TakingStock));
        }
예제 #4
0
        public async Task Given_reserving_state_When_order_item_added_Then_reserve_stock_command_is_issued()
        {
            var scenario = ProcessScenario.New <BuyNowState>(new BuyNow(_inMemoryPriceCalculator), _buyNowProcessStateFactory);
            var state    = scenario.NewState(nameof(BuyNow.Reserving), c => c.Without(d => d.ReserveId));

            await scenario.Given(state)
            .When(new StockReserved(state.StockId, state.ReserveId, DateTime.UtcNow.AddDays(1), state.Quantity))
            .Then(new CalculateOrderTotalCommand(state.OrderId))
            .Run()
            .CheckProducedCommands()
            .CheckStateName(nameof(BuyNow.Reserving));
        }
예제 #5
0
        public async Task Given_taking_stock_state_When_stockReserveTaken_Then_complete_order_and_complete_user_pending_order_commands_are_issued()
        {
            var scenario = ProcessScenario.New <BuyNowState>(new BuyNow(_inMemoryPriceCalculator), _buyNowProcessStateFactory);
            var state    = scenario.NewState(nameof(BuyNow.TakingStock));

            await scenario.Given(state)
            .When(new StockReserveTaken(state.StockId, state.ReserveId))
            .Then(new CompleteOrderCommand(state.OrderId),
                  new CompletePendingOrderCommand(state.UserId, state.OrderId))
            .Run()
            .CheckProducedCommands()
            .CheckOnlyStateNameChanged(nameof(BuyNow.Final));
        }
예제 #6
0
        public async Task Given_sku_purchase_ordered_Then_buy_now_process_is_created_and_create_order_command_issued()
        {
            SkuPurchaseOrdered ordered = new Fixture().Create <SkuPurchaseOrdered>();

            await ProcessScenario.New <BuyNowState>(new BuyNow(_inMemoryPriceCalculator), _buyNowProcessStateFactory)
            .When(ordered)
            .Then(new CreateOrderCommand(ordered.OrderId, ordered.SourceId))
            .Run()
            .CheckProducedCommands(Compare.Ignore(nameof(ICommand.ProcessId),
                                                  nameof(Command.Time),
                                                  nameof(Command.Id)));

            //igoring process id as it will be unique created on process creation from event
        }
예제 #7
0
        public async Task Given_reserving_state_When_order_total_calculated_Then_reserve_stock_command_is_issued_And_state_is_not_changed()
        {
            var scenario = ProcessScenario.New <BuyNowState>(new BuyNow(_inMemoryPriceCalculator), _buyNowProcessStateFactory);
            var state    = scenario.NewState(nameof(BuyNow.Reserving), c => c.Without(d => d.ReserveId));

            var totalPrice = new Money(100);

            await scenario.Given(state)
            .When(new OrderTotalCalculated(state.OrderId, totalPrice))
            .Then(new PayForOrderCommand(state.AccountId, totalPrice, state.OrderId))
            .Run()
            .CheckProducedCommands()
            .CheckStateName(nameof(BuyNow.Reserving));
        }
예제 #8
0
        public async Task Given_reserving_state_When_order_total_calculated_and__order_item_added_Then_state_is_changed()
        {
            var scenario   = ProcessScenario.New <BuyNowState>(new BuyNow(_inMemoryPriceCalculator), _buyNowProcessStateFactory);
            var state      = scenario.NewState(nameof(BuyNow.Reserving), c => c.Without(s => s.OrderWarReservedStatus));
            var totalPrice = new Money(100);

            await scenario.Given(state)
            .When(new OrderTotalCalculated(state.OrderId, totalPrice),
                  new StockReserved(state.StockId, state.ReserveId, DateTime.UtcNow.AddDays(1), state.Quantity))
            .Then(new PayForOrderCommand(state.AccountId, totalPrice, state.OrderId),
                  new CalculateOrderTotalCommand(state.OrderId))
            .Run()
            .CheckProducedCommands()
            .CheckStateName(nameof(BuyNow.Paying));
        }
예제 #9
0
        public async Task Given_adding_order_items_state_When_order_item_added_Then_reserve_stock_command_is_issued()
        {
            var scenario = ProcessScenario.New <BuyNowState>(new BuyNow(_inMemoryPriceCalculator), _buyNowProcessStateFactory);
            var state    = scenario.NewState(nameof(BuyNow.AddingOrderItems), c => c.Without(d => d.ReserveId));

            _inMemoryPriceCalculator.Add(state.SkuId, new Money(100));

            await scenario.Given(state)
            .When(
                new ItemAdded(state.OrderId,
                              state.SkuId,
                              state.Quantity,
                              await _inMemoryPriceCalculator.CalculatePrice(state.SkuId, state.Quantity),
                              1))
            .Then(new ReserveStockCommand(state.StockId, state.UserId, state.Quantity))
            .Run()
            .CheckProducedCommands()
            .CheckOnlyStateNameChanged(nameof(BuyNow.Reserving));
        }
예제 #10
0
        public async Task Process_scenario_transit_on_events_respecting_giving_state()
        {
            var personId       = Guid.NewGuid().ToString();
            var coffeMachineId = Guid.NewGuid().ToString();
            var sofaId         = Guid.NewGuid().ToString();
            var initialSofaId  = Guid.NewGuid().ToString();

            var scenario = ProcessScenario.New <SoftwareProgrammingState>(new SoftwareProgrammingProcess(), new SoftwareProgrammingProcessStateFactory());
            var results  = await scenario.Given(new SoftwareProgrammingState(Guid.NewGuid().ToString(), nameof(SoftwareProgrammingProcess.MakingCoffee)){ SofaId = initialSofaId })
                           .When(new CoffeMakeFailedEvent(coffeMachineId, personId),
                                 new SleptWellEvent(personId, sofaId))
                           .Then(new GoSleepCommand(personId, initialSofaId))
                           .Run();


            Assert.Single((IEnumerable)results.ExpectedCommands);
            Assert.Equal(2, results.ReceivedEvents.Length);
            Assert.Equal(sofaId, results.State.SofaId);
            results.CheckStateName(nameof(SoftwareProgrammingProcess.Coding));
            results.CheckProducedCommands();
        }
예제 #11
0
        public async Task Given_creating_order_state_When_order_created_Then_add_items_to_order_command_is_issued()
        {
            var calculator = new InMemoryPriceCalculator();
            var factory    = new BuyNowProcessStateFactory();
            var scenario   = ProcessScenario.New <BuyNowState>(new BuyNow(calculator), factory);

            var state = scenario.NewState(nameof(BuyNow.CreatingOrder), c => c.Without(d => d.ReserveId));

            calculator.Add(state.SkuId, new Money(100));

            await scenario.Given(state)
            .When(new OrderCreated(state.OrderId, 123, state.UserId, OrderStatus.Created))
            .Then(
                new AddItemToOrderCommand(state.OrderId,
                                          state.SkuId,
                                          state.Quantity,
                                          await calculator.CalculatePrice(state.SkuId, state.Quantity)))
            .Run()
            .CheckProducedCommands()
            .CheckOnlyStateNameChanged(nameof(BuyNow.AddingOrderItems));
        }