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);
        }
        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);
        }
        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));
        }
        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>();
        }
        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>();
        }
        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()));
        }
        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>();
        }
        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);
        }
        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);
        }
Esempio n. 10
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);
        }