Exemplo n.º 1
0
 public void Initialize()
 {
     AutoMapperConfigurator.Configure();
     _repositoryMock = new Mock<IRepository<StoredUser>>();
     _storedUser = new StoredUser {Id = 0, Name = "name", MetaData = "metaData"};
     _user = new User {Id = 0, Name = "name", MetaData = "metaData"};
 }
Exemplo n.º 2
0
        /// <summary>
        ///     Creates a user with information from a userDTo
        /// </summary>
        /// <param name="user">User object</param>
        public async Task<int> Create(User user)
        {
            if (user == null)
                throw new ArgumentException("User is null");
            if (!UserValidator.ValidateEnteredUserInformation(user))
                throw new ArgumentException("Input may not be null, whitespace or empty");

            return await _storage.Create(user);
        }
Exemplo n.º 3
0
        /// <summary>
        ///     Edit and update an existing user
        /// </summary>
        /// <param name="oldId">id of user to update</param>
        /// <param name="user">User object</param>
        public async Task<bool> Update(int oldId, User user)
        {
            if (!UserValidator.ValidateId(oldId))
                throw new ArgumentException("Id is not valid");
            if (!UserValidator.ValidateEnteredUserInformation(user))
                throw new ArgumentException("User data is invalid");
            if (!UserValidator.ValidateExistence(oldId, _storage))
                throw new ArgumentException("User does not exist");

            return await _storage.UpdateIfExists(user);
        }
Exemplo n.º 4
0
        public void CreateUser_NewUser_Valid_Test()
        {
            //Arrange
            const string expectedName = "Name";
            const string expectedMeta = "metaData";

            //Act
            var user = new User {Name = expectedName, MetaData = expectedMeta};

            //Assert
            Assert.AreEqual(expectedName, user.Name, expectedMeta);
        }
Exemplo n.º 5
0
        public async void CreateUser_Invalid_userInformationEmptyString_Test()
        {
            //Arrange
            var user = new User {Name = "", MetaData = ""};
            _adapterMock.Setup(r => r.Create(user));
            var userHandler = new UserHandler(_adapterMock.Object);

            //Act
            var result = await userHandler.Create(user);

            //Assert
            //Exception must be thrown
        }
Exemplo n.º 6
0
        public void ReadAllTeams_Valid_CorrectNumberOfTeams_Test()
        {
            //Arrange
            var team1 = new User {Id = 0, Name = "User1", MetaData = "Meta1"};
            var team2 = new User {Id = 1, Name = "User2", MetaData = "Meta2"};
            var users = new List<User> {team1, team2};
            _adapterMock.Setup(r => r.Read()).Returns(users.AsQueryable());
            var userHandler = new UserHandler(_adapterMock.Object);

            //Act
            var actualUsers = userHandler.GetAll();
            var counter = actualUsers.Count();


            //Assert
            Assert.IsTrue(counter == users.Count);
        }
Exemplo n.º 7
0
 public void Initialize()
 {
     AutoMapperConfigurator.Configure();
     _adapterMock = new Mock<IAdapter<User, StoredUser>>();
     _user = new User {Id = 0, MetaData = "Meta", Name = "name"};
 }
Exemplo n.º 8
0
 /// <summary>
 ///     Validate user information
 /// </summary>
 /// <param name="user">User</param>
 /// <returns>validation of user information</returns>
 internal static bool ValidateEnteredUserInformation(User user)
 {
     return !string.IsNullOrWhiteSpace(user.Name) && !string.IsNullOrWhiteSpace(user.MetaData);
 }
Exemplo n.º 9
0
        /// <summary>
        ///     Method for creating a user with a state matching the given User object's
        /// </summary>
        /// <param name="user">
        ///     The given user to be created in the database
        /// </param>
        /// <returns>
        ///     A response message indicating the result of the request
        /// </returns>
        public HttpResponseMessage CreateUser(User user)
        {
            try
            {
                var userId = _userHandler.Create(user).Result;

                return CreateResponse(HttpStatusCode.OK);
            }
            catch (Exception exception)
            {
                return CreateResponse(HttpStatusCode.BadRequest, exception.Message);
            }

        }
Exemplo n.º 10
0
        /// <summary>
        ///     Tries to update the state of a user in the database with the given id to the state of the given user object.
        ///     The update returns true if the update is complete, false otherwise
        /// </summary>
        /// <param name="id">
        ///     The id of the user requested for update
        /// </param>
        /// <param name="user">
        ///     The user object with the state which the chosen User should be updated to
        /// </param>
        /// <returns>
        ///     A response message indicating the result of the request
        /// </returns>
        public HttpResponseMessage UpdateUser(int id, User user)
        {
            try
            {
                var result = _userHandler.Update(id, user).Result;

                return CreateResponse(result ? HttpStatusCode.OK : HttpStatusCode.BadRequest);
            }
            catch (Exception exception)
            {

                return CreateResponse(HttpStatusCode.BadRequest, exception.Message);
            }

        }