Exemplo n.º 1
0
        public void Money_in_transaction_go_to_money_inside_after_purchase()
        {
            // Arrange
            var snackMachine = new SnackMachine();

            // Act
            snackMachine.InsertMoney(Money.Dollar);
            snackMachine.InsertMoney(Money.Dollar);
            snackMachine.BuySnack();

            // Assert
            snackMachine.MoneyInTransaction.Should().Be(Money.None);
            snackMachine.MoneyInside.Amount.Should().Be(2m);
        }
        public SnackMachineViewModel(SnackMachine snackMachine)
        {
            _snackMachine = snackMachine;
            _repository   = new SnackMachineRepository();

            InsertCentCommand         = new Command(() => InsertMoney(Money.Cent));
            InsertTenCentCommand      = new Command(() => InsertMoney(Money.TenCent));
            InsertQuarterCommand      = new Command(() => InsertMoney(Money.Quarter));
            InsertDollarCommand       = new Command(() => InsertMoney(Money.Dollar));
            InsertFiveDollarCommand   = new Command(() => InsertMoney(Money.FiveDollar));
            InsertTwentyDollarCommand = new Command(() => InsertMoney(Money.TwentyDollar));
            ReturnMoneyCommand        = new Command(() => ReturnMoney());
            BuySnackCommand           = new Command <string>(BuySnack);
        }
Exemplo n.º 3
0
        public void BuySnack_Can_buy_snack_if_enough_change_in_machine()
        {
            var snackMachine = new SnackMachine(Dollar + Dollar);

            snackMachine.LoadSnacks(1, new SnackPile(Snack.None, 1, 3m));
            snackMachine.InsertMoney(FiveDollar);

            var valid = snackMachine.CanBuySnack(1);

            //Assert
            true.Should().Equals(valid);
            false.Should().Equals(snackMachine.AnyErrors());
            snackMachine.Project().Should().Be(string.Empty);
        }
        public void Money_In_Transaction_Goes_To_Money_Inside_After_Purchase()
        {
            SnackMachine machine = new SnackMachine();

            machine.LoadSnacks(1, new SnackPile(new Snack("Hee haw"), 5, 6));
            machine.InsertMoney(Money.OneCent);
            machine.InsertMoney(Money.Dollar);
            machine.InsertMoney(Money.FiveDollar);

            machine.BuySnack(1);

            machine.AmountInTransaction.Should().Be(0);
            Assert.Equal(6, machine.MoneyInside.Amount);
        }
Exemplo n.º 5
0
        public void BuySnack_Cannot_buy_snack_if_not_enough_change_in_machine()
        {
            var snackMachine = new SnackMachine();

            snackMachine.LoadSnacks(1, new SnackPile(Snack.None, 1, 0.5m));
            snackMachine.InsertMoney(Dollar);

            var valid = snackMachine.CanBuySnack(1);

            //Assert
            false.Should().Equals(valid);
            true.Should().Equals(snackMachine.AnyErrors());
            Constants.NotEnoughChange.Should().Equals(snackMachine.Project());
        }
Exemplo n.º 6
0
        public void BuySnack_trades_inserted_money_for_a_snack()
        {
            var snackMachine = new SnackMachine();

            snackMachine.LoadSnacks(1, new SnackPile(Chocolate, 10, 1m));

            snackMachine.InsertMoney(Dollar);

            snackMachine.BuySnack(1);

            snackMachine.MoneyInTransaction.Should().Be(0m);
            snackMachine.MoneyInside.Amount.Should().Be(1m);
            snackMachine.GetSnackPile(1).Quantity.Should().Be(9);
        }
Exemplo n.º 7
0
        public void Snack_machine_returns_money_with_highest_denomination_first()
        {
            SnackMachine snackMachine = new SnackMachine();
            snackMachine.LoadMoney(Dollar);

            snackMachine.InsertMoney(Quarter);
            snackMachine.InsertMoney(Quarter);
            snackMachine.InsertMoney(Quarter);
            snackMachine.InsertMoney(Quarter);
            snackMachine.ReturnMoney();

            snackMachine.MoneyInside.QuarterCount.Should().Be(4);
            snackMachine.MoneyInside.OneDollarCount.Should().Be(0);
        }
