public void TestUpdatePerson()
        {
            var uowFactory = new FootlooseFSSqlUnitOfWorkFactory();
            var notificationService = new FootlooseFSNotificationService();
            var service = new FootlooseFSService(uowFactory, notificationService);

            // for this test lets get all of the linked tables and verify that we can properly query for all of the this information
            var person = service.GetPersonById(5, new PersonIncludes { Phones = true, Accounts = true, Addressses = true, AccountTransactions = true });

            // Update the email address
            person.EmailAddress = "*****@*****.**";

            // Upate the home phone
            var homePhone = person.Phones.Where(p => p.PhoneTypeID == 1).First();
            var oldhomePhone = homePhone.Number;
            homePhone.Number = "336-418-5555";

            // Update the home address
            var homeAddress = person.Addresses.Where(pa => pa.AddressTypeID == 1).First().Address;
            var oldAddress = homeAddress.StreetAddress;
            var oldCity = homeAddress.City;
            var oldZip = homeAddress.Zip;
            var oldState = homeAddress.State;

            homeAddress.StreetAddress = "631 Glebe Road";
            homeAddress.City = "Arlington";
            homeAddress.Zip = "20178";
            homeAddress.State = "VA";

            // Now perform the update in the SQL datastore
            var opStatus = service.UpdatePerson(person);

            var updatedPerson = (Person)opStatus.Data;

            // Verify that the UpdatePerson method returns data of type Person
            Assert.IsInstanceOf<Person>(updatedPerson);

            var updatedPersonFromUoW = service.GetPersonById(updatedPerson.PersonID, new PersonIncludes { Phones = true, Addressses = true });

            // Verify that email address was updated
            Assert.AreEqual(updatedPersonFromUoW.EmailAddress, "*****@*****.**");

            // Verify that the home phone number was updated
            homePhone = updatedPersonFromUoW.Phones.Where(p => p.PhoneTypeID == 1).FirstOrDefault();
            Assert.AreEqual(homePhone.Number, "336-418-5555");

            // Verify that the address was updated
            var address = updatedPersonFromUoW.Addresses.Where(a => a.AddressTypeID == 1).FirstOrDefault().Address;

            Assert.AreEqual(address.StreetAddress, "631 Glebe Road");
            Assert.AreEqual(address.City, "Arlington");
            Assert.AreEqual(address.Zip, "20178");
            Assert.AreEqual(address.State, "VA");

            // Now put the original data back
            homePhone = person.Phones.Where(p => p.PhoneTypeID == 1).First();
            homePhone.Number = oldhomePhone;

            // Update the home address
            homeAddress = person.Addresses.Where(pa => pa.AddressTypeID == 1).First().Address;
            homeAddress.StreetAddress = oldAddress;
            homeAddress.City = oldCity;
            homeAddress.Zip = oldZip;
            homeAddress.State = oldState;

            // Now perform the update in the SQL datastore
            opStatus = service.UpdatePerson(person);

            Assert.IsTrue(opStatus.Success);
        }
        public void TestUpdatePerson()
        {
            var testUoW = new FootlooseFSTestUnitOfWork();
            var mockUoWFactory = new Mock<IFootlooseFSUnitOfWorkFactory>();
            var mockNotificationService = new Mock<IFootlooseFSNotificationService>();

            // Instead of instantiating a new UoW object in the factory we want to use the one we created so we can monitor
            // it's internal data and verify that the service did what is was supposed to do
            mockUoWFactory.Setup(m => m.CreateUnitOfWork()).Returns(testUoW);

            mockNotificationService.Setup(m => m.SendPersonUpdatedNotification(It.IsAny<int>(), It.IsAny<string>())).Returns(true);

            var uowFactory = mockUoWFactory.Object;
            var service = new FootlooseFSService(uowFactory, mockNotificationService.Object);

            var person = new Person
            {
                PersonID = 1,
                FirstName = "Pam",
                LastName = "Scicchitano",
                EmailAddress = "*****@*****.**", // Updated email address
                Phones = new List<Phone>
                {
                    new Phone
                    {
                        PersonID = 1,
                        Number = "336-418-5555",    // Update home phone
                        PhoneType = new PhoneType { Name = "Home", PhoneTypeID = 1 },
                        PhoneTypeID = 1
                    },
                    new Phone
                    {
                        PersonID = 1,
                        Number = "336-418-7777",    // Updated work phone
                        PhoneType = new PhoneType { Name = "Work", PhoneTypeID = 2 },
                        PhoneTypeID = 2
                    },
                    new Phone
                    {
                        PersonID = 1,
                        Number = "336-418-4444",    // Updated cell phone
                        PhoneType = new PhoneType { Name = "Cell", PhoneTypeID = 3 },
                        PhoneTypeID = 3
                    }
                },
                Addresses = new List<PersonAddressAssn>
                {
                    new PersonAddressAssn
                    {
                        Address = new Address
                        {
                            StreetAddress = "631 Glebe Road",   // Updated address
                            State = "VA",
                            Zip = "20178",
                            AddressID = 1,
                            City = "Arlington"
                        },
                        AddressID = 1,
                        AddressType = new AddressType { Name = "Home", AddressTypeID = 1 },
                        AddressTypeID = 1,
                        PersonID = 1
                    }
                },
            };

            var opStatus = service.UpdatePerson(person);

            var updatedPerson = (Person)opStatus.Data;

            // Verify that the UpdatePerson method returns data of type Person
            Assert.IsInstanceOf<Person>(updatedPerson);

            // Get the updated person object from the UoW
            var updatedPersonFromUoW = testUoW.Persons.GetQueryable().Where(p => p.PersonID == 1).First();

            // Verify that email address was updated
            Assert.AreEqual(updatedPersonFromUoW.EmailAddress, "*****@*****.**");

            // Verify that the home phone number was updated
            var homePhone = updatedPersonFromUoW.Phones.Where(p => p.PhoneTypeID == 1).FirstOrDefault();
            Assert.AreEqual(homePhone.Number, "336-418-5555");

            // Verify that the work number was updated
            var workPhone = updatedPersonFromUoW.Phones.Where(p => p.PhoneTypeID == 2).FirstOrDefault();
            Assert.AreEqual(workPhone.Number, "336-418-7777");

            // Verify that the cell number was updated
            var cellPhone = updatedPersonFromUoW.Phones.Where(p => p.PhoneTypeID == 3).FirstOrDefault();
            Assert.AreEqual(cellPhone.Number, "336-418-4444");

            // Verify that the address was updated
            var address = updatedPersonFromUoW.Addresses.Where(a => a.AddressTypeID == 1).FirstOrDefault().Address;

            Assert.AreEqual(address.StreetAddress, "631 Glebe Road");
            Assert.AreEqual(address.City, "Arlington");
            Assert.AreEqual(address.Zip, "20178");
            Assert.AreEqual(address.State, "VA");
        }
        public void TestUpdatePerson()
        {
            var testFactory = new FootlooseFSTestUnitOfWorkFactory();

            var service = new FootlooseFSService(testFactory, options);

            var person = new Person
            {
                PersonID     = 1,
                FirstName    = "Pam",
                LastName     = "Scicchitano",
                EmailAddress = "*****@*****.**", // Updated email address
                Phones       = new List <Phone>
                {
                    new Phone
                    {
                        PersonID  = 1,
                        Number    = "336-418-5555", // Update home phone
                        PhoneType = new PhoneType {
                            Name = "Home", PhoneTypeID = 1
                        },
                        PhoneTypeID = 1
                    },
                    new Phone
                    {
                        PersonID  = 1,
                        Number    = "336-418-7777", // Updated work phone
                        PhoneType = new PhoneType {
                            Name = "Work", PhoneTypeID = 2
                        },
                        PhoneTypeID = 2
                    },
                    new Phone
                    {
                        PersonID  = 1,
                        Number    = "336-418-4444", // Updated cell phone
                        PhoneType = new PhoneType {
                            Name = "Cell", PhoneTypeID = 3
                        },
                        PhoneTypeID = 3
                    }
                },
                Addresses = new List <PersonAddressAssn>
                {
                    new PersonAddressAssn
                    {
                        Address = new Address
                        {
                            StreetAddress = "631 Glebe Road",   // Updated address
                            State         = "VA",
                            Zip           = "20178",
                            AddressID     = 1,
                            City          = "Arlington"
                        },
                        AddressID   = 1,
                        AddressType = new AddressType {
                            Name = "Home", AddressTypeID = 1
                        },
                        AddressTypeID = 1,
                        PersonID      = 1
                    }
                },
            };

            var opStatus = service.UpdatePerson(person);

            var updatedPerson = (Person)opStatus.Data;

            // Get the updated person object from the UoW
            var updatedPersonFromUoW = service.GetPersonById(updatedPerson.PersonID, new PersonIncludes {
                Phones = true, Addressses = true
            });

            // Verify that email address was updated
            Assert.AreEqual(updatedPersonFromUoW.EmailAddress, "*****@*****.**");

            // Verify that the home phone number was updated
            var homePhone = updatedPersonFromUoW.Phones.Where(p => p.PhoneTypeID == 1).FirstOrDefault();

            Assert.AreEqual(homePhone.Number, "336-418-5555");

            // Verify that the work number was updated
            var workPhone = updatedPersonFromUoW.Phones.Where(p => p.PhoneTypeID == 2).FirstOrDefault();

            Assert.AreEqual(workPhone.Number, "336-418-7777");

            // Verify that the cell number was updated
            var cellPhone = updatedPersonFromUoW.Phones.Where(p => p.PhoneTypeID == 3).FirstOrDefault();

            Assert.AreEqual(cellPhone.Number, "336-418-4444");

            // Verify that the address was updated
            var address = updatedPersonFromUoW.Addresses.Where(a => a.AddressTypeID == 1).FirstOrDefault().Address;

            Assert.AreEqual(address.StreetAddress, "631 Glebe Road");
            Assert.AreEqual(address.City, "Arlington");
            Assert.AreEqual(address.Zip, "20178");
            Assert.AreEqual(address.State, "VA");
        }
        public void TestUpdatePerson()
        {
            var uowFactory = new FootlooseFSSqlUnitOfWorkFactory(options);
            var service    = new FootlooseFSService(uowFactory, options);

            // for this test lets get all of the linked tables and verify that we can properly query for all of the this information
            var person = service.GetPersonById(5, new PersonIncludes {
                Phones = true, Accounts = true, Addressses = true, AccountTransactions = true
            });

            // Update the email address
            person.EmailAddress = "*****@*****.**";

            // Upate the home phone
            var homePhone    = person.Phones.Where(p => p.PhoneTypeID == 1).First();
            var oldhomePhone = homePhone.Number;

            homePhone.Number = "336-418-5555";

            // Update the home address
            var homeAddress = person.Addresses.Where(pa => pa.AddressTypeID == 1).First().Address;
            var oldAddress  = homeAddress.StreetAddress;
            var oldCity     = homeAddress.City;
            var oldZip      = homeAddress.Zip;
            var oldState    = homeAddress.State;

            homeAddress.StreetAddress = "631 Glebe Road";
            homeAddress.City          = "Arlington";
            homeAddress.Zip           = "20178";
            homeAddress.State         = "VA";

            // Now perform the update in the SQL datastore
            var opStatus = service.UpdatePerson(person);

            var updatedPerson = (Person)opStatus.Data;

            var updatedPersonFromUoW = service.GetPersonById(updatedPerson.PersonID, new PersonIncludes {
                Phones = true, Addressses = true
            });

            // Verify that email address was updated
            Assert.AreEqual(updatedPersonFromUoW.EmailAddress, "*****@*****.**");

            // Verify that the home phone number was updated
            homePhone = updatedPersonFromUoW.Phones.Where(p => p.PhoneTypeID == 1).FirstOrDefault();
            Assert.AreEqual(homePhone.Number, "336-418-5555");

            // Verify that the address was updated
            var address = updatedPersonFromUoW.Addresses.Where(a => a.AddressTypeID == 1).FirstOrDefault().Address;

            Assert.AreEqual(address.StreetAddress, "631 Glebe Road");
            Assert.AreEqual(address.City, "Arlington");
            Assert.AreEqual(address.Zip, "20178");
            Assert.AreEqual(address.State, "VA");

            // Now put the original data back
            homePhone        = person.Phones.Where(p => p.PhoneTypeID == 1).First();
            homePhone.Number = oldhomePhone;

            // Update the home address
            homeAddress = person.Addresses.Where(pa => pa.AddressTypeID == 1).First().Address;
            homeAddress.StreetAddress = oldAddress;
            homeAddress.City          = oldCity;
            homeAddress.Zip           = oldZip;
            homeAddress.State         = oldState;

            // Now perform the update in the SQL datastore
            opStatus = service.UpdatePerson(person);

            Assert.IsTrue(opStatus.Success);
        }
