示例#1
0
        /// <summary>
        /// Initialize and set properties to the UpdateAgent object (this.UpdateAgent property).
        /// </summary>
        /// <returns></returns>
        private bool GetAgentUpdatedFields()
        {
            bool    result             = false;
            int     resultCount        = 0;
            decimal updateAgentCommish = 0.0m;

            if (string.IsNullOrWhiteSpace(AgentCommissionTextbox.Text.Trim()))
            {
                DisplayStatusMessage("To Update, enter a new Commission Rate. Example 4% would be: 0.04");
            }
            if (Decimal.TryParse(AgentCommissionTextbox.Text.Trim(), out updateAgentCommish))
            {
                if (updateAgentCommish > 0.00m && updateAgentCommish < 1.0m)
                {
                    ReceivedAgent.CommissionPercent = updateAgentCommish;
                    resultCount++;
                    DisplayStatusMessage("Agent Commission updated. Click Save to close or File -> Exit to quit.");
                }
                else
                {
                    DisplayStatusMessage("Enter a valid Commission Rate between 1 and 99 percent.");
                }
            }
            else
            {
                DisplayStatusMessage("Enter a valid Commission Rate between 1 and 99 percent.");
            }

            if (SelectedReco != null)
            {
                ReceivedAgent.RealEstateCompany = SelectedReco;
                ReceivedAgent.CompanyID         = SelectedReco.CompanyID;
                resultCount++;
            }
            else
            {
                string recoName = AgentReCompanyTextbox.Text.Trim();
                if (string.IsNullOrWhiteSpace(recoName) != true)
                {
                    var inferredReco = (from re in ((App)Application.Current)._recosCollection
                                        where re.CompanyName == recoName
                                        select re).FirstOrDefault();
                    if (inferredReco != null && inferredReco.CompanyName != ReceivedAgent.RealEstateCompany.CompanyName)
                    {
                        ReceivedRECo = inferredReco;
                        ReceivedAgent.RealEstateCompany = ReceivedRECo;
                        resultCount++;
                    }
                }
            }

            DisplayStatusMessage("Agent assigned to RE Company.");

            if (resultCount > 0)
            {
                result = true;
            }

            return(result);
        }
        private void LoadDataUpdateHomeAsSold(int homeID)
        {
            HomeSale hfsHomesale = ((App)Application.Current)._homeSalesCollection.Where(
                hs =>
                hs.HomeID == homeID &&
                hs.MarketDate != null &&
                hs.SoldDate == null).FirstOrDefault();

            Home hfsHome = ((App)Application.Current)._homesCollection.Where(h => h.HomeID == homeID).FirstOrDefault();

            if (hfsHome != null && hfsHomesale != null)
            {
                Person hfsAgent = new Person();
                hfsAgent = ((App)Application.Current)._peopleCollection.Where(p => p.PersonID == hfsHomesale.AgentID).FirstOrDefault();

                if (hfsAgent != null && hfsAgent.Agent.CompanyID != null)
                {
                    RealEstateCompany hfsReco = new RealEstateCompany();
                    hfsReco = ((App)Application.Current)._recosCollection.Where(r => r.CompanyID == hfsAgent.Agent.CompanyID).FirstOrDefault();
                    if (hfsReco != null)
                    {
                        UpdatePerson   = hfsAgent;
                        UpdateAgent    = hfsAgent.Agent;
                        UpdateHome     = hfsHome;
                        UpdateHomeSale = hfsHomesale;
                        UpdateReco     = hfsReco;
                    }
                }
            }
        }
示例#3
0
        private void ExistingRECosCombobox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            DisplayStatusMessage("Real Estate Co selection changed!");
            SelectedReco = new RealEstateCompany();
            SelectedReco = (sender as ComboBox).SelectedItem as RealEstateCompany;

            RealEstateCompany tempRECo = (from re in ((App)Application.Current)._recosCollection
                                          where SelectedReco.CompanyID == re.CompanyID
                                          select re).FirstOrDefault();

            Agent tempAgent = (from hs in ((App)Application.Current)._homeSalesCollection
                               from a in ((App)Application.Current)._peopleCollection
                               where hs.AgentID == tempRECo.CompanyID &&
                               a.PersonID == hs.AgentID
                               select a.Agent).FirstOrDefault();

            if (SelectedReco != null && tempRECo != null && tempAgent != null)
            {
                ReceivedAgent                   = tempAgent;
                ReceivedAgent.CompanyID         = tempRECo.CompanyID;
                ReceivedAgent.RealEstateCompany = tempRECo;
                SelectedReco = tempRECo;
                AgentReCompanyTextbox.Text = tempRECo.CompanyName;
                DisplayStatusMessage("Loaded the selected RE Company.");
            }
            else
            {
                DisplayStatusMessage("Could not find RE Company info.");
            }
        }