Exemplo n.º 8
0
        public void Money_in_transaction_goes_to_money_inside_after_purchase()
        {
            SnackMachine snackMachine = new SnackMachine();

            snackMachine.InsertMoney(Money.Dollar);
            snackMachine.InsertMoney(Money.Dollar);
            snackMachine.InsertMoney(Money.Dollar);
            snackMachine.MoneyInTransaction.Amount.Should().Be(3m);
            snackMachine.BuySnack();
            snackMachine.MoneyInTransaction.Amount.Should().Be(0m);
            snackMachine.MoneyInTransaction.Should().Be(Money.None);

            snackMachine.MoneyInside.Amount.Should().Be(3m);
        }
Exemplo n.º 9
0
        public async Task <CommandResult> Handle(InitializeSnakMachineCommand request,
                                                 CancellationToken cancellationToken)
        {
            var moneyInside = new Money(request.OneCentCount, request.TenCentCount,
                                        request.QuarterCount, request.OneDollarCount, request.FiveDollarCount);

            var snackMachine = new SnackMachine(moneyInside);

            _snakMachineRepository.Add(snackMachine);

            await _snakMachineRepository
            .UnitOfWork.SaveEntitiesAsync();

            return(CommandResult.GetSuccess());
        }
Exemplo n.º 10
0
        public void BuySnack_When_Confirmed_Should_AddMoneyInTransactionToMoneyInside()
        {
            // Arrange
            var sut = new SnackMachine();

            sut.InsertMoney(Money.Dollar);
            sut.InsertMoney(Money.Dollar);

            // Act
            sut.BuySnack();

            // Assert
            sut.MoneyInTransaction.Should().Be(Money.None);
            sut.MoneyInside.Amount.Should().Be(2);
        }
        public void Should_Not_Be_Able_To_Purchase_If_Machine_Cant_Make_Change()
        {
            SnackMachine machine = new SnackMachine();

            machine.LoadMoney(Money.Dollar);
            machine.LoadSnacks(1, new SnackPile(new Snack("Tasty"), 400, .75m));

            machine.InsertMoney(Money.Quarter);
            machine.InsertMoney(Money.Quarter);
            machine.InsertMoney(Money.Dollar);

            Action action = () => machine.BuySnack(1);

            action.Should().Throw <CannotMakeChangeException>();
        }
Exemplo n.º 12
0
        public void MAchine_should_return_money_with_highest_nomination_First()
        {
            var snackMachine = new SnackMachine();

            snackMachine.LoadMoney(Money.OneDollar);
            snackMachine.InsertMoney(Money.QuaterCent);
            snackMachine.InsertMoney(Money.QuaterCent);
            snackMachine.InsertMoney(Money.QuaterCent);
            snackMachine.InsertMoney(Money.QuaterCent);

            snackMachine.ReturnMoney();

            snackMachine.MoneyInside.QuaterCentCount.Should().Be(4);
            snackMachine.MoneyInside.OneDollarCount.Should().Be(0);
        }
Exemplo n.º 13
0
        public SnackMachineViewModel(SnackMachine snackMachine)
        {
            this.snackMachine = snackMachine;
            mediator          = Infrastructure.ObjectFactory.Instance.GetService <IMediator>();

            InsertCentCommand         = new Command(() => InsertMoney(Cent));
            InsertTenCentCommand      = new Command(() => InsertMoney(TenCent));
            InsertQuarterCommand      = new Command(() => InsertMoney(Quarter));
            InsertDollarCommand       = new Command(() => InsertMoney(Dollar));
            InsertFiveDollarCommand   = new Command(() => InsertMoney(FiveDollar));
            InsertTwentyDollarCommand = new Command(() => InsertMoney(TwentyDollar));

            ReturnMoneyCommand = new Command(() => ReturnMoney());
            BuySnackCommand    = new Command <string>(BuySnack);
        }
Exemplo n.º 14
0
        public void Test1()
        {
            var snackMachine = new SnackMachine();

            snackMachine.LoadSnacks(1, new Snack("Some snack"), 10, 1m);
            snackMachine.InsertMoney(Money.Dollar);

            snackMachine.BuySnack(1);

            snackMachine.MoneyInTransaction.Should().Be(Money.None);
            snackMachine.MoneyInside.Amount.Should().Be(1m);
            snackMachine.GetQuantityOfSnacksInSlot(1).Should().Be(9);
            snackMachine.GetSnackInSlot(1).Should().Be(new Snack("Some snack"));
            snackMachine.GetPriceInSlot(1).Should().Be(1m);
        }
        private void UnloadCash(SnackMachineDto snackMachineDto)
        {
            SnackMachine snackMachine = _snackMachineRepository.GetById(snackMachineDto.Id);

            if (snackMachine == null)
            {
                return;
            }

            HeadOffice.UnloadCashFromSnackMachine(snackMachine);
            _snackMachineRepository.Save(snackMachine);
            _headOfficeRepository.Save(HeadOffice);

            RefreshAll();
        }
