public async Task HandleAsync(DeleteHouseholdCommand message, CancellationToken token = default(CancellationToken))
        {
            var household = await this.GetHouseholdAsync(message.HouseholdId);

            household.Delete();
            _households.Delete(household);
            await _households.SaveChangesAsync(token);
        }
Esempio n. 2
0
        public async Task ShouldDeleteExisting()
        {
            // Arrange
            Household entity = Household.Create(Guid.NewGuid(), Guid.NewGuid(), "Name", "Symbol",
                                                "Description", Address.Create("Country", "00-000", "City", "Street"));
            var repository = new Mock <IHouseholdRepository>();

            repository.Setup(e =>
                             e.GetByIdAsync(It.IsAny <Guid>(), It.IsAny <CancellationToken>())).ReturnsAsync(entity);
            DeleteHouseholdCommand cmd = new DeleteHouseholdCommand(entity.Id);

            HouseholdCommandHandler actual = new HouseholdCommandHandler(repository.Object);

            // Act
            await actual.HandleAsync(cmd);

            // Assert
            repository.Verify(e =>
                              e.Delete(It.Is <Household>(a => a.Equals(entity))),
                              Times.Once
                              );
        }