コード例 #1
0
        public void OutputService_CloseAsync_DeveMudarOEstadoParaFechadoCorretamenteQuandoEstiverAberto()
        {
            // Arange
            int totalItens = 5;

            Output             output      = OutputFaker.GenerateFaker().Generate();
            IList <OutputItem> outputItens = OutputItemFaker.GenerateFaker(output).Generate(totalItens);

            ConfigureMock();

            FactoryService();

            foreach (OutputItem outputItem in outputItens)
            {
                _outputService.AddItemAsync(output, outputItem);
            }

            // Act
            _outputService.CloseAsync(output);

            // Assert
            output.State.Should().Be(OutputState.Closed);
            output.Items.Should().HaveCount(totalItens);
            output.TotalValue.Should().Be(outputItens.Sum(x => x.CalculteValue()));
            _outputRepositoryMock.Verify(x => x.Update(It.IsAny <Output>()), Times.Exactly(totalItens + 1));
            _unitOfWork.Verify(x => x.CommitAsync(), Times.Exactly(totalItens + 1));
            _busHandlerMock.Verify(x => x.PublishDomainEvent(It.IsAny <OutputClosedEvent>()), Times.Once);
        }
コード例 #2
0
        public void OutputService_AddItemAsync_DeveAdicionarOsItensQuandoEmEstadoValido()
        {
            // Arange
            int totalItens = 5;

            Output             output      = OutputFaker.GenerateFaker().Generate();
            IList <OutputItem> outputItens = OutputItemFaker.GenerateFaker(output).Generate(totalItens);

            ConfigureMock();

            FactoryService();

            // Act
            foreach (OutputItem outputItem in outputItens)
            {
                _outputService.AddItemAsync(output, outputItem);
            }

            // Assert
            output.Items.Should().HaveCount(totalItens);
            output.TotalValue.Should().Be(outputItens.Sum(x => x.CalculteValue()));
            _outputRepositoryMock.Verify(x => x.Update(It.IsAny <Output>()), Times.Exactly(totalItens));
            _unitOfWork.Verify(x => x.CommitAsync(), Times.Exactly(totalItens));
            _busHandlerMock.Verify(x => x.PublishDomainEvent(It.IsAny <OutputItemAdded>()), Times.Exactly(totalItens));
        }
コード例 #3
0
        public void OutputService_RemoveItemAsync_DeveRemoverOItemQuandoOMesmoExistir()
        {
            // Arange
            int totalItens = 5;

            Output             output      = OutputFaker.GenerateFaker().Generate();
            IList <OutputItem> outputItens = OutputItemFaker.GenerateFaker(output).Generate(totalItens);

            ConfigureMock();

            FactoryService();

            foreach (OutputItem outputItem in outputItens)
            {
                _outputService.AddItemAsync(output, outputItem);
            }

            // Act
            _outputService.RemoveItemAsync(output, outputItens.First());

            // Assert
            output.Items.Should().HaveCount(totalItens - 1);
            output.TotalValue.Should().Be(outputItens.Skip(1).Sum(x => x.CalculteValue()));
            _outputRepositoryMock.Verify(x => x.Remove(It.IsAny <Output>()), Times.Once);
            _unitOfWork.Verify(x => x.CommitAsync(), Times.Exactly(totalItens + 1));
            _busHandlerMock.Verify(x => x.PublishDomainEvent(It.IsAny <OutputItemRemoved>()), Times.Once);
        }
コード例 #4
0
        public void Output_AddItem_DeveSetarOStatusParaFechadoCorretamenteSeEstiverAberto()
        {
            // Arange
            Output output = OutputFaker.GenerateFaker().Generate();

            // Act
            output.Close();

            // Assert
            output.State.Should().Be(OutputState.Closed);
        }
コード例 #5
0
        public void Output_RemoveItem_DeveGerarDomainExceptionAoFecharORegistroQueEstaFechado()
        {
            // Arange
            Output output = OutputFaker.GenerateFaker().Generate();

            output.Close();

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

            // Assert
            act.Should().Throw <DomainException>();
        }
コード例 #6
0
        public void OutputItem_Validate_DeveRetornarDomainExceptionAoTentarCriarComValoresInvalidos()
        {
            // Arange && Act
            Output  output  = OutputFaker.GenerateFaker().Generate();
            Product product = ProductFaker.GenerateFaker().Generate();

            Func <OutputItem> func1 = () => new OutputItem(0, 1, output, product);
            Func <OutputItem> func2 = () => new OutputItem(1, 0, output, product);

            // Assert
            func1.Should().Throw <DomainException>();
            func2.Should().Throw <DomainException>();
        }