Exemplo n.º 16
0
        public void BuySnack_trades_inserted_money_for_a_snack()
        {
            var snackMachine = new SnackMachine();

            snackMachine.LoadSnacks(1, new SnackPile(Chocolate, 10, 1m));
            snackMachine.InsertMoney(OneDollar);
            snackMachine.BuySnack(position: 1);

            //snackMachine.MoneyInTransaction.Should().Be(None);
            snackMachine.MoneyInTransaction.Should().Be(0);
            snackMachine.MoneyInside.Should().Be(OneDollar);
            //snackMachine.Slots.Single(x => x.Position == 1).Quantity.Should().Be(9);
            //snackMachine.GetQuantityOfSnacksInSlots(1).Quantity.Should().Be(9);
            snackMachine.GetSnackPile(1).Quantity.Should().Be(9);
        }
Exemplo n.º 17
0
        public void SnackMachineReturnsMoneyWithHighestDenominationFirst()
        {
            var snackMachine = new SnackMachine();

            snackMachine.LoadMoney(Dollar);

            snackMachine.InsertMoney(Quarter);
            snackMachine.InsertMoney(Quarter);
            snackMachine.InsertMoney(Quarter);
            snackMachine.InsertMoney(Quarter);
            snackMachine.ReturnMoney();

            snackMachine.MoneyInside.QuarterCount.Should().Be(4);
            snackMachine.MoneyInside.OneDollarCount.Should().Be(0);
        }
Exemplo n.º 18
0
        public void ReturnMoney_ShouldTryToReturnHighestDenominationFirst()
        {
            var snackMachine = new SnackMachine();

            snackMachine.LoadMoney(OneDollar);

            snackMachine.InsertMoney(QuarterCent);
            snackMachine.InsertMoney(QuarterCent);
            snackMachine.InsertMoney(QuarterCent);
            snackMachine.InsertMoney(QuarterCent);
            snackMachine.ReturnMoney();

            snackMachine.MoneyInside.QuarterCentCount.Should().Be(4);
            snackMachine.MoneyInside.OneDollarCount.Should().Be(0);
        }
Exemplo n.º 19
0
        public SnackMachineViewModel(SnackMachine snackMachine)
        {
            this.snackMachine = snackMachine;
            Title             = "Snack Machine";

            InsertFiveCentCommand   = new Command(execute: () => InsertMoneyAction(FiveCent));
            InsertTenCentCommand    = new Command(execute: () => InsertMoneyAction(TenCent));
            InsertTwentyCentCommand = new Command(execute: () => InsertMoneyAction(TwentyCent));
            InsertFiftyCentCommand  = new Command(execute: () => InsertMoneyAction(FiftyCent));
            InsertOneEuroCommand    = new Command(execute: () => InsertMoneyAction(OneEuro));
            InsertTwoEuroCommand    = new Command(execute: () => InsertMoneyAction(TwoEuro));

            BuySnackCommand    = new Command(execute: BuySnackAction);
            ReturnMoneyCommand = new Command(execute: ReturnMoneyAction);
        }
        public void Snack_Machine_Should_Give_Highest_Denomination_Back_First()
        {
            SnackMachine machine = new SnackMachine();

            machine.LoadMoney(Money.Dollar);

            machine.InsertMoney(Money.Quarter);
            machine.InsertMoney(Money.Quarter);
            machine.InsertMoney(Money.Quarter);
            machine.InsertMoney(Money.Quarter);

            machine.ReturnMoney();

            machine.MoneyInside.QuarterCount.Should().Be(4);
            machine.MoneyInside.OneDollarCount.Should().Be(0);
        }
        public async Task <CommandResult> Handle(InitializeSnakMachineCommand request,
                                                 CancellationToken cancellationToken)
        {
            var moneyInside = new Money(request.OneCentCount, request.TenCentCount,
                                        request.QuarterCount, request.OneDollarCount, request.FiveDollarCount);

            var snackMachine = new SnackMachine(moneyInside);

            var str = snackMachine.ToJson(new MongoDB.Bson.IO.JsonWriterSettings {
                Indent = true
            });

            await _snakMachineRepository.Add(snackMachine);

            return(CommandResult.GetSuccess());
        }
