public void AddUser_ReturnsFalse_WhenCalled_IfEmailProvidedBelongsToAUserOnTheSystem()
        {
            //Arrange
            string TestFirstName = "Joe";
            string TestLastName  = "Bloggs";
            string TestEmail     = "*****@*****.**";
            string TestPassword  = "******";
            bool   expected      = false;

            User TestUser = new User {
                Email = TestEmail
            };
            List <User> TestUsers = new List <User> {
                TestUser
            };

            Mock <ICRUD_Operations> MockCRUD = new Mock <ICRUD_Operations>();

            MockCRUD.Setup(x => x.GetAllUsers()).Returns(TestUsers);

            UserManagementService UserMgmtService = new UserManagementService(MockCRUD.Object);

            //Act
            bool actual = UserMgmtService.AddUser(TestFirstName, TestLastName, TestEmail, TestPassword);

            //Assert
            Assert.AreEqual(expected, actual);
        }
 public IActionResult Register([FromBody] RegisterRequest request)
 {
     try
     {
         _service.AddUser(request.Login, request.Password);
         return(Ok());
     }
     catch (LoginTakenError)
     {
         return(StatusCode(StatusCodes.Status409Conflict, new
         {
             message = "Указанный логин уже занят"
         }));
     }
     catch (InvalidParamsError)
     {
         return(StatusCode(StatusCodes.Status400BadRequest, new
         {
             message = "Логин и пароль обязательны для ввода"
         }));
     }
     catch (Exception e)
     {
         return(StatusCode(StatusCodes.Status500InternalServerError, new { message = e.Message }));
     }
 }
Example #3
0
        public void UserService_AddUser_SavesAUserToSession()
        {
            _session = A.Fake <ISession>();
            _userManagementService = new UserManagementService(_session);
            var user = new User();

            _userManagementService.AddUser(user);

            A.CallTo(() => _session.Save(user)).MustHaveHappened();
        }
        private void AddUserbutton_Click(object sender, EventArgs e)
        {
            if (userMgmt.AddUser(fNametextBox.Text, lNametextBox.Text, Email_textBox.Text,
                                 Password_textBox.Text) == true)
            {
                UserMgmt.LoadUsers();
                MessageBox.Show("New user " + fNametextBox.Text + " " + lNametextBox.Text
                                + " has been successfully added to the system.");
                this.Close();
            }

            else
            {
                MessageBox.Show("Failed to add new user to the system. A user already exists "
                                + "on the system with the email that you have provided.");
                this.Close();
            }
        }
        public void AddUser_CallsGetAllUsers_ExactlyOnce_WhenCalled()
        {
            //Arrange
            string TestFirstName = "Joe";
            string TestLastName  = "Bloggs";
            string TestEmail     = "*****@*****.**";
            string TestPassword  = "******";

            Mock <ICRUD_Operations> MockCRUD = new Mock <ICRUD_Operations>();

            MockCRUD.Setup(x => x.GetAllUsers()).Returns(new List <User>());

            UserManagementService UserMgmtService = new UserManagementService(MockCRUD.Object);

            //Act
            UserMgmtService.AddUser(TestFirstName, TestLastName, TestEmail, TestPassword);

            //Assert
            MockCRUD.Verify(x => x.GetAllUsers(), Times.Once);
        }
        public void AddUser_Calls_InsertUser_PassingDetailsProvided_ExactlyOnce_WhenCalled_IfEmailDoesNotBelongToAUserOnSystem()
        {
            //Arrange
            string TestFirstName = "Joe";
            string TestLastName  = "Bloggs";
            string TestEmail     = "*****@*****.**";
            string TestPassword  = "******";

            Mock <ICRUD_Operations> MockCRUD = new Mock <ICRUD_Operations>();

            MockCRUD.Setup(x => x.GetAllUsers()).Returns(new List <User>());

            UserManagementService UserMgmtService = new UserManagementService(MockCRUD.Object);

            //Act
            UserMgmtService.AddUser(TestFirstName, TestLastName, TestEmail, TestPassword);

            //Assert
            MockCRUD.Verify(x => x.InsertUser(TestFirstName, TestLastName,
                                              TestEmail, TestPassword));
        }