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 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 Output_AddItem_DeveSetarOStatusParaFechadoCorretamenteSeEstiverAberto() { // Arange Output output = OutputFaker.GenerateFaker().Generate(); // Act output.Close(); // Assert output.State.Should().Be(OutputState.Closed); }
public void Output_RemoveItem_DeveGerarDomainExceptionAoFecharORegistroQueEstaFechado() { // Arange Output output = OutputFaker.GenerateFaker().Generate(); output.Close(); // Act Action act = () => output.Close(); // Assert act.Should().Throw <DomainException>(); }
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>(); }
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 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); }
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 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); }
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); }
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>(); }
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); }
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); }