Beispiel #1
0
        //TODO refactor to take viewmodel and ids
        public void TransferCookiesFromTroopToGirlScout(TransferCookiesToGirlScoutDto data)
        {
            using (var uow = UnitOfWork)
            {
                IEnumerable <CookieQuantity> cookies = new[]
                {
                    new CookieQuantity(data.DoSiSos, Cookie.DosiSo),
                    new CookieQuantity(data.Samoas, Cookie.Samoas),
                    new CookieQuantity(data.Savannah, Cookie.Savannah),
                    new CookieQuantity(data.Smors, Cookie.Smors),
                    new CookieQuantity(data.Tagalongs, Cookie.Tagalongs),
                    new CookieQuantity(data.ThinMints, Cookie.ThinMints),
                    new CookieQuantity(data.ToffeeTastic, Cookie.ToffeeTastic),
                    new CookieQuantity(data.Trefoils, Cookie.Trefoils),
                };
                DateTime dateReceived         = data.DateReceived;
                int      troopInventoryId     = data.TroopInventoryId;
                int      girlScoutInventoryId = data.GirlScoutInventoryId;


                var command = new TransferCookiesCommand(troopInventoryId, girlScoutInventoryId, cookies, dateReceived);
                var handler = new TransferCookiesCommandHandler(uow);
                var result  = handler.Handle(command);
            }
        }
        public void TransferToTroopInventory_FromGirlInventory_Succeeds()
        {
            TransferFromTroopInventory_ToGirlInventory_Succeeds();

            _unitOfWork.Setup(f => f.Get <CookieInventory>(It.Is <int>(id => id == 1))).Returns(_troopInventory);
            _unitOfWork.Setup(f => f.Get <CookieInventory>(It.Is <int>(id => id == 2))).Returns(_girlInventory);

            var command = new TransferCookiesCommand(2, 1,
                                                     new[] { new CookieQuantity(5, Cookie.DosiSo) }, DateTime.UtcNow);

            var handler = new TransferCookiesCommandHandler(_unitOfWork.Object);
            var result  = handler.Handle(command);

            result.IsSuccess.Should().BeTrue();

            _troopInventory.Balance.Should().Be(125);
            _troopInventory.Stacks.Sum(c => c.CookieQuantity.Quantity).Should().Be(25);
            _girlInventory.Balance.Should().Be(0);
            _girlInventory.Stacks.Sum(c => c.CookieQuantity.Quantity).Should().Be(0);
        }