4
\$\begingroup\$

In our project we use domain-driven design and our customer aggregate root is large. The unit tests for the aggregate root itself are simple (~50 or so tests), but I am struggling with the repository tests. Other aggregate roots in our system are not this large (number of fields), and the database table for this data is not normalized (around ~40-70 columns). The design of this table was done about 10 years ago and normalizing this table is not feasible right now.

Normally I would add a test for each separate field because I find that it provides better feedback when a bug occurs, code has changed, and the tests fail. It's really easy to find that test and fix that specific bug. In this case I have avoided that because of the number of fields and amount of setup code, and grouped the assertions together by the operation or scenario moreso than a unit.

What is not shown in this test either is that for Add there are still ~20-30 other columns in this table that must have default values, but I have chosen to not verify those due to test value assuming the database will default them. I'm not sure I am okay with that outcome because the database is not normalized. If it were, where some columns were on join tables or separate tables it would not be an issue at all.

How have you dealt with unit testing large aggregate roots like this? I thought about separating the factory for constructing Customer and unit testing that with tests for each field, and creating another factory or builder with the same intent for constructing Data.Customer. If I take that approach, the unit tests for the repository are straight forward given that they become just identity based verifications like context.Verify(...Add...) and ```builder.AddCustomerInfo(...)`.

Some of the code has ... values that replace the actual values in our test code.

Repository

namespace OurProduct.Core.Infrastructure
{
    using System;
    using System.Collections.Generic;
    using System.Data.Entity;
    using System.Linq;
    using Business;
    using Data.Infrastructure;

    /// <inheritdoc cref="ICustomerRepository" />
    public class CustomerRepository : ICustomerRepository
    {
        private readonly IDateTime time;

        /// <summary>
        /// Initializes a new instance of the <see cref="CustomerRepository"/> class.
        /// </summary>
        /// <param name="database">The database context that will be used to access data.</param>
        /// <param name="time">A time object that will be used to get system clock info.</param>
        public CustomerRepository(IDataContext database, IDateTime time)
        {
            this.time = time;

            Database = database;
            Query    = Database.Customers
                               .Include(p => p.Branch)
                               .Include(p => p.Branch.Bank)
                               .Include(p => p.CreditClassification)
                               .Include(p => p.LoanOfficer)
                               .Include(p => p.CustomerStatus)
                               .Include(p => p.CustomerType);
        }

        /// <summary>
        /// Gets the database context that will be used to access data.
        /// </summary>
        public IDataContext Database
        {
            get;
        }

        /// <summary>
        /// Gets the queryable expression that will be used to load customers.
        /// </summary>
        public IQueryable<Data.Customer> Query
        {
            get;
        }

        /// <inheritdoc />
        public void Add(Customer customer)
        {
            var entity = new Data.Customer
                         {
                             CustomerId         = customer.Id,
                             CustomerNumber     = customer.Number,
                             CustomerFirstName  = customer.FirstName,
                             CustomerMiddleName = customer.MiddleName,
                             CustomerLastName   = customer.LastName,
                             CustomerName       = customer.FullName,
                             BusinessName       = customer.BusinessName, 
                             TaxId              = customer.TaxId,
                             PhoneFax           = customer.ContactInfo.FaxNumber,
                             PhoneHome          = customer.ContactInfo.HomeNumber,
                             PhoneMobile        = customer.ContactInfo.MobileNumber,
                             PhoneWork          = customer.ContactInfo.WorkNumber, 
                             Email              = customer.ContactInfo.Email,
                             Address1           = customer.ContactInfo.Address.Address1,
                             Address2           = customer.ContactInfo.Address.Address2,
                             City               = customer.ContactInfo.Address.City,
                             State              = customer.ContactInfo.Address.State,
                             ZipCode            = customer.ContactInfo.Address.Zip,
                             ...
                             ModifiedDate       = time.Now,
                             BankId             = ((ICustomer) customer).BankId,
                             CustomerBranchId   = ((ICustomer) customer).BranchId,
                             CustomerTypeId     = ((ICustomer) customer).TypeId,
                             CustomerStatusId   = ((ICustomer) customer).StatusId,
                             ClassificationId   = ((ICustomer) customer).RiskId,
                             CustomerOfficerId  = ((ICustomer) customer).OfficerId, 
                         };

            Database.Add(entity);
        }

