public async Task Then_the_account_changes_are_persisted_to_the_domain_repository() { //Arrange var command = _fixture.Create <RemoveLegalEntityCommand>(); var legalEntityModel = _fixture.Create <LegalEntityModel>(); legalEntityModel.Id = command.AccountId; legalEntityModel.AccountLegalEntityId = command.AccountLegalEntityId; _mockDomainRespository .Setup(m => m.Find(command.AccountId)) .ReturnsAsync(Account.Create( new AccountModel { Id = command.AccountId, LegalEntityModels = new Collection <LegalEntityModel>() { _fixture.Create <LegalEntityModel>(), legalEntityModel, _fixture.Create <LegalEntityModel>(), } })); //Act await _sut.Handle(command); //Assert _mockDomainRespository.Verify(m => m.Save(It.Is <Account>(i => i.Id == command.AccountId && i.LegalEntities.Count == 2)), Times.Once); }
public void ThenTheValidatorIsCalledAndAnInvalidRequestExceptionThrownIfItIsNotValid() { //Arrange _validator.Setup(x => x.ValidateAsync(It.IsAny <RemoveLegalEntityCommand>())).ReturnsAsync(new ValidationResult { ValidationDictionary = new Dictionary <string, string> { { "", "" } } }); //Act Assert Assert.ThrowsAsync <InvalidRequestException>(async() => await _handler.Handle(new RemoveLegalEntityCommand())); }