public void AdjustmentService_Close_DeveMudarOEstadoParaFechadoCorretamenteQuandoEstiverAberto()
        {
            // Arange
            int totalItens = 5;

            Adjustment             adjustment      = AdjustmentFaker.GenerateFaker().Generate();
            IList <AdjustmentItem> adjustmentItens = AdjustmentItemFaker.GenerateFaker(adjustment).Generate(totalItens);

            ConfigureMock();

            FactoryService();

            foreach (AdjustmentItem adjustmentItem in adjustmentItens)
            {
                _adjustmentService.AddItemAsync(adjustment, adjustmentItem);
            }

            // Act
            _adjustmentService.CloseAsync(adjustment);

            // Assert
            adjustment.State.Should().Be(AdjustmentState.Closed);
            adjustment.Items.Should().HaveCount(totalItens);
            adjustment.TotalValue.Should().Be(adjustmentItens.Sum(x => x.CalculteValue()));
            _adjustmentRepositoryMock.Verify(x => x.Update(It.IsAny <Adjustment>()), Times.Exactly(totalItens + 1));
            _unitOfWork.Verify(x => x.CommitAsync(), Times.Exactly(totalItens + 1));
            _busHandlerMock.Verify(x => x.PublishDomainEvent(It.IsAny <AdjustmentClosedEvent>()), Times.Once);
        }
        public void AdjustmentService_RemoveItem_DeveRemoverOItemQuandoOMesmoExistir()
        {
            // Arange
            int totalItens = 5;

            Adjustment             adjustment      = AdjustmentFaker.GenerateFaker().Generate();
            IList <AdjustmentItem> adjustmentItens = AdjustmentItemFaker.GenerateFaker(adjustment).Generate(totalItens);

            ConfigureMock();

            FactoryService();

            foreach (AdjustmentItem adjustmentItem in adjustmentItens)
            {
                _adjustmentService.AddItemAsync(adjustment, adjustmentItem);
            }

            // Act
            _adjustmentService.RemoveItemAsync(adjustment, adjustmentItens.First());

            // Assert
            adjustment.Items.Should().HaveCount(totalItens - 1);
            adjustment.TotalValue.Should().Be(adjustmentItens.Skip(1).Sum(x => x.CalculteValue()));
            _adjustmentRepositoryMock.Verify(x => x.Remove(It.IsAny <Adjustment>()), Times.Once);
            _unitOfWork.Verify(x => x.CommitAsync(), Times.Exactly(totalItens + 1));
            _busHandlerMock.Verify(x => x.PublishDomainEvent(It.IsAny <AdjustmentItemRemoved>()), Times.Once);
        }
        public void AdjustmentService_AddItem_DeveAdicionarOsItensQuandoEmEstadoValido()
        {
            // Arange
            int totalItens = 5;

            Adjustment             adjustment      = AdjustmentFaker.GenerateFaker().Generate();
            IList <AdjustmentItem> adjustmentItens = AdjustmentItemFaker.GenerateFaker(adjustment).Generate(totalItens);

            ConfigureMock();

            FactoryService();

            // Act
            foreach (AdjustmentItem adjustmentItem in adjustmentItens)
            {
                _adjustmentService.AddItemAsync(adjustment, adjustmentItem);
            }

            // Assert
            adjustment.Items.Should().HaveCount(totalItens);
            adjustment.TotalValue.Should().Be(adjustmentItens.Sum(x => x.CalculteValue()));
            _adjustmentRepositoryMock.Verify(x => x.Update(It.IsAny <Adjustment>()), Times.Exactly(totalItens));
            _unitOfWork.Verify(x => x.CommitAsync(), Times.Exactly(totalItens));
            _busHandlerMock.Verify(x => x.PublishDomainEvent(It.IsAny <AdjustmentItemAdded>()), Times.Exactly(totalItens));
        }
Ejemplo n.º 4
0
        public void Adjustment_AddItem_DeveSetarOStatusParaFechadoCorretamenteSeEstiverAberto()
        {
            // Arange
            Adjustment adjustment = AdjustmentFaker.GenerateFaker().Generate();

            // Act
            adjustment.Close();

            // Assert
            adjustment.State.Should().Be(AdjustmentState.Closed);
        }