        /// <inheritdoc />
        public IEnumerable<Customer> Find(IEnumerable<string> searchTerms, int? skip = 0, int? take = 25)
        {
            throw new NotImplementedException(@"Implement using full-text search in SQL using an indexed view.");
        }

        /// <inheritdoc />
        public Customer FindById(Guid id)
        {
            Data.Customer entity;

            try
            {
                entity = Query.Single(p => p.CustomerId == id);
            }
            catch (InvalidOperationException ex)
            {
                throw new ArgumentException(@"Identity does not exist", nameof(id), ex);
            }

            Customer customer = CustomerFactory.Create(entity);

            return customer;
        }

        /// <inheritdoc />
        public void Update(Customer customer)
        {
            var entity = Database.Find<Data.Customer>(customer.Id);

            if (entity == null)
            {
                throw new ArgumentException(@"The specified customer does not exist in the repository.", 
                                            nameof(customer));
            }

            entity.CustomerFirstName  = customer.FirstName;
            entity.CustomerMiddleName = customer.MiddleName;
            entity.CustomerLastName   = customer.LastName;
            entity.CustomerNumber     = customer.FullName;
            entity.BusinessName       = customer.BusinessName;
            entity.TaxId              = customer.TaxId;
            entity.PhoneFax           = customer.ContactInfo.FaxNumber;
            entity.PhoneHome          = customer.ContactInfo.HomeNumber;
            entity.PhoneMobile        = customer.ContactInfo.MobileNumber;
            entity.PhoneWork          = customer.ContactInfo.WorkNumber;
            entity.Email              = customer.ContactInfo.Email;
            entity.Address1           = customer.ContactInfo.Address.Address1;
            entity.Address2           = customer.ContactInfo.Address.Address2;
            entity.City               = customer.ContactInfo.Address.City;
            entity.State              = customer.ContactInfo.Address.State;
            entity.ZipCode            = customer.ContactInfo.Address.Zip;
            entity.ModifiedDate       = time.Now;
            entity.BankId             = ((ICustomer) customer).BankId;
            entity.CustomerBranchId   = ((ICustomer) customer).BranchId;
            entity.CustomerTypeId     = ((ICustomer) customer).TypeId;
            entity.CustomerStatusId   = ((ICustomer) customer).StatusId;
            entity.ClassificationId   = ((ICustomer) customer).RiskId;
            entity.CustomerOfficerId  = ((ICustomer) customer).OfficerId;
        }

