Beispiel #1
0
        public void Adjustment_AddItem_DeveGerarDomainExceptionQuandoAdicionarUmItemEOMesmoJaExistir()
        {
            // Arange
            Adjustment adjustment = AdjustmentFaker.GenerateFaker().Generate();

            AdjustmentItem item1 = AdjustmentItemFaker.GenerateFaker(adjustment).Generate();

            adjustment.AddItem(item1);

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

            // Assert
            act.Should().Throw <DomainException>();
        }
Beispiel #2
0
        public void Adjustment_RemoveItem_DeveRemoverCorretamenteQuandoItemExistir()
        {
            // Arange
            Adjustment adjustment = AdjustmentFaker.GenerateFaker().Generate();

            IList <AdjustmentItem> itemsMock = AdjustmentItemFaker.GenerateFaker(adjustment).Generate(2);

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

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

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

            _repository.Update(adjustment);

            if (await _repository.UnitOfWork.CommitAsync())
            {
                await _bus.PublishDomainEvent(new AdjustmentItemAdded(item.Id));
            }
        }
Beispiel #4
0
        public void Adjustment_CalculateTotalValue_DeveSomarCorretamenteValorTotal()
        {
            // Arange && Act
            Adjustment adjustment = AdjustmentFaker.GenerateFaker().Generate();

            IList <AdjustmentItem> itemsMock = AdjustmentItemFaker.GenerateFaker(adjustment).Generate(10);

            foreach (AdjustmentItem itemMock in itemsMock)
            {
                adjustment.AddItem(itemMock);
            }

            // Assert
            adjustment.TotalValue.Should().Be(itemsMock.Sum(x => x.CalculteValue()));
        }
Beispiel #5
0
        public void Adjustment_RemoveItem_DeveGerarDomainExceptionQuandoRemoverUmItemInexistente()
        {
            // Arange
            Adjustment adjustment = AdjustmentFaker.GenerateFaker().Generate();

            IList <AdjustmentItem> itemsMock = AdjustmentItemFaker.GenerateFaker(adjustment).Generate(2);

            adjustment.AddItem(itemsMock.First());

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

            // Assert
            act.Should().Throw <DomainException>();
        }
Beispiel #6
0
        public void Adjustment_UpdateItem_DeveAtualizarCorretamenteUmItemQuandoOMesmoExistir()
        {
            // Arange
            Adjustment adjustment = AdjustmentFaker.GenerateFaker().Generate();

            AdjustmentItem adjustmentItem = AdjustmentItemFaker.GenerateFaker(adjustment).Generate();

            adjustment.AddItem(adjustmentItem);

            // Act
            adjustment.UpdateItem(adjustmentItem);

            // Assert
            adjustment.Items.Should().HaveCount(1);
        }
Beispiel #7
0
        public void Adjustment_AddItem_DeveAdicionarOsItensCorretamenteQuandoValidos()
        {
            // Arange
            Adjustment adjustment = AdjustmentFaker.GenerateFaker().Generate();

            // Act
            IList <AdjustmentItem> itemsMock = AdjustmentItemFaker.GenerateFaker(adjustment).Generate(10);

            foreach (AdjustmentItem itemMock in itemsMock)
            {
                adjustment.AddItem(itemMock);
            }

            // Assert
            adjustment.Items.Should().HaveCount(10);
        }