public async Task RemoveItemAsync(Adjustment adjustment, AdjustmentItem item) { adjustment.RemoveItem(item); _repository.Update(adjustment); if (await _repository.UnitOfWork.CommitAsync()) { await _bus.PublishDomainEvent(new AdjustmentItemRemoved(item.Id)); } }
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>(); }
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); }