Ejemplo n.º 5
0
        public void AdjustmentItem_Validate_DeveRetornarDomainExceptionAoTentarCriarComValoresInvalidos()
        {
            // Arange && Act
            Adjustment adjustment = AdjustmentFaker.GenerateFaker().Generate();
            Product    product    = ProductFaker.GenerateFaker().Generate();

            Func <AdjustmentItem> func1 = () => new AdjustmentItem(0, 1, adjustment, product);
            Func <AdjustmentItem> func2 = () => new AdjustmentItem(1, 0, adjustment, product);

            // Assert
            func1.Should().Throw <DomainException>();
            func2.Should().Throw <DomainException>();
        }
Ejemplo n.º 6
0
        public void Adjustment_RemoveItem_DeveGerarDomainExceptionAoFecharORegistroQueEstaFechado()
        {
            // Arange
            Adjustment adjustment = AdjustmentFaker.GenerateFaker().Generate();

            adjustment.Close();

            // Act
            Action act = () => adjustment.Close();

            // Assert
            act.Should().Throw <DomainException>();
        }
Ejemplo n.º 7
0
        public void Adjustment_UpdateItem_DeveGerarDomainExceptionQuandoTentarAtualizarUmItemInexistente()
        {
            // Arange
            Adjustment adjustment = AdjustmentFaker.GenerateFaker().Generate();

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

            // Act
            Action act = () => adjustment.UpdateItem(adjustmentItem);

            // Assert
            act.Should().Throw <DomainException>();
        }
Ejemplo n.º 8
0
        public void AdjustmentItem_CalculteValue_DeveCalculaCorretamenteOValorDoItem()
        {
            // Arange && Act
            Adjustment adjustment = AdjustmentFaker.GenerateFaker().Generate();
            Product    product    = ProductFaker.GenerateFaker().Generate();

            AdjustmentItem item = new AdjustmentItem(10, 2, adjustment, product);

            // Act
            decimal value = item.CalculteValue();

            // Assert
            value.Should().Be(20);
        }
Ejemplo n.º 9
0
        public void Adjustment_AddItem_DeveGerarDomainExceptionQuandoAdicionarUmItemEEstiverFechado()
        {
            // Arange
            Adjustment adjustment = AdjustmentFaker.GenerateFaker().Generate();

            adjustment.Close();

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

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

            // Assert
            act.Should().Throw <DomainException>();
        }
Ejemplo n.º 10
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()));
        }
Ejemplo n.º 11
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>();
        }
Ejemplo n.º 12
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);
        }
Ejemplo n.º 13
0
        public void AdjustmentItem_Update_DeveAtualizarCorretamenteOItemQuandoInformadoValoresValidos()
        {
            // Arange && Act
            Adjustment adjustment = AdjustmentFaker.GenerateFaker().Generate();
            Product    product    = ProductFaker.GenerateFaker().Generate();
            Product    newProduct = ProductFaker.GenerateFaker().Generate();

            AdjustmentItem item = new AdjustmentItem(10, 2, adjustment, product);

            // Act
            item.Update(10, 5, newProduct);

            // Assert
            item.Amount.Should().Be(10);
            item.Value.Should().Be(5);
        }
Ejemplo n.º 14
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);
        }
Ejemplo n.º 15
0
        public void AdjustmentItem_Update_DeveRetornarDomainExceptionAoTentarAtualizarComValoresInvalidos()
        {
            // Arange && Act
            Adjustment adjustment = AdjustmentFaker.GenerateFaker().Generate();
            Product    product    = ProductFaker.GenerateFaker().Generate();
            Product    newProduct = ProductFaker.GenerateFaker().Generate();

            AdjustmentItem item = new AdjustmentItem(10, 2, adjustment, product);

            // Act
            Action action1 = () => item.Update(0, 5, newProduct);
            Action action2 = () => item.Update(1, 0, newProduct);

            // Assert
            action1.Should().Throw <DomainException>();
            action2.Should().Throw <DomainException>();
        }
Ejemplo n.º 16
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 void AdjustmentService_Close_DeveGerarDomainExceptionQuandoQuandoEstiverFechadoETentarFecharNovamente()
        {
            // Arange
            Adjustment adjustment = AdjustmentFaker.GenerateFaker().Generate();

            adjustment.Close();

            ConfigureMock();

            FactoryService();

            // Act
            Action act = () => adjustment.Close();

            // Assert
            act.Should().Throw <DomainException>();
            _adjustmentRepositoryMock.Verify(x => x.Update(It.IsAny <Adjustment>()), Times.Never);
            _unitOfWork.Verify(x => x.CommitAsync(), Times.Never);
            _busHandlerMock.Verify(x => x.PublishDomainEvent(It.IsAny <AdjustmentClosedEvent>()), Times.Never);
        }