Exemplo n.º 22
0
        public void BuySnack_Cannot_NotEnoughMoneyInserted_CannotBuy()
        {
            //Arrange
            var snackMachine = new SnackMachine();

            snackMachine.LoadSnacks(1, new SnackPile(Snack.None, 1, 2m));

            //Action
            snackMachine.InsertMoney(Dollar);
            var valid = snackMachine.CanBuySnack(1);

            //Assert
            false.Should().Equals(valid);
            true.Should().Equals(snackMachine.AnyErrors());
            Constants.NotEnoughMoneyInserted.Should().Equals(snackMachine.Project());
        }
Exemplo n.º 23
0
        public void BuySnack_trades_inserted_money_for_a_snack()
        {
            //Arrange
            var snackMachine = new SnackMachine();

            snackMachine.LoadSnacks(1, new SnackPile(Snack.None, 10, 1m));
            snackMachine.InsertMoney(Dollar);

            //Act
            snackMachine.BuySnack(1);

            //Assert
            0m.Should().Be(snackMachine.MoneyInTransaction);
            Dollar.Should().Be(snackMachine.MoneyInside);
            9.Should().Be(snackMachine.GetSnackPile(1).Quantity);
        }
        public void Change_Should_Be_Returned_After_Purchase()
        {
            SnackMachine machine = new SnackMachine();

            machine.LoadMoney(new Money(0, 0, 3, 0, 0, 0));

            machine.LoadSnacks(1, new SnackPile(new Snack("Tasty"), 400, .75m));

            machine.InsertMoney(Money.Quarter);
            machine.InsertMoney(Money.Quarter);
            machine.InsertMoney(Money.Dollar);

            machine.BuySnack(1);

            machine.MoneyInside.Amount.Should().Be(1.50m);
        }
Exemplo n.º 25
0
        public void BuySnack_After_purchase_Change_is_returned()
        {
            //Arrange
            var snackMachine = new SnackMachine();

            snackMachine.LoadSnacks(1, new SnackPile(Snack.None, 1, 0.5m));
            snackMachine.LoadMoney(TenCent * 10);

            //Action
            snackMachine.InsertMoney(Dollar);
            snackMachine.BuySnack(1);

            //Assert
            snackMachine.MoneyInside.Amount.Should().Be(1.5m);
            snackMachine.MoneyInTransaction.Should().Be(0m);
        }
Exemplo n.º 26
0
        public void Return_money_with_highest_denomination_first()
        {
            SnackMachine snackMachine = new SnackMachine();

            //one dollar in the machine
            snackMachine.LoadMoney(OneDollar);

            //customer inserted a quarter 4 times and get one dollar
            snackMachine.InsertMoney(Quarter);
            snackMachine.InsertMoney(Quarter);
            snackMachine.InsertMoney(Quarter);
            snackMachine.InsertMoney(Quarter);

            //return the money to the customer
            snackMachine.ReturnMoney();
            snackMachine.MoneyInside.QuarterCount.Should().Be(4);
            snackMachine.MoneyInside.OneDollarCount.Should().Be(0);
        }
Exemplo n.º 27
0
        public void ReturnMoney_returns_money_with_highest_denomination_first()
        {
            //Arrange
            SnackMachine snackMachine = new SnackMachine();

            snackMachine.LoadMoney(Dollar);

            //Action
            snackMachine.InsertMoney(Quarter);
            snackMachine.InsertMoney(Quarter);
            snackMachine.InsertMoney(Quarter);
            snackMachine.InsertMoney(Quarter);
            snackMachine.ReturnMoney();

            //Assert
            4.Should().Be(snackMachine.MoneyInside.QuarterCount);
            0.Should().Be(snackMachine.MoneyInside.OneDollarCount);
        }
Exemplo n.º 28
0
        public void Test()
        {
            SessionFactory.Init(@"Server=(localdb)\mssqllocaldb;Database=DddInPractice;Trusted_Connection=True;");

//            using (ISession session = SessionFactory.OpenSession())
//            {
//                long id = 1;
//                var snackMachine = session.Get<SnackMachine>(id);
//            }

            var          repository   = new SnackMachineRepository();
            SnackMachine snackMachine = repository.GetById(1);

            snackMachine.InsertMoney(Money.Dollar);
            snackMachine.InsertMoney(Money.Dollar);
            snackMachine.InsertMoney(Money.Dollar);
            snackMachine.BuySnack(1);
            repository.Save(snackMachine);
        }
Exemplo n.º 29
0
 public SnackMachineShould()
 {
     _sut = new SnackMachine();
 }
Exemplo n.º 30
0
        public virtual void TransferInCashFromSnackMachine(SnackMachine snackMachine)
        {
            Money money = snackMachine.UnloadMoney();

            Cash += money;
        }