        /// <summary>
        /// Factory class that creates new <see cref="Customer"/> instances.
        /// </summary>
        private static class CustomerFactory
        {
            /// <summary>
            /// Creates a new customer from the specified data entity.
            /// </summary>
            /// <param name="entity">The <see cref="Data.Customer"/> data entity containing the data that will be used to create a new customer.</param>
            /// <returns>Returns a new <see cref="Customer"/> instance.</returns>
            public static Customer Create(Data.Customer entity)
            {
                var bank    = new Bank(entity.Branch.Bank.BankId, entity.Branch.Bank.BankName);
                var region  = new Region(entity.Branch.RegionId, entity.Branch.Region.RegionName);
                var branch  = new Branch(entity.Branch.BranchId, entity.Branch.BranchName, bank, region);
                var risk    = new CustomerRisk(entity.CreditClassification.ClassificationId, entity.CreditClassification.ClassificationName);
                var officer = new Officer(entity.LoanOfficer.OfficerId, entity.LoanOfficer.OfficerName, entity.LoanOfficer.OfficerTitle);
                var status  = new CustomerStatus(entity.CustomerStatus.CustomerStatusId, entity.CustomerStatus.CustomerStatusDescription, entity.CustomerStatus.IsActive);
                var type    = new CustomerType(entity.CustomerType.CustomerTypeId, entity.CustomerType.CustomerTypeDescription);

                var customer = new Customer(entity.CustomerId,
                                            entity.CustomerName,
                                            entity.CustomerNumber,
                                            type,
                                            branch,
                                            officer,
                                            status,
                                            risk)
                               {
                                   FirstName    = entity.CustomerFirstName,
                                   MiddleName   = entity.CustomerMiddleName,
                                   LastName     = entity.CustomerLastName,
                                   BusinessName = entity.BusinessName,
                                   TaxId        = entity.TaxId
                               };

                customer.ContactInfo.Email            = entity.Email;
                customer.ContactInfo.Address.Address1 = entity.Address1;
                customer.ContactInfo.Address.Address2 = entity.Address2;
                customer.ContactInfo.Address.City     = entity.City;
                customer.ContactInfo.Address.State    = entity.State;
                customer.ContactInfo.Address.Zip      = entity.ZipCode;
                customer.ContactInfo.FaxNumber        = entity.PhoneFax;
                customer.ContactInfo.HomeNumber       = entity.PhoneHome;
                customer.ContactInfo.WorkNumber       = entity.PhoneWork;
                customer.ContactInfo.MobileNumber     = entity.PhoneMobile;

                return customer;
            }
        }
    }
}

Unit Tests

namespace OurProduct.Core.Tests
{
    using System;
    using System.Linq;
    using Business;
    using Data;
    using Data.Infrastructure;
    using Infrastructure;
    using Microsoft.VisualStudio.TestTools.UnitTesting;
    using Moq;
    using Bank = Business.Bank;
    using Branch = Business.Branch;
    using Customer = Business.Customer;
    using CustomerStatus = Business.CustomerStatus;
    using CustomerType = Business.CustomerType;
    using Region = Business.Region;