コード例 #7
0
        public void Output_UpdateItem_DeveGerarDomainExceptionQuandoTentarAtualizarUmItemInexistente()
        {
            // Arange
            Output output = OutputFaker.GenerateFaker().Generate();

            OutputItem outputItem = OutputItemFaker.GenerateFaker(output).Generate();

            // Act
            Action act = () => output.UpdateItem(outputItem);

            // Assert
            act.Should().Throw <DomainException>();
        }
コード例 #8
0
        public void OutputItem_CalculteValue_DeveCalculaCorretamenteOValorDoItem()
        {
            // Arange && Act
            Output  output  = OutputFaker.GenerateFaker().Generate();
            Product product = ProductFaker.GenerateFaker().Generate();

            OutputItem item = new OutputItem(10, 2, output, product);

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

            // Assert
            value.Should().Be(20);
        }
コード例 #9
0
        public void Output_AddItem_DeveGerarDomainExceptionQuandoAdicionarUmItemEEstiverFechado()
        {
            // Arange
            Output output = OutputFaker.GenerateFaker().Generate();

            output.Close();

            OutputItem item1 = OutputItemFaker.GenerateFaker(output).Generate();

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

            // Assert
            act.Should().Throw <DomainException>();
        }
コード例 #10
0
        public void Output_CalculateTotalValue_DeveSomarCorretamenteValorTotal()
        {
            // Arange && Act
            Output output = OutputFaker.GenerateFaker().Generate();

            IList <OutputItem> itemsMock = OutputItemFaker.GenerateFaker(output).Generate(10);

            foreach (OutputItem itemMock in itemsMock)
            {
                output.AddItem(itemMock);
            }

            // Assert
            output.TotalValue.Should().Be(itemsMock.Sum(x => x.CalculteValue()));
        }
コード例 #11
0
        public void Output_RemoveItem_DeveGerarDomainExceptionQuandoRemoverUmItemInexistente()
        {
            // Arange
            Output output = OutputFaker.GenerateFaker().Generate();

            IList <OutputItem> itemsMock = OutputItemFaker.GenerateFaker(output).Generate(2);

            output.AddItem(itemsMock.First());

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

            // Assert
            act.Should().Throw <DomainException>();
        }
コード例 #12
0
        public void Output_UpdateItem_DeveAtualizarCorretamenteUmItemQuandoOMesmoExistir()
        {
            // Arange
            Output output = OutputFaker.GenerateFaker().Generate();

            OutputItem outputItem = OutputItemFaker.GenerateFaker(output).Generate();

            output.AddItem(outputItem);

            // Act
            output.UpdateItem(outputItem);

            // Assert
            output.Items.Should().HaveCount(1);
        }
コード例 #13
0
        public void OutputItem_Update_DeveAtualizarCorretamenteOItemQuandoInformadoValoresValidos()
        {
            // Arange && Act
            Output  output     = OutputFaker.GenerateFaker().Generate();
            Product product    = ProductFaker.GenerateFaker().Generate();
            Product newProduct = ProductFaker.GenerateFaker().Generate();

            OutputItem item = new OutputItem(10, 2, output, product);

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

            // Assert
            item.Amount.Should().Be(10);
            item.Value.Should().Be(5);
        }
コード例 #14
0
        public void Output_AddItem_DeveAdicionarOsItensCorretamenteQuandoValidos()
        {
            // Arange
            Output output = OutputFaker.GenerateFaker().Generate();

            // Act
            IList <OutputItem> itemsMock = OutputItemFaker.GenerateFaker(output).Generate(10);

            foreach (OutputItem itemMock in itemsMock)
            {
                output.AddItem(itemMock);
            }

            // Assert
            output.Items.Should().HaveCount(10);
        }
コード例 #15
0
        public void OutputItem_Update_DeveRetornarDomainExceptionAoTentarAtualizarComValoresInvalidos()
        {
            // Arange && Act
            Output  output     = OutputFaker.GenerateFaker().Generate();
            Product product    = ProductFaker.GenerateFaker().Generate();
            Product newProduct = ProductFaker.GenerateFaker().Generate();

            OutputItem item = new OutputItem(10, 2, output, 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>();
        }
コード例 #16
0
        public void Output_RemoveItem_DeveRemoverCorretamenteQuandoItemExistir()
        {
            // Arange
            Output output = OutputFaker.GenerateFaker().Generate();

            IList <OutputItem> itemsMock = OutputItemFaker.GenerateFaker(output).Generate(2);

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

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

            // Assert
            output.Items.Should().HaveCount(1);
            output.Items.Should().NotContain(x => x.Id == itemsMock.First().Id);
        }
コード例 #17
0
        public void OutputService_CloseAsync_DeveGerarDomainExceptionQuandoQuandoEstiverFechadoETentarFecharNovamente()
        {
            // Arange
            Output output = OutputFaker.GenerateFaker().Generate();

            output.Close();

            ConfigureMock();

            FactoryService();

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

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