public async Task Handle(UpsertLegalEntityCommand command, CancellationToken cancellationToken = default) { var account = await _domainRepository.Find(command.AccountId); if (account == null) { account = Account.New(command.AccountId); } var legalEntity = account.GetLegalEntity(command.AccountLegalEntityId); if (account.GetLegalEntity(command.AccountLegalEntityId) != null) { if (!string.IsNullOrEmpty(legalEntity.HashedLegalEntityId)) { return; // already created } legalEntity.SetHashedLegalEntityId(_hashingService.HashValue(command.LegalEntityId)); } else { account.AddLegalEntity(command.AccountLegalEntityId, LegalEntity.New(command.LegalEntityId, command.Name, _hashingService.HashValue(command.LegalEntityId))); } await _domainRepository.Save(account); }
public async Task Then_VRF_EmployerVendorId_is_not_added_to_legal_entities_which_do_have_a_vendor_id_assigned() { // Arrange var command = new AddEmployerVendorIdForLegalEntityCommand(LegalEntityToBeUpdatedId, _fixture.Create <string>()); var accounts = _fixture.CreateMany <Account>(3).ToList(); var legalEntityToBeUpdated = LegalEntity.New(123, _fixture.Create <string>(), LegalEntityToBeUpdatedId); legalEntityToBeUpdated.AddEmployerVendorId(_fixture.Create <string>()); accounts[0].AddLegalEntity(1, legalEntityToBeUpdated); accounts[0].AddLegalEntity(2, _fixture.Create <LegalEntity>()); accounts[0].AddLegalEntity(3, _fixture.Create <LegalEntity>()); accounts[1].AddLegalEntity(4, _fixture.Create <LegalEntity>()); accounts[1].AddLegalEntity(5, legalEntityToBeUpdated); _mockDomainRepository.Setup(x => x.GetByHashedLegalEntityId(command.HashedLegalEntityId)).ReturnsAsync(accounts); // Act await _sut.Handle(command); // Assert var updatedLegalEntities = accounts.SelectMany(x => x.LegalEntities.Where(e => e.HashedLegalEntityId == command.HashedLegalEntityId)).ToList(); updatedLegalEntities.Should().NotBeEmpty(); foreach (var legalEntity in updatedLegalEntities) { legalEntity.VrfVendorId.Should().NotBe(command.EmployerVendorId); } _mockDomainRepository.Verify(m => m.Save(accounts[0]), Times.Once); _mockDomainRepository.Verify(m => m.Save(accounts[1]), Times.Once); _mockDomainRepository.VerifyAll(); }
public async Task Then_event_BankDetailsApprovedForLegalEntity_is_raised_when_status_is_completed() { // Arrange var account = _fixture.Create <Account>(); var caseCompletedCommand = new UpdateVendorRegistrationCaseStatusForAccountCommand(account.Id, LegalEntityToBeUpdatedId, _fixture.Create <string>(), LegalEntityVrfCaseStatus.Completed, _fixture.Create <DateTime>()); var legalEntityToBeUpdated = LegalEntity.New(123, _fixture.Create <string>(), LegalEntityToBeUpdatedId); account.AddLegalEntity(1, legalEntityToBeUpdated); account.AddLegalEntity(2, _fixture.Create <LegalEntity>()); account.AddLegalEntity(3, _fixture.Create <LegalEntity>()); _mockDomainRepository.Setup(x => x.Find(caseCompletedCommand.AccountId)).ReturnsAsync(account); // Act await _sut.Handle(caseCompletedCommand); // Assert var events = account.FlushEvents().ToList(); events.Count.Should().Be(1); events[0].GetType().Should().Be <BankDetailsApprovedForLegalEntity>(); ((BankDetailsApprovedForLegalEntity)events[0]).HashedLegalEntityId.Should().Be(LegalEntityToBeUpdatedId); }
public void Then_has_signed_incentive_terms_is_false() { // Act var legalEntity = LegalEntity.New(_fixture.Create <long>(), _fixture.Create <string>()); // Assert legalEntity.HasSignedAgreementTerms.Should().BeFalse(); }
public void Then_the_name_is_set() { // Arrange var name = _fixture.Create <string>(); // Act var legalEntity = LegalEntity.New(_fixture.Create <long>(), name); // Assert legalEntity.Name.Should().Be(name); }
public void Then_the_id_is_set() { // Arrange var id = _fixture.Create <long>(); // Act var legalEntity = LegalEntity.New(id, _fixture.Create <string>()); // Assert legalEntity.Id.Should().Be(id); }
public async Task Then_VRF_details_for_given_legal_entity_are_not_updated_if_status_is_completed() { // Arrange var account = _fixture.Create <Account>(); var caseCompletedCommand = new UpdateVendorRegistrationCaseStatusForAccountCommand(account.Id, LegalEntityToBeUpdatedId, _fixture.Create <string>(), "case request completed", _fixture.Create <DateTime>()); var legalEntityToBeUpdated = LegalEntity.New(123, _fixture.Create <string>(), LegalEntityToBeUpdatedId); account.AddLegalEntity(1, legalEntityToBeUpdated); account.AddLegalEntity(2, _fixture.Create <LegalEntity>()); account.AddLegalEntity(3, _fixture.Create <LegalEntity>()); // Act _mockDomainRepository.Setup(x => x.Find(caseCompletedCommand.AccountId)).ReturnsAsync(account); await _sut.Handle(caseCompletedCommand); var command2 = new UpdateVendorRegistrationCaseStatusForAccountCommand(account.Id, LegalEntityToBeUpdatedId, caseCompletedCommand.CaseId, "New Status", _fixture.Create <DateTime>()); // Act await _sut.Handle(command2); // Assert var legalEntities = account.LegalEntities.Where( e => e.HashedLegalEntityId == command2.HashedLegalEntityId).ToList(); legalEntities.Should().NotBeEmpty(); foreach (var legalEntity in legalEntities) { legalEntity.VrfCaseId.Should().Be(caseCompletedCommand.CaseId); legalEntity.VrfCaseStatus.Should().Be(caseCompletedCommand.Status); legalEntity.VrfCaseStatusLastUpdatedDateTime.Should().Be(caseCompletedCommand.LastUpdatedDate); } }
public async Task Then_VRF_details_for_given_legal_entity_are_updated() { // Arrange var account = _fixture.Create <Account>(); var command = new UpdateVendorRegistrationCaseStatusForAccountCommand( account.Id, LegalEntityToBeUpdatedId, _fixture.Create <string>(), _fixture.Create <string>(), _fixture.Create <DateTime>()); var legalEntityToBeUpdated = LegalEntity.New(123, _fixture.Create <string>(), LegalEntityToBeUpdatedId); account.AddLegalEntity(1, legalEntityToBeUpdated); account.AddLegalEntity(2, _fixture.Create <LegalEntity>()); account.AddLegalEntity(3, _fixture.Create <LegalEntity>()); account.AddLegalEntity(4, legalEntityToBeUpdated); _mockDomainRepository.Setup(x => x.Find(command.AccountId)).ReturnsAsync(account); // Act await _sut.Handle(command); // Assert var updatedLegalEntities = account.LegalEntities.Where( e => e.HashedLegalEntityId == command.HashedLegalEntityId && e.VrfCaseStatus != "Completed").ToList(); updatedLegalEntities.Should().HaveCount(2); foreach (var legalEntity in updatedLegalEntities) { legalEntity.VrfCaseId.Should().Be(command.CaseId); legalEntity.VrfCaseStatus.Should().Be(command.Status); legalEntity.VrfCaseStatusLastUpdatedDateTime.Should().Be(command.LastUpdatedDate); } _mockDomainRepository.Verify(m => m.Save(account), Times.Once); _mockDomainRepository.VerifyAll(); }