    [TestClass]
    public class CustomerRepositoryTests
    {
        [TestMethod]
        public void Add_CustomerIsNotNull_AddsCustomerToContext()
        {
            Guid customerId = Guid.Parse("{341E4B1C-EBA3-4587-B7A6-3C9641C39191}");
            Guid bankId     = Guid.Parse("{BE3590B5-F570-44B6-BAF1-86597CC404A6}");
            Guid branchId   = Guid.Parse("{2CA73ABE-0EFC-4C8F-9BD9-8D1F4E0E74DE}");
            Guid regionId   = Guid.Parse("{3C4D243F-47AF-4224-B805-55E2D8EB0DE0}");
            Guid riskId     = Guid.Parse("{DC0A5EF1-2376-4FA9-B09A-69CD1B28CEF5}");
            Guid officerId  = Guid.Parse("{8F02B1F8-1551-4124-B9B7-492FD18830DD}");
            Guid statusId   = Guid.Parse("{C53BE489-DDC5-4178-BA83-3422A58CC1D8}");
            Guid typeId     = Guid.Parse("{F2118364-64FB-44DC-8AC2-19223447A125}");

            var bank     = new Bank(bankId, "...");
            var region   = new Region(regionId, "West US");
            var branch   = new Branch(branchId, "...", bank, region);
            var risk     = new CustomerRisk(riskId, "Low Risk");
            var officer  = new Officer(officerId, "Bob Smith", "Senior Lender");
            var status   = new CustomerStatus(statusId, "Active", true);
            var type     = new CustomerType(typeId, "Consumer");

            var customer = new Customer(customerId,
                                        "John J Doe",
                                        "CC001",
                                        type,
                                        branch,
                                        officer,
                                        status,
                                        risk)
                           {
                               FirstName    = "John",
                               MiddleName   = "J",
                               LastName     = "Doe",
                               BusinessName = "Local Shipping, Inc.",
                               TaxId        = "123456789"
                           };

            customer.ContactInfo.Email            = "jjdoe@....net";
            customer.ContactInfo.Address.Address1 = "...";
            customer.ContactInfo.Address.Address2 = "";
            customer.ContactInfo.Address.City     = "...";
            customer.ContactInfo.Address.State    = "..";
            customer.ContactInfo.Address.Zip      = "...";
            customer.ContactInfo.FaxNumber        = "123 456 7890";
            customer.ContactInfo.HomeNumber       = "123 456 7891";
            customer.ContactInfo.WorkNumber       = "123 456 7892";
            customer.ContactInfo.MobileNumber     = "123 456 7893";

            var context    = new Mock<IDataContext>();
            var time       = new Mock<IDateTime>();
            var repository = new CustomerRepository(context.Object, time.Object);

            repository.Add(customer);

            context.Verify(p => p.Add(It.Is<Data.Customer>(q => q.CustomerId == customer.Id)), Times.Once);
            context.Verify(p => p.Add(It.Is<Data.Customer>(q => q.BankId == ((ICustomer)customer).BankId)), Times.Once);
            context.Verify(p => p.Add(It.Is<Data.Customer>(q => q.CustomerBranchId == ((ICustomer)customer).BranchId)), Times.Once);
            context.Verify(p => p.Add(It.Is<Data.Customer>(q => q.CustomerTypeId == ((ICustomer)customer).TypeId)), Times.Once);
            context.Verify(p => p.Add(It.Is<Data.Customer>(q => q.CustomerStatusId == ((ICustomer)customer).StatusId)), Times.Once);
            context.Verify(p => p.Add(It.Is<Data.Customer>(q => q.ClassificationId == ((ICustomer)customer).RiskId)), Times.Once);
            context.Verify(p => p.Add(It.Is<Data.Customer>(q => q.CustomerNumber == customer.Number)), Times.Once);
            context.Verify(p => p.Add(It.Is<Data.Customer>(q => q.CustomerName == customer.FullName)), Times.Once);
            context.Verify(p => p.Add(It.Is<Data.Customer>(q => q.CustomerFirstName == customer.FirstName)), Times.Once);
            context.Verify(p => p.Add(It.Is<Data.Customer>(q => q.CustomerMiddleName == customer.MiddleName)), Times.Once);
            context.Verify(p => p.Add(It.Is<Data.Customer>(q => q.CustomerLastName == customer.LastName)), Times.Once);
            context.Verify(p => p.Add(It.Is<Data.Customer>(q => q.BusinessName == customer.BusinessName)), Times.Once);
            context.Verify(p => p.Add(It.Is<Data.Customer>(q => q.TaxId == customer.TaxId)), Times.Once);
            context.Verify(p => p.Add(It.Is<Data.Customer>(q => q.Email == customer.ContactInfo.Email)), Times.Once);
            context.Verify(p => p.Add(It.Is<Data.Customer>(q => q.Address1 == customer.ContactInfo.Address.Address1)), Times.Once);
            context.Verify(p => p.Add(It.Is<Data.Customer>(q => q.Address2 == customer.ContactInfo.Address.Address2)), Times.Once);
            context.Verify(p => p.Add(It.Is<Data.Customer>(q => q.City == customer.ContactInfo.Address.City)), Times.Once);
            context.Verify(p => p.Add(It.Is<Data.Customer>(q => q.State == customer.ContactInfo.Address.State)), Times.Once);
            context.Verify(p => p.Add(It.Is<Data.Customer>(q => q.ZipCode == customer.ContactInfo.Address.Zip)), Times.Once);
            context.Verify(p => p.Add(It.Is<Data.Customer>(q => q.PhoneHome == customer.ContactInfo.HomeNumber)), Times.Once);
            context.Verify(p => p.Add(It.Is<Data.Customer>(q => q.PhoneFax == customer.ContactInfo.FaxNumber)), Times.Once);
            context.Verify(p => p.Add(It.Is<Data.Customer>(q => q.PhoneWork == customer.ContactInfo.WorkNumber)), Times.Once);
            context.Verify(p => p.Add(It.Is<Data.Customer>(q => q.PhoneMobile == customer.ContactInfo.MobileNumber)), Times.Once);
            ...
            context.Verify(p => p.Add(It.Is<Data.Customer>(q => q.ModifiedDate == time.Object.Now)), Times.Once);
        }

