Ejemplo n.º 1
0
        public void DeleteUser()
        {
            // Arrange
            ExternalService exService = new ExternalService();
            UserService service = new UserService(exService);

            using (var _session = DBSetup())
            {
                var userModel = new User()
                {
                    FirstName = "TestFN",
                    LastName = "TestLN",
                    Email = "*****@*****.**",
                    StreetAddress = "TestSA",
                    City = "TestCity",
                    State = "TestState",
                    Zip = "99999"
                };
                _session.Store(userModel);
                _session.SaveChanges();

                // Act
                string result = service.DeleteUser(_session, "users/1");

                // Assert
                Assert.IsNotNull(result);

                var user = _session.Load<User>(result);

                Assert.IsNull(user);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Adds the user.
        /// </summary>
        /// <param name="ravenSession">The raven session.</param>
        /// <param name="model">The model.</param>
        /// <returns>The identifier of the added user.</returns>
        public string AddUser(IDocumentSession ravenSession, User model)
        {
            if (!String.IsNullOrEmpty(model.StreetAddress)
                && !String.IsNullOrEmpty(model.City)
                && !String.IsNullOrEmpty(model.State)
                && !String.IsNullOrEmpty(model.Zip))
            {
                var addrStr = ExternalService.GetAddressStrFromObject(model);
                model.Coordinates = ExternalService.GetCoordinatesFromAddress(addrStr);
            }

            ravenSession.Store(model);
            ravenSession.SaveChanges();

            return model.Id;
        }
Ejemplo n.º 3
0
        public void GetAddressStrFromObject()
        {
            // Arrange
            ExternalService service = new ExternalService();

            var userModel = new User()
            {
                FirstName = "TestFN",
                LastName = "TestLN",
                Email = "*****@*****.**",
                StreetAddress = "TestSA",
                City = "TestCity",
                State = "TestState",
                Zip = "99999"
            };

            // Act
            var result = service.GetAddressStrFromObject(userModel);

            // Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(result, "TestSA, TestCity, TestState 99999");
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Gets the address string from object.
 /// </summary>
 /// <param name="model">The model.</param>
 /// <returns>The address.</returns>
 public string GetAddressStrFromObject(User model)
 {
     return model.StreetAddress + ", " + model.City + ", " + model.State + " " + model.Zip;
 }
Ejemplo n.º 5
0
        /// <summary>
        /// Updates the user.
        /// </summary>
        /// <param name="ravenSession">The raven session.</param>
        /// <param name="model">The model.</param>
        /// <returns>The updated user.</returns>
        public User UpdateUser(IDocumentSession ravenSession, User model)
        {
            var currentDbModel = ravenSession.Load<User>(model.Id);

            if (currentDbModel == null)
            {
                return null;
            }

            currentDbModel.FirstName = model.FirstName;
            currentDbModel.LastName = model.LastName;
            currentDbModel.Email = model.Email;

            if (currentDbModel.StreetAddress != model.StreetAddress
                || currentDbModel.City != model.City
                || currentDbModel.State != model.State
                || currentDbModel.Zip != model.Zip)
            {
                var addrStr = ExternalService.GetAddressStrFromObject(model);
                currentDbModel.Coordinates = ExternalService.GetCoordinatesFromAddress(addrStr);
            }

            currentDbModel.StreetAddress = model.StreetAddress;
            currentDbModel.City = model.City;
            currentDbModel.State = model.State;
            currentDbModel.Zip = model.Zip;

            ravenSession.SaveChanges();

            return currentDbModel;
        }
Ejemplo n.º 6
0
        public void UpdateUserFail()
        {
            // Arrange
            ExternalService exService = new ExternalService();
            UserService service = new UserService(exService);

            using (var _session = DBSetup())
            {
                var changeUserModel = new User()
                {
                    Id = "users/1",
                    FirstName = "TestFN",
                    LastName = "TestLN",
                    Email = "*****@*****.**",
                    StreetAddress = "NEWTestSA",
                    City = "TestCity",
                    State = "TestState",
                    Zip = "99999"
                };

                // Act
                User result = service.UpdateUser(_session, changeUserModel);

                // Assert
                Assert.IsNull(result);
            }
        }
Ejemplo n.º 7
0
        public void UpdateUser()
        {
            // Arrange
            ExternalService exService = new ExternalService();
            UserService service = new UserService(exService);

            using (var _session = DBSetup())
            {
                var userModel = new User()
                {
                    FirstName = "TestFN",
                    LastName = "TestLN",
                    Email = "*****@*****.**",
                    StreetAddress = "TestSA",
                    City = "TestCity",
                    State = "TestState",
                    Zip = "99999"
                };
                _session.Store(userModel);
                _session.SaveChanges();

                var changeUserModel = new User()
                {
                    Id = userModel.Id,
                    FirstName = "TestFN",
                    LastName = "TestLN",
                    Email = "*****@*****.**",
                    StreetAddress = "NEWTestSA",
                    City = "TestCity",
                    State = "TestState",
                    Zip = "99999"
                };

                // Act
                User result = service.UpdateUser(_session, changeUserModel);

                // Assert
                Assert.IsNotNull(result);
                Assert.AreEqual(result.Id, "users/1");
                Assert.AreEqual(result.StreetAddress, "NEWTestSA");
            }
        }
Ejemplo n.º 8
0
        public void GetAllUsers()
        {
            // Arrange
            ExternalService exService = new ExternalService();
            UserService service = new UserService(exService);

            using (var _session = DBSetup())
            {
                var userModel1 = new User()
                {
                    FirstName = "TestFN1",
                    LastName = "TestLN1",
                    Email = "*****@*****.**",
                    StreetAddress = "TestSA1",
                    City = "TestCity1",
                    State = "TestState1",
                    Zip = "99998"
                };
                _session.Store(userModel1);

                var userModel2 = new User()
                {
                    FirstName = "TestFN2",
                    LastName = "TestLN2",
                    Email = "*****@*****.**",
                    StreetAddress = "TestSA2",
                    City = "TestCity2",
                    State = "TestState2",
                    Zip = "99999"
                };
                _session.Store(userModel2);
                _session.SaveChanges();

                // Act
                List<User> result = service.GetAllUsers(_session);

                // Assert
                Assert.IsNotNull(result);
                Assert.AreEqual(result.Count, 2);
            }
        }