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

            var person = new Person
            {
                FirstName = "John",
                LastName = "Dorman",
                EmailAddress = "*****@*****.**", // Updated email address
                Phones = new List<Phone>
                {
                    new Phone
                    {
                        Number = "813-657-2222",    // Update home phone
                        PhoneTypeID = 1
                    }
                },
                Addresses = new List<PersonAddressAssn>
                {
                    new PersonAddressAssn
                    {
                        Address = new Address
                        {
                            StreetAddress = "823 Newton Drive",   // Updated address
                            State = "FL",
                            Zip = "33782",
                            AddressID = 5,
                            City = "Pinellas Park"
                        },
                        AddressTypeID = 1,
                    }
                },
            };

            var opStatus = service.InsertPerson(person);

            var insertedPerson = (Person)opStatus.Data;

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

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

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

            // Verify that the home phone number was updated
            var homePhone = insertedPersonFromUoW.Phones.Where(p => p.PhoneTypeID == 1).FirstOrDefault();
            Assert.AreEqual(homePhone.Number, "813-657-2222");

            // Verify that there is no work number
            var workPhone = insertedPersonFromUoW.Phones.Where(p => p.PhoneTypeID == 2 && ! string.IsNullOrEmpty(p.Number));
            Assert.AreEqual(workPhone.Count(), 0);

            // Verify that there is no cell number
            var cellPhone = insertedPersonFromUoW.Phones.Where(p => p.PhoneTypeID == 3 && !string.IsNullOrEmpty(p.Number));
            Assert.AreEqual(cellPhone.Count(), 0);

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

            Assert.AreEqual(address.StreetAddress, "823 Newton Drive");
            Assert.AreEqual(address.City, "Pinellas Park");
            Assert.AreEqual(address.Zip, "33782");
            Assert.AreEqual(address.State, "FL");

            // Now delete the person
            service.DeletePerson(insertedPersonFromUoW);

            // Make sure the person is deleted
            var deletedPerson = service.GetPersonById(insertedPersonFromUoW.PersonID, new PersonIncludes());

            Assert.IsNull(deletedPerson);
        }
        public void TestInsertAndDeletePerson()
        {
            var uowFactory = new FootlooseFSSqlUnitOfWorkFactory(options);
            var service    = new FootlooseFSService(uowFactory, options);

            var person = new Person
            {
                FirstName    = "John",
                LastName     = "Dorman",
                EmailAddress = "*****@*****.**", // Updated email address
                Phones       = new List <Phone>
                {
                    new Phone
                    {
                        Number      = "813-657-2222", // Update home phone
                        PhoneTypeID = 1
                    }
                },
                Addresses = new List <PersonAddressAssn>
                {
                    new PersonAddressAssn
                    {
                        Address = new Address
                        {
                            StreetAddress = "823 Newton Drive",   // Updated address
                            State         = "FL",
                            Zip           = "33782",
                            City          = "Pinellas Park"
                        },
                        AddressTypeID = 1,
                    }
                },
            };

            var opStatus = service.InsertPerson(person);

            var insertedPerson = (Person)opStatus.Data;

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

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

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

            Assert.AreEqual(homePhone.Number, "813-657-2222");

            // Verify that there is no work number
            var workPhone = insertedPersonFromUoW.Phones.Where(p => p.PhoneTypeID == 2 && !string.IsNullOrEmpty(p.Number));

            Assert.AreEqual(workPhone.Count(), 0);

            // Verify that there is no cell number
            var cellPhone = insertedPersonFromUoW.Phones.Where(p => p.PhoneTypeID == 3 && !string.IsNullOrEmpty(p.Number));

            Assert.AreEqual(cellPhone.Count(), 0);

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

            Assert.AreEqual(address.StreetAddress, "823 Newton Drive");
            Assert.AreEqual(address.City, "Pinellas Park");
            Assert.AreEqual(address.Zip, "33782");
            Assert.AreEqual(address.State, "FL");

            // Now delete the person
            service.DeletePerson(insertedPersonFromUoW);

            // Make sure the person is deleted
            var deletedPerson = service.GetPersonById(insertedPersonFromUoW.PersonID, new PersonIncludes());

            Assert.IsNull(deletedPerson);
        }
        public void TestInsertPerson()
        {
            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 = 5,
                FirstName = "John",
                LastName = "Dorman",
                EmailAddress = "*****@*****.**", // Updated email address
                Phones = new List<Phone>
                {
                    new Phone
                    {
                        PersonID = 5,
                        Number = "813-657-2222",    // Update home phone
                        PhoneType = new PhoneType { Name = "Home", PhoneTypeID = 1 },
                        PhoneTypeID = 1
                    }
                },
                Addresses = new List<PersonAddressAssn>
                {
                    new PersonAddressAssn
                    {
                        Address = new Address
                        {
                            StreetAddress = "823 Newton Drive",   // Updated address
                            State = "FL",
                            Zip = "33782",
                            AddressID = 5,
                            City = "Pinellas Park"
                        },
                        AddressID = 5,
                        AddressType = new AddressType { Name = "Home", AddressTypeID = 1 },
                        AddressTypeID = 1,
                        PersonID = 5
                    }
                },
            };

            var opStatus = service.InsertPerson(person);

            var insertedPerson = (Person)opStatus.Data;

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

            // Get the inserted person object from the UoW
            var insertedPersonFromUoW = testUoW.Persons.GetQueryable().Where(p => p.PersonID == 5).First();

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

            // Verify that the home phone number was updated
            var homePhone = insertedPersonFromUoW.Phones.Where(p => p.PhoneTypeID == 1).FirstOrDefault();
            Assert.AreEqual(homePhone.Number, "813-657-2222");

            // Verify that there is no work number
            var workPhone = insertedPersonFromUoW.Phones.Where(p => p.PhoneTypeID == 2);
            Assert.AreEqual(workPhone.Count(), 0);

            // Verify that there is no cell number
            var cellPhone = insertedPersonFromUoW.Phones.Where(p => p.PhoneTypeID == 3);
            Assert.AreEqual(cellPhone.Count(), 0);

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

            Assert.AreEqual(address.StreetAddress, "823 Newton Drive");
            Assert.AreEqual(address.City, "Pinellas Park");
            Assert.AreEqual(address.Zip, "33782");
            Assert.AreEqual(address.State, "FL");
        }