        [TestMethod]
        public void FindById_IdentityExists_ReturnsCustomer()
        {
            var entity = new Data.Customer
            {
                CustomerId           = Guid.Parse("{E9B6F735-7984-4746-92CF-3EEA9E742209}"),
                CustomerNumber       = "CC001",
                CustomerName         = "John J Smith",
                CustomerFirstName    = "John",
                CustomerMiddleName   = "J",
                CustomerLastName     = "Smith",
                Email                = "johnjsmith@....net",
                Address1             = "...",
                Address2             = "",
                City                 = "...",
                State                = "..",
                ZipCode              = "...", 
                PhoneFax             = "123 456 7890",
                PhoneWork            = "123 456 7891",
                PhoneMobile          = "123 456 7892",
                PhoneHome            = "123 456 7893", 
                BusinessName         = "Local Shipping, Inc.",
                TaxId                = "123456789",
                CreditClassification = new CreditClassification
                                       {
                                           ClassificationId   = Guid.Parse("{C31C1C79-5181-4D06-86EA-7AEDECDB8A01}"),
                                           ClassificationName = "Low Risk"
                                       },
                CustomerType         = new Data.CustomerType
                                       {
                                           CustomerTypeId          = Guid.Parse("{3C1236F0-145D-4258-AC54-3EF1331B0B66}"),
                                           CustomerTypeDescription = "Consumer"
                                       },
                CustomerStatus       = new Data.CustomerStatus
                                       {
                                           CustomerStatusId          = Guid.Parse("{0567B8ED-F947-4BF5-936F-630AB3677095}"),
                                           CustomerStatusDescription = "Active"
                                       },
                LoanOfficer          = new LoanOfficer
                                       {
                                           OfficerId    = Guid.Parse("{58DEB0AD-3830-437E-B22D-04376AB5296C}"),
                                           OfficerName  = "Bob Doe",
                                           OfficerTitle = "Senior Lender"
                                       },
                Branch               = new Data.Branch
                                       {
                                           BranchId   = Guid.Parse("{003ED79C-938E-4DB8-9A3C-2AA35E64DAEB}"),
                                           BranchName = "...",
                                           Region     = new Data.Region
                                                        {
                                                            RegionId   = Guid.Parse("{F2992F17-B94A-4CE5-83D1-B3E6A2AC31A7}"),
                                                            RegionName = "West US"
                                                        },
                                           Bank       = new Data.Bank
                                                        {
                                                            BankId   = Guid.Parse("{11D291A4-3F93-443B-93C8-88621F25891A}"),
                                                            BankName = "..."
                                                        }
                                       }
            };

            var context = new Mock<IDataContext>();

            context.Setup(p => p.Customers).Returns(new[] {entity}.AsQueryable);

            var repository = new CustomerRepository(context.Object, Mock.Of<IDateTime>());

            Customer customer = repository.FindById(entity.CustomerId);

            Assert.AreEqual("{e9b6f735-7984-4746-92cf-3eea9e742209}", customer.Id.ToString("B"));
            Assert.AreEqual("{11d291a4-3f93-443b-93c8-88621f25891a}", ((ICustomer)customer).BankId.ToString("B"));
            Assert.AreEqual("{003ed79c-938e-4db8-9a3c-2aa35e64daeb}", ((ICustomer)customer).BranchId.ToString("B"));
            Assert.AreEqual("{3c1236f0-145d-4258-ac54-3ef1331b0b66}", ((ICustomer)customer).TypeId.ToString("B"));
            Assert.AreEqual("{0567b8ed-f947-4bf5-936f-630ab3677095}", ((ICustomer)customer).StatusId.ToString("B"));
            Assert.AreEqual("{c31c1c79-5181-4d06-86ea-7aedecdb8a01}", ((ICustomer)customer).RiskId.ToString("B"));
            Assert.AreEqual("CC001", customer.Number);
            Assert.AreEqual("John J Smith", customer.FullName);
            Assert.AreEqual("John", customer.FirstName);
            Assert.AreEqual("J", customer.MiddleName);
            Assert.AreEqual("Smith", customer.LastName);
            Assert.AreEqual("johnjsmith@....net", customer.ContactInfo.Email);
            Assert.AreEqual("...", customer.ContactInfo.Address.Address1);
            Assert.AreEqual("", customer.ContactInfo.Address.Address2);
            Assert.AreEqual("...", customer.ContactInfo.Address.City);
            Assert.AreEqual("...", customer.ContactInfo.Address.State);
            Assert.AreEqual("81003", customer.ContactInfo.Address.Zip);
            Assert.AreEqual("123 456 7890", customer.ContactInfo.FaxNumber);
            Assert.AreEqual("123 456 7893", customer.ContactInfo.HomeNumber);
            Assert.AreEqual("123 456 7892", customer.ContactInfo.MobileNumber);
            Assert.AreEqual("123 456 7891", customer.ContactInfo.WorkNumber);
            Assert.AreEqual("Low Risk", customer.Risk);
            Assert.AreEqual("Consumer", customer.Type);
            Assert.AreEqual("Active", customer.Status);
            Assert.AreEqual("...", customer.Branch);
            Assert.AreEqual("...", customer.Bank);
            Assert.AreEqual("Bob Doe", customer.Officer);
            Assert.AreEqual("Local Shipping, Inc.", customer.BusinessName);
            Assert.AreEqual("123456789", customer.TaxId);
        }