示例#4
0
        /// <summary>
        /// IN TEST. Heavily refactored to enable adding Agent to existing Person for Add HFS scenario.
        /// Load Agent Details with received Agent properties. Also load Agent combobox and realestateco combobox.
        /// </summary>
        private void LoadAgentPanel()
        {
            ReceivedPerson = ((App)Application.Current)._peopleCollection.Where(p => p.PersonID == ReceivedPersonID).FirstOrDefault();

            if (ReceivedPerson != null)
            {
                ReceivedAgent = ReceivedPerson.Agent;

                var tempRECo      = new RealEstateCompany();
                var tempHomesales = new List <HomeSale>();

                if (ReceivedAgent != null)
                {
                    tempRECo      = ((App)Application.Current)._recosCollection.Where(re => re.CompanyID == ReceivedAgent.CompanyID).FirstOrDefault();
                    tempHomesales = ((App)Application.Current)._homeSalesCollection.Where(hs => hs.AgentID == ReceivedAgent.AgentID).ToList();

                    ReceivedAgent.Person            = ReceivedPerson;
                    ReceivedAgent.RealEstateCompany = tempRECo;
                    ReceivedAgent.HomeSales         = tempHomesales;

                    if (ReceivedAgent.CompanyID == null)
                    {
                        AgentReCompanyTextbox.Text = "Agent no longer active";
                    }
                    else
                    {
                        AgentReCompanyTextbox.Text       = tempRECo.CompanyName.ToString();
                        AgentReCompanyTextbox.IsReadOnly = true;
                    }

                    AgentCommissionTextbox.Text      = ReceivedAgent.CommissionPercent.ToString();
                    AgentCommissionTextbox.IsEnabled = true;
                    DisableBuyerDetailsControls();
                    DisableOwnerDetailsControls();
                    ExistingAgentsCombobox.IsEnabled = false;
                    EnableEditingPersonBasicInformation();
                    ExistingAgentsCombobox.IsEnabled = true;
                    LoadAgentsComboBox();
                }

                else if (ReceivedAgent == null)
                {
                    AgentReCompanyTextbox.IsReadOnly = true;
                    AgentCommissionTextbox.IsEnabled = true;
                    DisableBuyerDetailsControls();
                    DisableOwnerDetailsControls();
                    ExistingAgentsCombobox.IsEnabled = false; //  user is here to create new Agent props for existing person
                    DisableEditingPersonBasicInformation();   //  user is NOT here to change the Person
                    AgentCommissionTextbox.Text = string.Empty;
                    AgentReCompanyTextbox.Text  = string.Empty;
                }
                else
                {
                    var loadAgentPanelException = new Exception("Load Agent Panel method failed.");
                    throw loadAgentPanelException;
                }

                LoadRealEstateCoCombobox();
            }
        }
示例#5
0
        public void Add(RealEstateCompany realEstateCompany)
        {
            var re = _realEstateCompanies.SingleOrDefault(r => r.CompanyID == realEstateCompany.CompanyID);

            if (re == null)//the r here might give us trouble later
            {
                _realEstateCompanies.Add(realEstateCompany);
            }
        }
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            collectionMonitor = ((App)Application.Current)._recosCollection.collectionMonitor;
            collectionMonitor.Subscribe(this);
            LoadRECoComboBox();

            this.IsButtonClose = false;
            NewPerson          = new Person();

            switch (this.AddType)
            {
            case "Agent":
            {
                NewAgent     = new Agent();
                ExistingRECo = new RealEstateCompany();
                LoadAgentPanel();
                LoadRECoComboBox();
                DisableBuyerPanel();
                DisableOwnerPanel();
                break;
            }

            case "Owner":
            {
                NewOwner = new Owner();
                LoadOwnerPanel();
                DisableAgentPanel();
                DisableBuyerPanel();
                break;
            }

            case "Buyer":
            {
                NewBuyer = new Buyer();
                LoadBuyerPanel();
                DisableAgentPanel();
                DisableOwnerPanel();
                break;
            }

            default:
            {
                DisplayStatusMessage("No type included. Click Close to exit without saving.");
                AddOwnerButton.IsEnabled         = false;
                AddBuyerButton.IsEnabled         = false;
                AddAgentButton.IsEnabled         = false;
                UpdatePersonInfoButton.IsEnabled = false;
                CloseButton.IsEnabled            = true;
                this.IsButtonClose = true;
                break;
            }
            }
        }
