public void PostUser_Negative_TestResults()
        {
            var           _mockBussinessMethod = new Mock <UserManager>();
            var           _usermanager         = new UserManager();
            HelperAddUser user           = GetUsers_Mock_Negative();
            var           _returnAskType = new Acknowledgement <User>
            {
                code    = 0,
                Set     = null,
                Message = "Something went wrong please try again later"
            };

            try
            {
                _mockBussinessMethod.Setup(p => p.PostUser(user)).Throws <System.Exception>();

                //Act
                var _actualReturnType = _usermanager.PostUser(user) as Acknowledgement <User>;

                //Assert
                Assert.AreEqual(_returnAskType, _actualReturnType);
                Assert.IsTrue(false);
            }
            catch (Exception)
            {
                Assert.IsTrue(true);
            }
        }
Exemple #2
0
        public HelperAddUser GetUsers_Mock_Negative()
        {
            HelperAddUser user = new HelperAddUser();

            user.UserName     = "******";
            user.Email        = "*****@*****.**";
            user.MobileNumber = "9876543210";
            user.Address      = "asdfghjklqwertyui";
            user.Password     = "******";
            user.Type         = "partner";
            return(user);
        }
        public User GetUser(HelperAddUser helperAddUser)
        {
            User user = new User
            {
                UserName        = helperAddUser.UserName,
                UserEmail       = helperAddUser.Email,
                UserPhoneNumber = helperAddUser.MobileNumber,
                UserAddress     = helperAddUser.Address,
                UserPassword    = helperAddUser.Password,
                UserType        = helperAddUser.Type,
                UserStatus      = "valid"
            };

            return(user);
        }
Exemple #4
0
        public IActionResult PostUser(HelperAddUser addUser)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }

                return(Ok(usermanager.PostUser(addUser)));
            }

            catch (Exception)
            {
                aknowledgement.code    = 2;
                aknowledgement.Set     = null;
                aknowledgement.Message = "Something went wrong. Please try again later";
                return(Ok(aknowledgement));
            }
        }
        public void PostUser_Negative_AlreadyExists()
        {
            var           _mockBussinessMethod = new Mock <UserManager>();
            var           _usermanager         = new UserManager();
            HelperAddUser user           = GetUsers_Mock_Negative();
            var           _returnAskType = new Acknowledgement <User>
            {
                code    = 2,
                Set     = null,
                Message = "This account already exists."
            };

            _mockBussinessMethod.Setup(p => p.PostUser(user)).Returns(_returnAskType);

            //Act
            var _actualReturnType = _usermanager.PostUser(user) as Acknowledgement <User>;

            //Assert
            Assert.ReferenceEquals(_returnAskType, _actualReturnType);
        }
        public void PostUser_Positive_Testresults()
        {
            var           _mockBussinessMethod = new Mock <UserManager>();
            var           _usermanager         = new UserManager();
            HelperAddUser user = GetUsers_Mock_Negative();

            user.Email = "*****@*****.**";
            var _returnAskType = new Acknowledgement <User>
            {
                code    = 0,
                Set     = null,
                Message = "Successfully Registered."
            };

            _mockBussinessMethod.Setup(p => p.PostUser(user)).Returns(_returnAskType);

            //Act
            var _actualReturnType = _usermanager.PostUser(user) as Acknowledgement <User>;

            //Assert
            Assert.ReferenceEquals(_returnAskType, _actualReturnType);
        }
        public void PostUser_Negative_Address()
        {
            var           _mockBussinessMethod = new Mock <UserManager>();
            var           _usermanager         = new UserManager();
            HelperAddUser user = GetUsers_Mock_Negative();

            user.Address = "      ";
            var _returnAskType = new Acknowledgement <User>
            {
                code    = 2,
                Set     = null,
                Message = "Address field should not be empty"
            };

            _mockBussinessMethod.Setup(p => p.PostUser(user)).Returns(_returnAskType);

            //Act
            var _actualReturnType = _usermanager.PostUser(user) as Acknowledgement <User>;

            //Assert
            Assert.ReferenceEquals(_returnAskType, _actualReturnType);
        }
        public void PostUser_Negative_UsersType()
        {
            var           _mockBussinessMethod = new Mock <UserManager>();
            var           _usermanager         = new UserManager();
            HelperAddUser user = GetUsers_Mock_Negative();

            user.Type = "admin";
            var _returnAskType = new Acknowledgement <User>
            {
                code    = 2,
                Set     = null,
                Message = "user type should be either partner or renter"
            };

            _mockBussinessMethod.Setup(p => p.PostUser(user)).Returns(_returnAskType);

            //Act
            var _actualReturnType = _usermanager.PostUser(user) as Acknowledgement <User>;

            //Assert
            Assert.ReferenceEquals(_returnAskType, _actualReturnType);
        }
        public void PostUser_Negative_UsersPassword()
        {
            var           _mockBussinessMethod = new Mock <UserManager>();
            var           _usermanager         = new UserManager();
            HelperAddUser user = GetUsers_Mock_Negative();

            user.Password = "******";
            var _returnAskType = new Acknowledgement <User>
            {
                code    = 2,
                Set     = null,
                Message = "password is invalid, It should consists atleast one Uppercase,special character and number of length more than 7"
            };

            _mockBussinessMethod.Setup(p => p.PostUser(user)).Returns(_returnAskType);

            //Act
            var _actualReturnType = _usermanager.PostUser(user) as Acknowledgement <User>;

            //Assert
            Assert.ReferenceEquals(_returnAskType, _actualReturnType);
        }
        public void PostUser_Negative_UsersPhoneNo()
        {
            var           _mockBussinessMethod = new Mock <UserManager>();
            var           _usermanager         = new UserManager();
            HelperAddUser user = GetUsers_Mock_Negative();

            user.MobileNumber = "1234567890";
            var _returnAskType = new Acknowledgement <User>
            {
                code    = 2,
                Set     = null,
                Message = "mobile number is invalid it should start with 9/8/7/6 and of length 10."
            };

            _mockBussinessMethod.Setup(p => p.PostUser(user)).Returns(_returnAskType);

            //Act
            var _actualReturnType = _usermanager.PostUser(user) as Acknowledgement <User>;

            //Assert
            Assert.ReferenceEquals(_returnAskType, _actualReturnType);
        }
        public void PostUser_Negative_UsersEmail()
        {
            var           _mockBussinessMethod = new Mock <UserManager>();
            var           _usermanager         = new UserManager();
            HelperAddUser user = GetUsers_Mock_Negative();

            user.Email = "shravani@er";
            var _returnAskType = new Acknowledgement <User>
            {
                code    = 2,
                Set     = null,
                Message = "email is invalid"
            };

            _mockBussinessMethod.Setup(p => p.PostUser(user)).Returns(_returnAskType);

            //Act
            var _actualReturnType = _usermanager.PostUser(user) as Acknowledgement <User>;

            //Assert
            Assert.ReferenceEquals(_returnAskType, _actualReturnType);
        }
        public void PostUser_Negative_UserName()
        {
            var           _mockBussinessMethod = new Mock <UserManager>();
            var           _usermanager         = new UserManager();
            HelperAddUser user = GetUsers_Mock_Negative();

            user.UserName = "******";
            var _returnAskType = new Acknowledgement <User>
            {
                code    = 2,
                Set     = null,
                Message = "Username is invalid it should consists only characters."
            };

            _mockBussinessMethod.Setup(p => p.PostUser(user)).Returns(_returnAskType);

            //Act
            var _actualReturnType = _usermanager.PostUser(user) as Acknowledgement <User>;

            //Assert
            Assert.ReferenceEquals(_returnAskType, _actualReturnType);
        }