Ejemplo n.º 4
0
        public void TestInsertPerson()
        {
            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     = 5,
                FirstName    = "John",
                LastName     = "Dorman",
                EmailAddress = "*****@*****.**", // Updated email address
                Phones       = new List <Phone>
                {
                    new Phone
                    {
                        PersonID  = 5,
                        Number    = "813-657-2222", // Update home phone
                        PhoneType = new PhoneType {
                            Name = "Home", PhoneTypeID = 1
                        },
                        PhoneTypeID = 1
                    }
                },
                Addresses = new List <PersonAddressAssn>
                {
                    new PersonAddressAssn
                    {
                        Address = new Address
                        {
                            StreetAddress = "823 Newton Drive",   // Updated address
                            State         = "FL",
                            Zip           = "33782",
                            AddressID     = 5,
                            City          = "Pinellas Park"
                        },
                        AddressID   = 5,
                        AddressType = new AddressType {
                            Name = "Home", AddressTypeID = 1
                        },
                        AddressTypeID = 1,
                        PersonID      = 5
                    }
                },
            };

            var opStatus = service.InsertPerson(person);

            var insertedPerson = (Person)opStatus.Data;

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

            // Get the inserted person object from the UoW
            var insertedPersonFromUoW = testUoW.Persons.GetQueryable().Where(p => p.PersonID == 5).First();

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

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

            Assert.AreEqual(homePhone.Number, "813-657-2222");

            // Verify that there is no work number
            var workPhone = insertedPersonFromUoW.Phones.Where(p => p.PhoneTypeID == 2);

            Assert.AreEqual(workPhone.Count(), 0);

            // Verify that there is no cell number
            var cellPhone = insertedPersonFromUoW.Phones.Where(p => p.PhoneTypeID == 3);

            Assert.AreEqual(cellPhone.Count(), 0);

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

            Assert.AreEqual(address.StreetAddress, "823 Newton Drive");
            Assert.AreEqual(address.City, "Pinellas Park");
            Assert.AreEqual(address.Zip, "33782");
            Assert.AreEqual(address.State, "FL");
        }