示例#7
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            personCollectionMonitor = ((App)Application.Current)._peopleCollection.collectionMonitor;
            personCollectionMonitor.Subscribe(this);
            recoCollectionMonitor = ((App)Application.Current)._recosCollection.collectionMonitor;
            recoCollectionMonitor.Subscribe(this);

            ReceivedPerson = ((App)Application.Current)._peopleCollection.Get(ReceivedPersonID);
            if (ReceivedPerson == null)
            {
                DisplayStatusMessage("No person found. Exit this Window and try again.");
                return;
            }

            var ReceivedRECo = new RealEstateCompany();
            var SelectedRECo = new RealEstateCompany();


            LoadPersonInformation();
            logger = new Logger();
            string updateType = CalledByUpdateMenuType;

            switch (updateType)
            {
            case "AGENT":
            {
                LoadAgentPanel();
                break;
            }

            case "BUYER":
            {
                LoadBuyerPanel();
                break;
            }

            case "OWNER":
            {
                LoadOwnerPanel();
                break;
            }

            default:
            {
                break;
            }
            }

            IsButtonClose = false;
        }
        private void LoadDataPutHomeOnMarket(int homeID)
        {
            UpdateHome = ((App)Application.Current)._homesCollection.Where(h => h.HomeID == homeID).FirstOrDefault();

            if (UpdateHome == null)
            {
                //  theoretically a null UpdateHome will cause the Window to only allow user to close it
                UpdateHome = new Home();
            }

            UpdateAgent    = new Agent();
            UpdatePerson   = new Person();
            UpdateHomeSale = new HomeSale();
            UpdateReco     = new RealEstateCompany();
        }
        private void ExistingRECosCombobox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            var selectedRECo = (sender as ComboBox).SelectedItem as RealEstateCompany;

            ExistingRECo = ((App)Application.Current)._recosCollection.Where(re => re.CompanyID == selectedRECo.CompanyID).FirstOrDefault();
            if (ExistingRECo != null)
            {
                AgentRecoTextbox.Text = selectedRECo.CompanyName;
            }
            else
            {
                AgentRecoTextbox.Text = "Agent no longer active.";
            }

            NewAgent.CompanyID = ExistingRECo.CompanyID;
        }
        private void ListOfExistingAgentsCombobox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            Person selectedAgent = (sender as ComboBox).SelectedItem as Person;

            if (selectedAgent != null)
            {
                UpdatePerson = selectedAgent;

                if (selectedAgent.Agent != null)
                {
                    UpdateAgent           = selectedAgent.Agent;
                    AgentNameTextbox.Text = UpdatePerson.GetFirstAndLastName();

                    if (selectedAgent.Agent.CompanyID != null)
                    {
                        var agentsAffiliatedReco = (from re in ((App)Application.Current)._recosCollection
                                                    where selectedAgent.Agent.CompanyID == re.CompanyID
                                                    select re).FirstOrDefault();
                        UpdateAgentCompanyNameTextbox.Text = agentsAffiliatedReco.CompanyName;
                        UpdateReco = agentsAffiliatedReco;
                    }
                    else
                    {
                        UpdateAgentCompanyNameTextbox.Text = "Agent no longer active";
                    }

                    UpdateAgentCommissionTextbox.Text = UpdateAgent.CommissionPercent.ToString().Trim();
                }

                if (selectedAgent.Agent == null)
                {
                    AgentNameTextbox.IsReadOnly        = true;
                    AddNewAgentButton.IsEnabled        = true;
                    AddNewAgentButton.Visibility       = Visibility.Visible;
                    UpdateAgentCompanyNameTextbox.Text = "Click ADD NEW.";
                    UpdateAgentCommissionTextbox.Text  = "Click ADD NEW";
                }

                UpdateHomeSale.AgentID = UpdateAgent.AgentID;
            }
        }
        public void OneBigTest()
        {
            {
                #region LogicBrokerTests
                //  GetPerson(PersonID)
                {
                    var expectedPerson = new Person()
                    {
                        FirstName = "John",
                        LastName  = "Smith",
                        Email     = "*****@*****.**",
                        Phone     = "1112223333"
                    };

                    int    personID     = 1;
                    Person actualPerson = LogicBroker.GetPerson(personID);

                    bool areEqual = expectedPerson.Equals(actualPerson);
                    Assert.IsTrue(areEqual);
                }

                //  GetPerson(firstname, lastname)
                {
                    string firstName = "John";
                    string lastName  = "Smith";

                    var expectedPerson = new Person()
                    {
                        FirstName = firstName,
                        LastName  = lastName,
                        Email     = "*****@*****.**",
                        Phone     = "1112223333"
                    };

                    Person actualPerson = LogicBroker.GetPerson(firstName, lastName);

                    bool areEqual = expectedPerson.Equals(actualPerson);
                    Assert.IsTrue(areEqual);
                }

                //  GetHome(homeID)
                {
                    var address = "23 Oak St.";
                    var zip     = "955551111";

                    var expectedHome = new Home()
                    {
                        Address = address,
                        City    = "Johnsonville",
                        State   = "CA",
                        Zip     = zip
                    };

                    int  homeID     = 1;
                    Home actualHome = LogicBroker.GetHome(homeID);

                    bool areEqual = expectedHome.Equals(actualHome);
                    Assert.IsTrue(areEqual);
                }

                //  GetHome(address, zip)
                {
                    var address = "23 Oak St.";
                    var zip     = "955551111";

                    var expectedHome = new Home()
                    {
                        Address = address,
                        City    = "Johnsonville",
                        State   = "CA",
                        Zip     = zip
                    };

                    Home actualHome = LogicBroker.GetHome(address, zip);

                    bool areEqual = expectedHome.Equals(actualHome);
                    Assert.IsTrue(areEqual);
                }

                //  GetHomeSale(saleID)
                //  SOLD
                {
                    int homesaleID = 6;

                    var expectedHomeSale = new HomeSale()
                    {
                        SaleID     = homesaleID,
                        HomeID     = 3,
                        SoldDate   = new DateTime(2014, 06, 13),
                        AgentID    = 1,
                        SaleAmount = 550_000m,
                        BuyerID    = 5,
                        MarketDate = new DateTime(2014, 06, 01),
                        CompanyID  = 4
                    };

                    var actualHomeSale = LogicBroker.GetHomeSale(homesaleID);

                    bool areEqual = expectedHomeSale.Equals(actualHomeSale);
                    if (!areEqual)
                    {
                        var items = new List <HomeSale>()
                        {
                            expectedHomeSale, actualHomeSale
                        };

                        PrintObjects(items);
                    }

                    Assert.IsTrue(areEqual);
                }

                //  GetHomeSale(marketDate, saleAmount)
                //  SOLD
                {
                    int homesaleID = 6;
                    var marketDate = new DateTime(2015, 03, 01);
                    var saleAmount = 335_000m;

                    var expectedHomeSale = new HomeSale()
                    {
                        SaleID     = homesaleID,
                        HomeID     = 1,
                        SoldDate   = new DateTime(2010, 03, 15),
                        AgentID    = 1,
                        SaleAmount = saleAmount,
                        BuyerID    = 1,
                        MarketDate = marketDate,
                        CompanyID  = 2
                    };

                    var actualHomeSale = LogicBroker.GetHomeSale(marketDate, saleAmount);

                    bool areEqual = expectedHomeSale.Equals(actualHomeSale);
                    if (!areEqual)
                    {
                        var items = new List <HomeSale>()
                        {
                            expectedHomeSale, actualHomeSale
                        };

                        PrintObjects(items);
                    }

                    Assert.IsTrue(areEqual);
                }

                //  GetHomeSale(saleID)
                //  FOR SALE
                {
                    var saleID = 1;

                    var expectedHomeForSale = new HomeSale()
                    {
                        SaleID     = saleID,
                        HomeID     = 3,
                        SoldDate   = null,
                        AgentID    = 4,
                        SaleAmount = 700_000m,
                        MarketDate = new DateTime(2016, 08, 15),
                        CompanyID  = 1
                    };

                    var actualHomeForSale = LogicBroker.GetHomeSale(saleID);

                    bool areEqual = expectedHomeForSale.Equals(actualHomeForSale);
                    if (!areEqual)
                    {
                        var items = new List <HomeSale>()
                        {
                            expectedHomeForSale, actualHomeForSale
                        };

                        PrintObjects(items);
                    }

                    Assert.IsTrue(areEqual);
                }

                //  GetReCompany(companyID)
                {
                    int companyID = 3;

                    var expectedRECo = new RealEstateCompany()
                    {
                        CompanyID   = companyID,
                        CompanyName = "Rapid Real Estate",
                        Phone       = "6662221111"
                    };

                    var actualRECo = LogicBroker.GetReCompany(companyID);

                    bool areEqual = expectedRECo.Equals(actualRECo);
                    if (!areEqual)
                    {
                        var items = new List <RealEstateCompany>()
                        {
                            expectedRECo, actualRECo
                        };

                        PrintObjects(items);
                    }

                    Assert.IsTrue(areEqual);
                }

                //  GetReCompany(companyName)
                {
                    int companyID   = 3;
                    var companyName = "Rapid Real Estate";

                    var expectedRECo = new RealEstateCompany()
                    {
                        CompanyID   = companyID,
                        CompanyName = companyName,
                        Phone       = "6662221111"
                    };

                    var actualRECo = LogicBroker.GetReCompany(companyName);

                    bool areEqual = expectedRECo.Equals(actualRECo);
                    if (!areEqual)
                    {
                        var items = new List <RealEstateCompany>()
                        {
                            expectedRECo, actualRECo
                        };

                        PrintObjects(items);
                    }

                    Assert.IsTrue(areEqual);
                }

                //  GetAgent(AgentID)
                {
                    var agentID = 4;

                    var expectedAgent = new Agent()
                    {
                        AgentID           = agentID,
                        CompanyID         = 1,
                        CommissionPercent = 0.03m
                    };

                    var actualAgent = LogicBroker.GetAgent(agentID);

                    bool areEqual = expectedAgent.Equals(actualAgent);
                    if (!areEqual)
                    {
                        var items = new List <Agent>()
                        {
                            expectedAgent, actualAgent
                        };

                        PrintObjects(items);
                    }

                    Assert.IsTrue(areEqual);
                }

                //  GetBuyer(BuyerID)
                {
                    var buyerID = 7;

                    var expectedBuyer = new Buyer()
                    {
                        BuyerID      = buyerID,
                        CreditRating = 780
                    };

                    var actualBuyer = LogicBroker.GetBuyer(buyerID);

                    bool areEqual = expectedBuyer.Equals(actualBuyer);
                    if (!areEqual)
                    {
                        var items = new List <Buyer>()
                        {
                            expectedBuyer, actualBuyer
                        };

                        PrintObjects(items);
                    }

                    Assert.IsTrue(areEqual);
                }

                //  GetOwner(OwnerID)
                {
                    var ownerID = 7;

                    var expectedOwner = new Owner()
                    {
                        OwnerID         = ownerID,
                        PreferredLender = "Unique Mortgaging"
                    };

                    var actualOwner = LogicBroker.GetOwner(ownerID);

                    bool areEqual = expectedOwner.Equals(actualOwner);
                    if (!areEqual)
                    {
                        var items = new List <Owner>()
                        {
                            expectedOwner, actualOwner
                        };

                        PrintObjects(items);
                    }

                    Assert.IsTrue(areEqual);
                }

                //  UpdateExistingItem<Person>(person)
                {
                    var updatePersonFirstName = "p1FirstName";
                    var updatePersonLastName  = "p2LastName";
                    var addUpdateRemovePerson = new Person
                    {
                        FirstName = updatePersonFirstName,
                        LastName  = updatePersonLastName,
                        Phone     = "123456789",
                        Email     = "*****@*****.**"
                    };

                    var expectedStoreResult = true;
                    var actualStoreResult   = LogicBroker.StoreItem <Person>(addUpdateRemovePerson);

                    PrintObject <Person>(addUpdateRemovePerson, "Update Existing Item addUpdateRemovePerson.");
                    PrintObject <bool>(actualStoreResult, "Return value from StoreItem().");

                    if (!actualStoreResult)
                    {
                        Console.WriteLine(addUpdateRemovePerson.ToString());
                    }

                    Assert.AreEqual(expectedStoreResult, actualStoreResult);

                    var personToUpdate = LogicBroker.GetPerson(updatePersonFirstName, updatePersonLastName);
                    PrintObject <Person>(personToUpdate, "Returned Person from GetPerson(firstname, lastname).");

                    var expectedUpdateResult = true;
                    var updatePerson         = new Person()
                    {
                        PersonID  = personToUpdate.PersonID,
                        FirstName = personToUpdate.FirstName,
                        LastName  = personToUpdate.LastName,
                        Phone     = "0000000000",
                        Email     = "*****@*****.**"
                    };

                    var actualUpdateResult = LogicBroker.UpdateExistingItem <Person>(updatePerson);

                    PrintObject <bool>(actualUpdateResult, "Return value from UpdateExistingItem().");

                    if (actualUpdateResult)
                    {
                        Person resultPerson = LogicBroker.GetPerson(addUpdateRemovePerson.FirstName, addUpdateRemovePerson.LastName);
                        Console.WriteLine(resultPerson.ToString());
                    }

                    Assert.AreEqual(expectedUpdateResult, actualUpdateResult);

                    var expectedRemoveResult = true;
                    var actualRemoveResult   = LogicBroker.RemoveEntity <Person>(updatePerson);

                    PrintObject <bool>(actualRemoveResult, "Return value from RemoveEntity<Person>().");

                    if (!actualRemoveResult)
                    {
                        Console.WriteLine("RemoveEntity<Person>(addUpdateRemovePerson) failed.");
                        Console.WriteLine(addUpdateRemovePerson.ToString());
                    }

                    Assert.AreEqual(expectedRemoveResult, actualRemoveResult);
                }
            }
            #endregion LogicBrokerTests

            #region InitializeCollections

            DbPeopleCollection = new PeopleCollection <Person>(EntityLists.GetListOfPeople());
            Assert.IsTrue(DbPeopleCollection.Count == 10);

            DbHomesCollection = new HomesCollection(EntityLists.GetTreeListOfHomes());
            Assert.IsTrue(DbHomesCollection.Count == 5);

            DbHomesalesCollection = new HomeSalesCollection(EntityLists.GetListOfHomeSales());
            Assert.IsTrue(DbHomesalesCollection.Count == 8);

            DbRECosCollection = new RealEstateCosCollection(EntityLists.GetTreeListOfRECompanies());
            Assert.IsTrue(DbRECosCollection.Count == 4);
            #endregion InitializeCollections

            #region PeopleCollectionTests
            {
                //  COUNT
                var expectedCount = 10;
                var actualCount   = DbPeopleCollection.Count;
                Assert.AreEqual(expectedCount, actualCount);

                //  ADD
                var personPerson = new Person()
                {
                    FirstName = "Owen",
                    LastName  = "Owner",
                    Phone     = "123456789",
                    Email     = "*****@*****.**"
                };
                var personAddedCount = DbPeopleCollection.Add(personPerson);
                PrintObject <Person>(personPerson, $"Attempted to add Person to PersonCollection. Result: { personAddedCount }.");
                Assert.IsTrue(personAddedCount == 1);   //  Add plain Person

                //  GET (PersonID by F+L Names)
                int addedPersonID = 0;
                addedPersonID = DbPeopleCollection.GetPersonIDbyName(personPerson.FirstName, personPerson.LastName);
                PrintObject <int>(addedPersonID, "Returned PersonID from GetPersonIDbyName(Owen, Owner).");
                Assert.IsTrue(addedPersonID > 10);

                //  GET (Person by Person)
                Person addedPerson = null;
                addedPerson = DbPeopleCollection.Get(addedPersonID);
                PrintObject <Person>(addedPerson, "Returned Person from Get(addedPersonID).");
                Assert.IsTrue(addedPerson != null);

                //  UPDATE (Person's Phone)
                addedPerson.Phone = "3254678451";
                var addedPersonUpdated = DbPeopleCollection.UpdatePerson(addedPerson);
                PrintObject <Person>(addedPerson, $"UpdatePerson(addedPerson) result: { addedPersonUpdated }.");
                Assert.IsTrue(addedPersonUpdated == 1);

                //  UPDATE (Person as an Owner)
                var existingUpdatePerson = DbPeopleCollection.Get(addedPersonID);
                var owner = new Owner()
                {
                    OwnerID         = addedPerson.PersonID,
                    PreferredLender = "Lender Test"
                };
                existingUpdatePerson.Owner = owner;
                var ownerPersonUpdated = DbPeopleCollection.UpdatePerson(existingUpdatePerson);
                PrintObject <Person>(existingUpdatePerson, $"UpdatePerson(addedPerson) with Owner result: { ownerPersonUpdated }.");
                Assert.IsTrue(ownerPersonUpdated > 0);

                //  REMOVE
                var updatePersonWithOwner = DbPeopleCollection.Get(addedPersonID);
                var personRemoved         = DbPeopleCollection.Remove(updatePersonWithOwner);
                PrintObject <Person>(updatePersonWithOwner, $"Removing person from collection result: { personRemoved }.");
                Assert.IsTrue(personRemoved);           //  Remove Person with Owner FK

                //  CLEAR
                DbPeopleCollection.Clear();
                expectedCount = 0;
                actualCount   = DbPeopleCollection.Count;

                //  REINIT
                DbPeopleCollection = new PeopleCollection <Person>(EntityLists.GetListOfPeople());
                Assert.IsTrue(DbPeopleCollection.Count == 10);
            }
            #endregion

            #region HomesCollectionTests
            {
                var newHome = new Home()
                {
                    Address = "4412 153rd Ave SE",
                    City    = "Bellevue",
                    State   = "WA",
                    Zip     = "980060000"
                };

                //  GET HOME BY ADDRESS AND ZIP
                //  var homeByAddress = DbHomesCollection.GetHome(anAddress, aZipCode);


                //  GET HOME BY ID
                var homeID   = 1;
                var homeByID = DbHomesCollection.Retreive(homeID);

                var expectedHome = new Home()
                {
                    HomeID  = 1,
                    Address = "23 Oak St.",
                    City    = "Johnsonville",
                    State   = "CA",
                    Zip     = "955551111",
                    OwnerID = 1
                };
                var expectedResult = true;
                var actualResult   = expectedHome.Equals(homeByID);
                PrintObject <Home>(homeByID, "Get Home by ID Result.");
                PrintObject <bool>(actualResult, "Get Home by id actual result:");
                Assert.AreEqual(expectedResult, actualResult);

                //  UPDATE HOME
                newHome.OwnerID = 3;
                var actualUpdateResult   = DbHomesCollection.Update(newHome);
                var expectedUpdateResult = 1;
                PrintObject <int>(actualUpdateResult, "Update Home actual update result:");
                Assert.AreEqual(expectedUpdateResult, actualUpdateResult);

                //  REMOVE HOME
                var expectedRemoveResult = true;
                var actualRemoveResult   = DbHomesCollection.Remove(newHome.HomeID);
                PrintObject <bool>(actualRemoveResult, "Remove Home actual result:");
                Assert.AreEqual(expectedRemoveResult, actualRemoveResult);

                //  CLEAR
                //DbHomesCollection.Clear();
                //expectedCount = 0;
                //actualCount = DbHomesCollection.Count;
                //Assert.AreEqual(expectedCount, actualCount);

                //  REINIT
                DbHomesCollection = new HomesCollection(EntityLists.GetTreeListOfHomes());

                var expectedCount = 5;
                var actualCount   = DbHomesCollection.Count;
                PrintObject <int>(actualCount, "Actual Count of reinitialized Homes collection.");
                Assert.AreEqual(expectedCount, actualCount);
            }
            #endregion

            #region HomeSalesCollectionTests
            {
                //  GET BY ID
                var existingSaleID = 1;
                var getHomesale    = DbHomesalesCollection.Retreive(existingSaleID);
                PrintObject <HomeSale>(getHomesale, "Retreived Homesale with SaleID=1: ");
                var marketDate       = new DateTime(2016, 08, 15);
                var expectedHomesale = new HomeSale()
                {
                    SaleID     = 6,
                    HomeID     = 3,
                    AgentID    = 4,
                    SaleAmount = 700000m,
                    MarketDate = new DateTime(2016, 08, 15),
                    CompanyID  = 1
                };

                var expectedResult = true;
                var actualResult   = expectedHomesale.Equals(getHomesale);
                Assert.AreEqual(expectedResult, actualResult);

                //  GET BY ITEM?
                //  TODO: Implement if necessary

                //  UPDATE E.G. SELLHOME
                var preNewHomesale = DbHomesalesCollection.Retreive(1); //  so it can be put back into DB at end of tests
                PrintObject <HomeSale>(preNewHomesale, "PreNewHomesale instance, SaleID=1: ");

                var newHomeSale = new HomeSale()
                {
                    SaleID     = 1,
                    HomeID     = 3,
                    AgentID    = 4,
                    SaleAmount = 766666m,
                    MarketDate = new DateTime(2016, 08, 15),
                    CompanyID  = 1,
                    SoldDate   = new DateTime(2020, 08, 15),
                    BuyerID    = 1
                };

                var actualUpdateResult = DbHomesalesCollection.Update(newHomeSale);
                PrintObject <HomeSale>(newHomeSale, "NewHomeSale instance sent to Update method: ");
                PrintObject <int>(actualUpdateResult, "UPDATE Home as sold result: ");
                var expectedUpdateResult = 1;
                Assert.AreEqual(expectedUpdateResult, actualUpdateResult);

                //  REMOVE
                var actualRemoveResult = DbHomesalesCollection.Remove(newHomeSale);
                PrintObject <HomeSale>(newHomeSale, "Item sent to Remove() method: ");

                var expectedRemoveResult = true;
                Assert.AreEqual(expectedRemoveResult, actualRemoveResult);

                //  GET UPDATE REMOVEFROMMARKET (put homesale back, then remove from market)
                var expectedPostRemoveFromMarketCount = DbHomesalesCollection.Count;
                var resetHomesale = new HomeSale()
                {
                    SaleID     = 6,
                    HomeID     = 3,
                    AgentID    = 4,
                    SaleAmount = 700000m,
                    MarketDate = new DateTime(2016, 08, 15),
                    CompanyID  = 1
                };
                var reAddHomeForSaleToCollectionResult = DbHomesalesCollection.Add(resetHomesale);
                PrintObject <HomeSale>(resetHomesale, "ResetHomesale, SaleID=6, sent to Add method: ");

                var expectedReAddHomeForSaleToCollectionResult = 1;
                Assert.AreEqual(expectedReAddHomeForSaleToCollectionResult, reAddHomeForSaleToCollectionResult);

                var expectedPostRemoveFromMarketResult = true;
                var actualPostRemoveFromMarketResult   = DbHomesalesCollection.Remove(resetHomesale);
                PrintObject <HomeSale>(resetHomesale, "ResetHomesale, SaleID=6, sent to Remove method: ");

                var actualPostRemoveFromMarketCount = DbHomesalesCollection.Count;

                Assert.AreEqual(expectedPostRemoveFromMarketResult, actualPostRemoveFromMarketResult);
                Assert.AreEqual(expectedPostRemoveFromMarketCount, actualPostRemoveFromMarketCount);

                //  CLEAR
                //  TODO: Implement Clear method if necessary.
            }
            #endregion

            #region RealEstateCompaniesTests
            {
                //  RETREIVE
                var recoToRetreiveID = 3;
                var retreivedRECo    = DbRECosCollection.Retrieve(recoToRetreiveID);
                var expectedRECo     = new RealEstateCompany()
                {
                    CompanyID   = 3,
                    CompanyName = "Rapid Real Estate",
                    Phone       = "6662221111",
                };
                var expectedAgentsCount    = 1;
                var expectedHomesalesCount = 2;
                PrintObject <RealEstateCompany>(retreivedRECo, "Expecting Rapid Real Estate. RECo retreived from Collection: ");
                var actualRetreivedRECoAgentsCount    = retreivedRECo.Agents.Count;
                var actualRetreivedRECoHomesalesCount = retreivedRECo.HomeSales.Count;
                PrintObject <int>(actualRetreivedRECoAgentsCount, "Expected: 1; Actual AGENTS in retreived RECo instance: ");
                PrintObject <int>(actualRetreivedRECoHomesalesCount, "Expected: 2; Actual HOMESALES in retreived RECo instance: ");
                Assert.AreEqual(expectedAgentsCount, retreivedRECo.Agents.Count);
                Assert.AreEqual(expectedHomesalesCount, retreivedRECo.HomeSales.Count);
                var expectedRECoRetreiveResult = true;
                var actualRECoRetreiveResult   = expectedRECo.Equals(retreivedRECo);
                PrintObject <bool>(actualRECoRetreiveResult, "Expected .Equals(): True; Actual comparison result: ");
                Assert.AreEqual(expectedRECoRetreiveResult, actualRECoRetreiveResult);

                //  ADD
                var expectedPreCount = DbRECosCollection.Count;
                var recoToAdd        = new RealEstateCompany()
                {
                    CompanyName = "TestCompany",
                    Phone       = "2061234567"
                };
                var expectedAddResult = 1;
                var actualAddResult   = DbRECosCollection.Add(recoToAdd);
                Assert.AreEqual(expectedAddResult, actualAddResult);

                //  SEARCH and store
                var recoToRemove = DbRECosCollection.Where(re => re.CompanyName == recoToAdd.CompanyName).FirstOrDefault();
                if (recoToRemove == null)
                {
                    Assert.Fail($"Unable to recover added RECo: { recoToAdd }");
                }

                //  Remove
                var expectedRemoveResult = true;
                var recoRemovalPreCount  = DbRECosCollection.Count;
                var expectedPostCount    = recoRemovalPreCount - 1;
                var actualRemoveResult   = DbRECosCollection.Remove(recoToRemove.CompanyID); //  this exercizes BOTH remove methods
                var actualPostCount      = DbRECosCollection.Count;
                Assert.AreEqual(expectedPostCount, actualPostCount);
                Assert.AreEqual(expectedRemoveResult, actualRemoveResult);
            }
            #endregion
        }
    }
}