Exemple #13
0
        //This method will do validations for existance of email and type of partner and if not exists it inserts data.
        public virtual Acknowledgement <User> PostUser(HelperAddUser adduser)
        {
            User user  = new User();
            int  count = 0;

            try
            {
                user.UserName        = adduser.UserName;
                user.UserEmail       = adduser.Email;
                user.UserPhoneNumber = adduser.MobileNumber;
                user.UserAddress     = adduser.Address;
                user.UserPassword    = adduser.Password;
                user.UserType        = adduser.Type;
                user.UserStatus      = "valid";
                List <User> users = new List <User>();
                users.Add(user);
                string validator = validations(user);
                if (!validator.Equals("success"))
                {
                    acknowledgement.code    = 2;
                    acknowledgement.Set     = null;
                    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     = null;
                        acknowledgement.Message = "Username field and address field should not empty";
                        return(acknowledgement);
                    }
                    if (name.Equals(""))
                    {
                        acknowledgement.code    = 2;
                        acknowledgement.Set     = null;
                        acknowledgement.Message = "Fullname field should not empty";
                        return(acknowledgement);
                    }
                    if (address.Equals(""))
                    {
                        acknowledgement.code    = 2;
                        acknowledgement.Set     = null;
                        acknowledgement.Message = "Address field should not be empty";
                        return(acknowledgement);
                    }
                    foreach (var item in signup.Getdata())
                    {
                        if ((item.UserEmail.Equals(user.UserEmail, StringComparison.OrdinalIgnoreCase)))
                        {
                            count++;
                        }
                    }
                    if (count == 0)
                    {
                        PasswordHashing hash     = new PasswordHashing();
                        string          password = "";
                        acknowledgement.code    = 0;
                        acknowledgement.Set     = null;
                        acknowledgement.Message = "Successfully Registered.";
                        password          = hash.CreatePasswordSalt(user.UserPassword);
                        user.UserPassword = password;
                        signup.PostUser(user);
                        return(acknowledgement);
                    }

                    else
                    {
                        acknowledgement.code    = 2;
                        acknowledgement.Set     = null;
                        acknowledgement.Message = "This account already exists.";
                        return(acknowledgement);
                    }
                    //return acknowledgement;
                }
            }

            catch (Exception e)
            {
                throw e;
            }
        }