Ejemplo n.º 1
0
        public void Purchase_AddItem_DeveGerarDomainExceptionQuandoAdicionarUmItemEOMesmoJaExistir()
        {
            // Arange
            Purchase purchase = PurchaseFaker.GenerateFaker().Generate();

            PurchaseItem item1 = PurchaseItemFaker.GenerateFaker(purchase).Generate();

            purchase.AddItem(item1);

            // Act
            Action act = () => purchase.AddItem(item1);

            // Assert
            act.Should().Throw <DomainException>();
        }
Ejemplo n.º 2
0
        public void Purchase_RemoveItem_DeveRemoverCorretamenteQuandoItemExistir()
        {
            // Arange
            Purchase purchase = PurchaseFaker.GenerateFaker().Generate();

            IList <PurchaseItem> itemsMock = PurchaseItemFaker.GenerateFaker(purchase).Generate(2);

            purchase.AddItem(itemsMock.First());
            purchase.AddItem(itemsMock.Last());

            // Act
            purchase.RemoveItem(itemsMock.First());

            // Assert
            purchase.Items.Should().HaveCount(1);
            purchase.Items.Should().NotContain(x => x.Id == itemsMock.First().Id);
        }
        public async Task AddItemAsync(Purchase purchase, PurchaseItem item)
        {
            purchase.AddItem(item);

            _repository.Update(purchase);

            if (await _repository.UnitOfWork.CommitAsync())
            {
                await _bus.PublishDomainEvent(new PurchaseItemAdded(item.Id));
            }
        }
Ejemplo n.º 4
0
 void AddIngredientsToSession(List <IngredientWithCountVM> ingredients)
 {
     purchase = sessionManager.GetItem();
     foreach (IngredientWithCountVM ingredient in ingredients)
     {
         if (ingredient != null)
         {
             purchase.AddItem(ingredient, ingredient.Count);
             sessionManager.SetItem(purchase);
         }
     }
 }
Ejemplo n.º 5
0
        public void Purchase_CalculateTotalValue_DeveSomarCorretamenteValorTotal()
        {
            // Arange && Act
            Purchase purchase = PurchaseFaker.GenerateFaker().Generate();

            IList <PurchaseItem> itemsMock = PurchaseItemFaker.GenerateFaker(purchase).Generate(10);

            foreach (PurchaseItem itemMock in itemsMock)
            {
                purchase.AddItem(itemMock);
            }

            // Assert
            purchase.TotalValue.Should().Be(itemsMock.Sum(x => x.CalculteValue()));
        }
Ejemplo n.º 6
0
        public void Purchase_RemoveItem_DeveGerarDomainExceptionQuandoRemoverUmItemInexistente()
        {
            // Arange
            Purchase purchase = PurchaseFaker.GenerateFaker().Generate();

            IList <PurchaseItem> itemsMock = PurchaseItemFaker.GenerateFaker(purchase).Generate(2);

            purchase.AddItem(itemsMock.First());

            // Act
            Action act = () => purchase.RemoveItem(itemsMock.Last());

            // Assert
            act.Should().Throw <DomainException>();
        }
Ejemplo n.º 7
0
        public void Purchase_UpdateItem_DeveAtualizarCorretamenteUmItemQuandoOMesmoExistir()
        {
            // Arange
            Purchase purchase = PurchaseFaker.GenerateFaker().Generate();

            PurchaseItem purchaseItem = PurchaseItemFaker.GenerateFaker(purchase).Generate();

            purchase.AddItem(purchaseItem);

            // Act
            purchase.UpdateItem(purchaseItem);

            // Assert
            purchase.Items.Should().HaveCount(1);
        }
Ejemplo n.º 8
0
        public void UseDemandingMock()
        {
            var demandingMock    = new Mock <IDiscountLogic>();
            var expectedPurchase = new Purchase();

            expectedPurchase.AddItem(new Item(400));
            expectedPurchase.AddItem(new Item(650));

            var purchaseWorkflow
                = new PurchaseWorkflow(demandingMock.Object);

            purchaseWorkflow.AddItemsStep(new Item(400),
                                          new Item(650));
            purchaseWorkflow.DiscountStep();
            purchaseWorkflow.DiscountStep();
            purchaseWorkflow.DiscountStep();

            demandingMock.Verify(am => am.ApplyDiscount(
                                     It.IsInRange(1000000L, 9999999L,
                                                  Range.Inclusive),
                                     It.IsRegex("DISCOUNT_\\d{3,10}[X-Z]?"),
                                     It.Is <Purchase>(p => IsPremiumPurchase(p))),
                                 Times.Exactly(3));
        }
Ejemplo n.º 9
0
        public void Purchase_AddItem_DeveAdicionarOsItensCorretamenteQuandoValidos()
        {
            // Arange
            Purchase purchase = PurchaseFaker.GenerateFaker().Generate();

            // Act
            IList <PurchaseItem> itemsMock = PurchaseItemFaker.GenerateFaker(purchase).Generate(10);

            foreach (PurchaseItem itemMock in itemsMock)
            {
                purchase.AddItem(itemMock);
            }

            // Assert
            purchase.Items.Should().HaveCount(10);
        }
Ejemplo n.º 10
0
        public void UseAverageMock()
        {
            var averageMock      = new Mock <IDiscountLogic>();
            var expectedPurchase = new Purchase();

            expectedPurchase.AddItem(new Item(400));

            var purchaseWorkflow
                = new PurchaseWorkflow(averageMock.Object);

            purchaseWorkflow.AddItemsStep(new Item(400));
            purchaseWorkflow.DiscountStep();

            averageMock.Verify(am => am.ApplyDiscount(
                                   It.IsInRange(1, long.MaxValue,
                                                Range.Inclusive),
                                   "DISCOUNT_123",
                                   It.Is <Purchase>(p => p.Equals(expectedPurchase))));
        }