Пример #1
0
        public void UpdateUserData_PositiveUserTestCases_TestResults()
        {
            //Assign
            var user = new UserPutHelp()
            {
                UserId          = 53,
                UserName        = "******",
                UserAddress     = "Admin",
                UserPhoneNumber = "9999999999",
            };
            var UserList = new List <UserPutHelp>();

            UserList.Add(user);

            var _mockUserMethod = new Mock <UserManager>();
            var _returnAckType  = new Acknowledgement <UserPutHelp>
            {
                code    = 1,
                Set     = UserList,
                Message = "Successfully updated."
            };

            _mockUserMethod.Setup(p => p.UpdateUser(user)).Returns(_returnAckType);
            UserController _userController = new UserController(_mockUserMethod.Object);
            //Act
            var _actualReturnType = _userController.UpdateUserData(user) as OkObjectResult;

            //Assert
            Assert.ReferenceEquals(_returnAckType, _actualReturnType.Value);
        }
Пример #2
0
        public void UpdateUserData_NegativeTestCases_TestResults()
        {
            //Assign
            var user = new UserPutHelp()
            {
                UserId          = 1,
                UserName        = "******",
                UserAddress     = "Admin",
                UserPhoneNumber = "9999999999",
            };
            var _returnAckType = new Acknowledgement <UserPutHelp>
            {
                code    = 3,
                Set     = null,
                Message = "Something went wrong. Please try again later"
            };
            var _mockUserMethod = new Mock <UserManager>();

            _mockUserMethod.Setup(p => p.UpdateUser(user)).Throws <System.Exception>();
            UserController _userController = new UserController(_mockUserMethod.Object);
            //Act
            var _actualReturnType = _userController.UpdateUserData(user) as OkObjectResult;

            //Assert
            Assert.ReferenceEquals(_returnAckType, _actualReturnType.Value);
        }
Пример #3
0
        public void UpdateUser_Positive_TestsReturned()
        {
            //Assign
            UserPutHelp userUpdateHelp = new UserPutHelp()
            {
                UserId          = 53,
                UserName        = "******",
                UserAddress     = "Admin",
                UserPhoneNumber = "9999999999"
            };
            List <UserPutHelp> userPutHelps = new List <UserPutHelp>();

            userPutHelps.Add(userUpdateHelp);
            var _returnAckType = new Acknowledgement <UserPutHelp>
            {
                code    = 1,
                Set     = userPutHelps,
                Message = "Successfully updated."
            };
            var _mockUserservice = new Mock <UserService>();

            _mockUserservice.Setup(p => p.UpdateUser(userUpdateHelp));
            UserManager _userManager = new UserManager(_mockUserservice.Object);
            //Act
            var _actualReturnType = _userManager.UpdateUser(userUpdateHelp);

            //Assert
            Assert.ReferenceEquals(_returnAckType, _actualReturnType);
        }
Пример #4
0
        public void UpdateUser_Negative_Exception_TestsReturned()
        {
            //Assign
            UserPutHelp userUpdateHelp = new UserPutHelp()
            {
                UserId          = 53,
                UserName        = "******",
                UserAddress     = "Admin",
                UserPhoneNumber = "9999999999"
            };
            List <UserPutHelp> userPutHelps = new List <UserPutHelp>();

            userPutHelps.Add(userUpdateHelp);
            var _mockUserservice = new Mock <UserService>();

            _mockUserservice.Setup(p => p.UpdateUser(userUpdateHelp)).Throws <System.Exception>();
            UserManager _userManager = new UserManager(_mockUserservice.Object);

            //Act
            try
            {
                var _actualReturnType = _userManager.UpdateUser(userUpdateHelp);
                //Assert
                //Assert.ReferenceEquals(_returnAckType, _actualReturnType);
                Assert.IsTrue(false);
            }
            catch
            {
                Assert.IsTrue(true);
            }
        }
Пример #5
0
        public void UpdateUser_Negative_PhoneMisMatch_TestsReturned()
        {
            //Assign
            UserPutHelp userUpdateHelp = new UserPutHelp()
            {
                UserId          = 53,
                UserName        = "******",
                UserAddress     = "Admin",
                UserPhoneNumber = "99999999aa"
            };
            List <UserPutHelp> userPutHelps = new List <UserPutHelp>();

            userPutHelps.Add(userUpdateHelp);
            var _returnAckType = new Acknowledgement <UserPutHelp>
            {
                code    = 2,
                Set     = userPutHelps,
                Message = "mobile number is invalid it should start with 9/8/7/6 and of length 10."
            };
            UserManager _userManager = new UserManager();
            //Act
            var _actualReturnType = _userManager.UpdateUser(userUpdateHelp);

            //Assert
            Assert.ReferenceEquals(_returnAckType, _actualReturnType);
        }
