Пример #1
0
        public void DeleteUserSuccessful()
        {
            //First, create a user with known id
            var repo = new UserRepository();
            var id = Guid.NewGuid().ToString();
            var user = new User
            {
                Id = id,
                FirstName = "Test",
                LastName = "Test",
                City = "Test",
                AddressLine1 = "Line 1",
                Country = "AUS",
                State = "state",
                Zip = "123456",
                Email = id + "@google.com"
            };

            var createdUser = repo.CreateUser(user);

            //Then, get user
            var gotUser = repo.GetUserById(id);
            Assert.IsNotNull(gotUser);
            Assert.AreEqual(gotUser.Id, id);

            //Now, delete user
            repo.DeleteUser(id);

            //And check whether user exists now
            var success = false;
            try
            {
                repo.GetUserById(id);
            }
            catch (UnauthorizedException)
            {
                success = true;
            }

            if (!success)
            {
                Assert.Fail("Delete user failed!");
            }
        }
Пример #2
0
        public User CreateUser(User user)
        {
            ValidateUser(user);
            var request = new RestRequest("/users", Method.POST);
            request.AddParameter("id", user.Id);
            request.AddParameter("first_name", user.FirstName);
            request.AddParameter("last_name", user.LastName);
            request.AddParameter("email", user.Email);
            request.AddParameter("mobile", user.Mobile);
            request.AddParameter("address_line1", user.AddressLine1);
            request.AddParameter("address_line2", user.AddressLine2);
            request.AddParameter("state", user.State);
            request.AddParameter("city", user.City);
            request.AddParameter("zip", user.Zip);
            request.AddParameter("country", user.Country);

            var response = SendRequest(Client, request);
            return JsonConvert.DeserializeObject<IDictionary<string,User>>(response.Content).Values.First();
        }
Пример #3
0
        public void EditUserMissingId()
        {
            var repo = new UserRepository();
            var id = Guid.NewGuid().ToString();
            var user = new User
            {
                Id = id,
                FirstName = "Test",
                LastName = "Test",
                City = "Test",
                AddressLine1 = "Line 1",
                Country = "AUS",
                State = "state",
                Zip = "123456",
                Email = id + "@google.com"
            };

            repo.UpdateUser(user);
        }
Пример #4
0
 public void ValidationErrorUserCreateWrongEmail()
 {
     var repo = new UserRepository();
     var id = Guid.NewGuid().ToString();
     var user = new User
     {
         Id = id,
         FirstName = "Test",
         LastName = "Test",
         City = "Test",
         AddressLine1 = "Line 1",
         Country = "AUS",
         State = "state",
         Zip = "123456",
         Email = id
     };
     repo.CreateUser(user);
 }
Пример #5
0
 public void ValidationErrorUserCreateWrongCountry()
 {
     var repo = new UserRepository();
     var id = Guid.NewGuid().ToString();
     var user = new User
     {
         Id = id,
         FirstName = "Test",
         LastName = "Test",
         City = "Test",
         AddressLine1 = "Line 1",
         Country = "Australia", //Not a correct ISO code
         State = "state",
         Zip = "123456",
         Email = id + "@google.com"
     };
     repo.CreateUser(user);
 }
Пример #6
0
        public void UserCreateSuccessful()
        {
            var repo = new UserRepository();
            var id = Guid.NewGuid().ToString();
            var user = new User
            {
                Id = id,
                FirstName = "Test",
                LastName = "Test",
                City = "Test",
                AddressLine1 = "Line 1",
                Country = "AUS",
                State = "state",
                Zip = "123456",
                Email = id + "@google.com"
            };

            var createdUser = repo.CreateUser(user);

            Assert.AreEqual(user.Id, createdUser.Id);
            Assert.AreEqual(user.FirstName, createdUser.FirstName);
            Assert.AreEqual(user.LastName, createdUser.LastName);
            Assert.AreEqual("Test Test", createdUser.FullName);
            Assert.AreEqual(user.Email, createdUser.Email);
            Assert.IsTrue(createdUser.CreatedAt.HasValue);
            Assert.IsTrue(createdUser.UpdatedAt.HasValue);
        }
Пример #7
0
        public void ListUsersSuccessful()
        {
            //First, create a user, so we'll have at least one
            var repo = new UserRepository();
            var id = Guid.NewGuid().ToString();
            var user = new User
            {
                Id = id,
                FirstName = "Test",
                LastName = "Test",
                City = "Test",
                AddressLine1 = "Line 1",
                Country = "AUS",
                State = "state",
                Zip = "123456",
                Email = id + "@google.com"
            };

            var createdUser = repo.CreateUser(user);

            //Then, list users
            var users = repo.ListUsers(200);

            Assert.IsNotNull(users);
            Assert.IsTrue(users.Any());
            Assert.IsTrue(users.Any(x => x.Id == id));
        }
Пример #8
0
        public void GetUserSuccessful()
        {
            //First, create a user with known id
            var repo = new UserRepository();
            var id = Guid.NewGuid().ToString();
            var user = new User
            {
                Id = id,
                FirstName = "Test",
                LastName = "Test",
                City = "Test",
                AddressLine1 = "Line 1",
                Country = "AUS",
                State = "state",
                Zip = "123456",
                Email = id + "@google.com"
            };

            var createdUser = repo.CreateUser(user);

            //Then, get user
            var gotUser = repo.GetUserById(id);

            Assert.IsNotNull(gotUser);
            Assert.AreEqual(gotUser.Id, id);
        }
Пример #9
0
        public void EditUserSuccessful()
        {
            //First, create a user we'll work with
            var repo = new UserRepository();
            var id = Guid.NewGuid().ToString();
            var user = new User
            {
                Id = id,
                FirstName = "Test",
                LastName = "Test",
                City = "Test",
                AddressLine1 = "Line 1",
                Country = "AUS",
                State = "state",
                Zip = "123456",
                Email = id + "@google.com"
            };

            var createdUser = repo.CreateUser(user);

            //Now, try to edit newly created user
            user.FirstName = "Test123";
            user.LastName = "Test123";
            var modifiedUser = repo.UpdateUser(user);

            Assert.AreEqual("Test123", modifiedUser.FirstName);
            Assert.AreEqual("Test123", modifiedUser.LastName);
        }
 private void ValidateUser(User user)
 {
     if (String.IsNullOrEmpty(user.Id))
     {
         throw new ValidationException("Field User.ID should not be empty!");
     }
     if (String.IsNullOrEmpty(user.FirstName))
     {
         throw new ValidationException("Field User.FirstName should not be empty!");
     }
     if (!IsCorrectCountryCode(user.Country))
     {
         throw new ValidationException("Field User.Country should contain 3-letter ISO country code!");
     }
     if (!IsCorrectEmail(user.Email))
     {
         throw new ValidationException("Field User.Email should contain correct email address!");
     }
 }