Exemple #1
0
        public async Task Update(AccountModel account)
        {
            var existing = await _dbContext.Accounts.Where(a => a.Id == account.Id).ToListAsync();

            foreach (Models.Account item in existing)
            {
                if (!account.LegalEntityModels.Any(i => i.AccountLegalEntityId == item.AccountLegalEntityId))
                {
                    _dbContext.Remove(item);
                }
            }

            foreach (Models.Account item in account.Map())
            {
                var legalEntity = existing.SingleOrDefault(a => a.AccountLegalEntityId == item.AccountLegalEntityId);
                if (legalEntity == null)
                {
                    _dbContext.Add(item);
                }
                else
                {
                    legalEntity.LegalEntityName          = item.LegalEntityName;
                    legalEntity.HasSignedIncentivesTerms = item.HasSignedIncentivesTerms;
                    legalEntity.SignedAgreementVersion   = item.SignedAgreementVersion;
                    legalEntity.VrfCaseId     = item.VrfCaseId;
                    legalEntity.VrfCaseStatus = item.VrfCaseStatus;
                    legalEntity.VrfVendorId   = item.VrfVendorId;
                    legalEntity.VrfCaseStatusLastUpdatedDateTime = item.VrfCaseStatusLastUpdatedDateTime;
                    legalEntity.HashedLegalEntityId = item.HashedLegalEntityId;
                }
            }
        }
Exemple #2
0
        public async Task Then_the_expected_account_is_returned_if_it_exists()
        {
            // Arrange
            var testAccount = _fixture.Create <Models.Account>();

            _dbContext.Add(testAccount);
            _dbContext.SaveChanges();

            // Act
            var account = await _sut.Find(testAccount.Id);

            // Assert
            account.Should().NotBeNull();
            account.Id.Should().Be(testAccount.Id);
            var legalEntity = account.LegalEntityModels.Single();

            legalEntity.Id.Should().Be(testAccount.LegalEntityId);
            legalEntity.Name.Should().Be(testAccount.LegalEntityName);
            legalEntity.AccountLegalEntityId.Should().Be(testAccount.AccountLegalEntityId);
            legalEntity.HashedLegalEntityId.Should().Be(testAccount.HashedLegalEntityId);
            legalEntity.VrfCaseStatusLastUpdatedDateTime.Should().Be(testAccount.VrfCaseStatusLastUpdatedDateTime);
            legalEntity.VrfCaseStatus.Should().Be(testAccount.VrfCaseStatus);
            legalEntity.VrfVendorId.Should().Be(testAccount.VrfVendorId);
            legalEntity.VrfCaseId.Should().Be(testAccount.VrfCaseId);
        }
        public async Task Then_the_account_is_updated_if_it_already_exists()
        {
            // Arrange
            var testAccount = _fixture.Create <Models.Account>();

            _dbContext.Add(_fixture.Create <Models.Account>());
            _dbContext.Add(testAccount);
            _dbContext.Add(_fixture.Create <Models.Account>());
            _dbContext.SaveChanges();
            var newName           = testAccount.LegalEntityName + "changed";
            var newHasSignedTerms = !testAccount.HasSignedIncentivesTerms;
            var newSignedVersion  = testAccount.SignedAgreementVersion + 1;

            var legalEntities = new List <LegalEntityModel>
            {
                new LegalEntityModel
                {
                    Id = testAccount.LegalEntityId,
                    AccountLegalEntityId = testAccount.AccountLegalEntityId,
                    Name = newName,
                    HasSignedAgreementTerms = newHasSignedTerms,
                    SignedAgreementVersion  = newSignedVersion
                }
            };

            var accountModel = new AccountModel {
                Id = testAccount.Id, LegalEntityModels = legalEntities
            };

            // Act
            await _sut.Update(accountModel);

            await _dbContext.SaveChangesAsync();

            // Assert
            var addedAccount = _dbContext.Accounts.Single(a => a.Id == testAccount.Id && a.AccountLegalEntityId == testAccount.AccountLegalEntityId);

            addedAccount.LegalEntityId.Should().Be(testAccount.LegalEntityId);
            addedAccount.LegalEntityName.Should().Be(newName);
            addedAccount.HasSignedIncentivesTerms.Should().Be(newHasSignedTerms);
            addedAccount.SignedAgreementVersion.Should().Be(newSignedVersion);
            addedAccount.VrfCaseId.Should().Be(testAccount.VrfCaseId);
            addedAccount.VrfCaseStatus.Should().Be(testAccount.VrfCaseStatus);
            addedAccount.VrfVendorId.Should().Be(testAccount.VrfVendorId);
            addedAccount.VrfCaseStatusLastUpdatedDateTime.Should().Be(testAccount.VrfCaseStatusLastUpdatedDateTime);
            addedAccount.HashedLegalEntityId.Should().Be(testAccount.HashedLegalEntityId);
        }