Пример #6
0
        public void UpdateUser_Negative_AddressEmpty_TestsReturned()
        {
            //Assign
            UserPutHelp userUpdateHelp = new UserPutHelp()
            {
                UserId          = 53,
                UserName        = "******",
                UserAddress     = "    ",
                UserPhoneNumber = "9999999999"
            };
            List <UserPutHelp> userPutHelps = new List <UserPutHelp>();

            userPutHelps.Add(userUpdateHelp);
            var _returnAckType = new Acknowledgement <UserPutHelp>
            {
                code    = 2,
                Set     = userPutHelps,
                Message = "Address field should not empty"
            };
            UserManager _userManager = new UserManager();
            //Act
            var _actualReturnType = _userManager.UpdateUser(userUpdateHelp);

            //Assert
            Assert.ReferenceEquals(_returnAckType, _actualReturnType);
        }
Пример #7
0
        public void UpdateUser_Negative_NameMisMatch_TestsReturned()
        {
            //Assign
            UserPutHelp userUpdateHelp = new UserPutHelp()
            {
                UserId          = 53,
                UserName        = "******",
                UserAddress     = "Admin",
                UserPhoneNumber = "9999999999"
            };
            List <UserPutHelp> userPutHelps = new List <UserPutHelp>();

            userPutHelps.Add(userUpdateHelp);
            var _returnAckType = new Acknowledgement <UserPutHelp>
            {
                code    = 2,
                Set     = userPutHelps,
                Message = "Username is invalid it should consists only characters."
            };
            UserManager _userManager = new UserManager();
            //Act
            var _actualReturnType = _userManager.UpdateUser(userUpdateHelp);

            //Assert
            Assert.ReferenceEquals(_returnAckType, _actualReturnType);
        }
Пример #8
0
        public string ValidateUser(UserPutHelp user)
        {
            Regex Name         = new Regex(@"^[a-zA-Z\s]*$");
            Regex MobileNumber = new Regex(@"[6/7/8/9]{1}[0-9]{9}$");

            int Count1 = 0;

            foreach (var item in signup.Getdata())
            {
                if ((item.UserId == user.UserId))
                {
                    Count1++;
                }
            }
            if (Count1 == 0)
            {
                return("UserID does not exist");
            }
            if (!Name.IsMatch(user.UserName))
            {
                return("Username is invalid it should consists only characters.");
            }
            else if (!MobileNumber.IsMatch(user.UserPhoneNumber))
            {
                return("mobile number is invalid it should start with 9/8/7/6 and of length 10.");
            }
            else
            {
                return("success");
            }
        }
Пример #9
0
        public virtual Acknowledgement <UserPutHelp> UpdateUser(UserPutHelp user)
        {
            Acknowledgement <UserPutHelp> acknowledgement = new Acknowledgement <UserPutHelp>();

            try
            {
                List <UserPutHelp> users = new List <UserPutHelp>();
                users.Add(user);
                string validator = ValidateUser(user);
                if (!validator.Equals("success"))
                {
                    acknowledgement.code    = 2;
                    acknowledgement.Set     = users;
                    acknowledgement.Message = validator;
                    return(acknowledgement);
                }
                else
                {
                    string name    = user.UserName.Trim();
                    string address = user.UserAddress.Trim();
                    if ((name.Equals("")) && (address.Equals("")))
                    {
                        acknowledgement.code    = 2;
                        acknowledgement.Set     = users;
                        acknowledgement.Message = "Username field and address field should not empty";
                        return(acknowledgement);
                    }
                    if (name.Equals(""))
                    {
                        acknowledgement.code    = 2;
                        acknowledgement.Set     = users;
                        acknowledgement.Message = "Fullname field should not empty";
                        return(acknowledgement);
                    }
                    if (address.Equals(""))
                    {
                        acknowledgement.code    = 2;
                        acknowledgement.Set     = users;
                        acknowledgement.Message = "Address field should not be empty";
                        return(acknowledgement);
                    }

                    acknowledgement.code    = 1;
                    acknowledgement.Set     = users;
                    acknowledgement.Message = "Successfully updated.";
                    signup.UpdateUser(user);
                    return(acknowledgement);
                }
            }
            catch (Exception e)
            {
                throw e;
            }
        }
Пример #10
0
 public IActionResult UpdateUserData([FromBody] UserPutHelp user)
 {
     try
     {
         return(Ok(usermanager.UpdateUser(user)));
     }
     catch (Exception)
     {
         aknowledgement.code    = 3;
         aknowledgement.Set     = null;
         aknowledgement.Message = "Something went wrong. Please try again later";
         return(Ok(aknowledgement));
     }
 }
Пример #11
0
 public virtual void UpdateUser(UserPutHelp user)
 {
     try
     {
         User users = roomDb.FMRUsers.Find(user.UserId);
         if (users == null)
         {
             return;
         }
         users.UserId          = user.UserId;
         users.UserName        = user.UserName;
         users.UserAddress     = user.UserAddress;
         users.UserPhoneNumber = user.UserPhoneNumber;
         roomDb.SaveChanges();
     }
     catch (Exception e)
     {
         throw e;
     }
 }