        [TestMethod]
        public void FindById_IdentityDoesNotExist_ThrowsException()
        {
            var repository = new CustomerRepository(Mock.Of<IDataContext>(), Mock.Of<IDateTime>());

            Assert.ThrowsException<ArgumentException>(() => repository.FindById(Guid.Empty));
        }

        [TestMethod]
        public void Update_IdentityDoesNotExist_ThrowsException()
        {
            var customer = new Customer(Guid.Empty, 
                                        "John J Doe",
                                        "CC001",
                                        Mock.Of<ICustomerType>(),
                                        Mock.Of<IBranch>(),
                                        Mock.Of<IOfficer>(),
                                        Mock.Of<ICustomerStatus>(),
                                        Mock.Of<ICustomerRisk>());

            var repository = new CustomerRepository(Mock.Of<IDataContext>(), Mock.Of<IDateTime>());

            Assert.ThrowsException<ArgumentException>(() => repository.Update(customer));
        }

        [TestMethod]
        public void Update_IdentityExists_UpdatesCustomer()
        {
            Guid customerId = Guid.Parse("{341E4B1C-EBA3-4587-B7A6-3C9641C39191}");
            Guid bankId     = Guid.Parse("{BE3590B5-F570-44B6-BAF1-86597CC404A6}");
            Guid branchId   = Guid.Parse("{2CA73ABE-0EFC-4C8F-9BD9-8D1F4E0E74DE}");
            Guid regionId   = Guid.Parse("{3C4D243F-47AF-4224-B805-55E2D8EB0DE0}");
            Guid riskId     = Guid.Parse("{DC0A5EF1-2376-4FA9-B09A-69CD1B28CEF5}");
            Guid officerId  = Guid.Parse("{8F02B1F8-1551-4124-B9B7-492FD18830DD}");
            Guid statusId   = Guid.Parse("{C53BE489-DDC5-4178-BA83-3422A58CC1D8}");
            Guid typeId     = Guid.Parse("{F2118364-64FB-44DC-8AC2-19223447A125}");

            var bank     = new Bank(bankId, "...");
            var region   = new Region(regionId, "West US");
            var branch   = new Branch(branchId, "...", bank, region);
            var risk     = new CustomerRisk(riskId, "Low Risk");
            var officer  = new Officer(officerId, "Bob Smith", "Senior Lender");
            var status   = new CustomerStatus(statusId, "Active", true);
            var type     = new CustomerType(typeId, "Consumer");

            var customer = new Customer(customerId,
                                        "John J Doe",
                                        "CC001",
                                        type,
                                        branch,
                                        officer,
                                        status,
                                        risk)
                           {
                               FirstName    = "John",
                               MiddleName   = "J",
                               LastName     = "Doe",
                               BusinessName = "Local Shipping, Inc.",
                               TaxId        = "123456789"
                           };

            customer.ContactInfo.Email            = "jjdoe@....net";
            customer.ContactInfo.Address.Address1 = "...";
            customer.ContactInfo.Address.Address2 = "";
            customer.ContactInfo.Address.City     = "...";
            customer.ContactInfo.Address.State    = "...";
            customer.ContactInfo.Address.Zip      = "...";
            customer.ContactInfo.FaxNumber        = "123 456 7890";
            customer.ContactInfo.HomeNumber       = "123 456 7891";
            customer.ContactInfo.WorkNumber       = "123 456 7892";
            customer.ContactInfo.MobileNumber     = "123 456 7893";

            var context = new Mock<IDataContext>();
            var entity  = new Data.Customer {CustomerId = customer.Id};

            context.Setup(p => p.Find<Data.Customer>(It.Is<Guid>(q => q == customer.Id)))
                   .Returns(entity);

            var repository = new CustomerRepository(context.Object, Mock.Of<IDateTime>());

            repository.Update(customer);

            Assert.AreEqual(customer.FirstName, entity.CustomerFirstName);
            Assert.AreEqual(customer.MiddleName, entity.CustomerMiddleName);
            Assert.AreEqual(customer.LastName, entity.CustomerLastName);
            Assert.AreEqual(customer.FullName, entity.CustomerNumber);
            Assert.AreEqual(customer.BusinessName, entity.BusinessName);
            Assert.AreEqual(customer.TaxId, entity.TaxId);
            Assert.AreEqual(customer.ContactInfo.FaxNumber, entity.PhoneFax);
            Assert.AreEqual(customer.ContactInfo.HomeNumber, entity.PhoneHome);
            Assert.AreEqual(customer.ContactInfo.MobileNumber, entity.PhoneMobile);
            Assert.AreEqual(customer.ContactInfo.WorkNumber, entity.PhoneWork);
            Assert.AreEqual(customer.ContactInfo.Email, entity.Email);
            Assert.AreEqual(customer.ContactInfo.Address.Address1, entity.Address1);
            Assert.AreEqual(customer.ContactInfo.Address.Address2, entity.Address2);
            Assert.AreEqual(customer.ContactInfo.Address.City, entity.City);
            Assert.AreEqual(customer.ContactInfo.Address.State, entity.State);
            Assert.AreEqual(customer.ContactInfo.Address.Zip, entity.ZipCode);
            Assert.AreEqual(bankId, entity.BankId);
            Assert.AreEqual(branchId, entity.CustomerBranchId);
            Assert.AreEqual(typeId, entity.CustomerTypeId);
            Assert.AreEqual(statusId, entity.CustomerStatusId);
            Assert.AreEqual(riskId, entity.ClassificationId);
            Assert.AreEqual(officerId, entity.CustomerOfficerId);
            //Assert.AreEqual(time.Now, entity.ModifiedDate);
        }
    }
}
```
\$\endgroup\$
1
  • 1
    \$\begingroup\$ Have you considered creating a mapper between Data.Customer and Business.Customer? Then tests to assert on mapping would be easier and repository tests would focus on adding, retrieving, querying... \$\endgroup\$ Jul 3 '20 at 21:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.