Esempio n. 5
0
        public void TestUpdatePerson()
        {
            var testUoW                 = new FootlooseFSTestUnitOfWork();
            var mockUoWFactory          = new Mock <IFootlooseFSUnitOfWorkFactory>();
            var mockNotificationService = new Mock <IFootlooseFSNotificationService>();

            // Instead of instantiating a new UoW object in the factory we want to use the one we created so we can monitor
            // it's internal data and verify that the service did what is was supposed to do
            mockUoWFactory.Setup(m => m.CreateUnitOfWork()).Returns(testUoW);

            mockNotificationService.Setup(m => m.SendPersonUpdatedNotification(It.IsAny <int>(), It.IsAny <string>())).Returns(true);

            var uowFactory = mockUoWFactory.Object;
            var service    = new FootlooseFSService(uowFactory, mockNotificationService.Object);

            var person = new Person
            {
                PersonID     = 1,
                FirstName    = "Pam",
                LastName     = "Scicchitano",
                EmailAddress = "*****@*****.**", // Updated email address
                Phones       = new List <Phone>
                {
                    new Phone
                    {
                        PersonID  = 1,
                        Number    = "336-418-5555", // Update home phone
                        PhoneType = new PhoneType {
                            Name = "Home", PhoneTypeID = 1
                        },
                        PhoneTypeID = 1
                    },
                    new Phone
                    {
                        PersonID  = 1,
                        Number    = "336-418-7777", // Updated work phone
                        PhoneType = new PhoneType {
                            Name = "Work", PhoneTypeID = 2
                        },
                        PhoneTypeID = 2
                    },
                    new Phone
                    {
                        PersonID  = 1,
                        Number    = "336-418-4444", // Updated cell phone
                        PhoneType = new PhoneType {
                            Name = "Cell", PhoneTypeID = 3
                        },
                        PhoneTypeID = 3
                    }
                },
                Addresses = new List <PersonAddressAssn>
                {
                    new PersonAddressAssn
                    {
                        Address = new Address
                        {
                            StreetAddress = "631 Glebe Road",   // Updated address
                            State         = "VA",
                            Zip           = "20178",
                            AddressID     = 1,
                            City          = "Arlington"
                        },
                        AddressID   = 1,
                        AddressType = new AddressType {
                            Name = "Home", AddressTypeID = 1
                        },
                        AddressTypeID = 1,
                        PersonID      = 1
                    }
                },
            };

            var opStatus = service.UpdatePerson(person);

            var updatedPerson = (Person)opStatus.Data;

            // Verify that the UpdatePerson method returns data of type Person
            Assert.IsInstanceOf <Person>(updatedPerson);

            // Get the updated person object from the UoW
            var updatedPersonFromUoW = testUoW.Persons.GetQueryable().Where(p => p.PersonID == 1).First();

            // Verify that email address was updated
            Assert.AreEqual(updatedPersonFromUoW.EmailAddress, "*****@*****.**");

            // Verify that the home phone number was updated
            var homePhone = updatedPersonFromUoW.Phones.Where(p => p.PhoneTypeID == 1).FirstOrDefault();

            Assert.AreEqual(homePhone.Number, "336-418-5555");

            // Verify that the work number was updated
            var workPhone = updatedPersonFromUoW.Phones.Where(p => p.PhoneTypeID == 2).FirstOrDefault();

            Assert.AreEqual(workPhone.Number, "336-418-7777");

            // Verify that the cell number was updated
            var cellPhone = updatedPersonFromUoW.Phones.Where(p => p.PhoneTypeID == 3).FirstOrDefault();

            Assert.AreEqual(cellPhone.Number, "336-418-4444");

            // Verify that the address was updated
            var address = updatedPersonFromUoW.Addresses.Where(a => a.AddressTypeID == 1).FirstOrDefault().Address;

            Assert.AreEqual(address.StreetAddress, "631 Glebe Road");
            Assert.AreEqual(address.City, "Arlington");
            Assert.AreEqual(address.Zip, "20178");
            Assert.AreEqual(address.State, "VA");
        }