Example #1
0
            public async Task AutheficationWhenDataInvalid_ExpectedNotOKModel()
            {
                //Arrange
                var loginModel = new UserLoginViewModel()
                {
                    Email      = "*****@*****.**",
                    Password   = "",
                    RememberMe = false
                };

                var userManager = FakeTestingService.MockUserManager <User>(_users);

                userManager.Setup(m => m.FindByEmailAsync(It.IsAny <string>()))
                .ReturnsAsync(null as User);
                var signInManager = FakeTestingService.MockSightInManager <User>(userManager.Object);

                signInManager.Setup(m =>
                                    m.PasswordSignInAsync(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <bool>(), It.IsAny <bool>()))
                .ReturnsAsync(SignInResult.Success);


                var accaunt = new preparation.Controllers.AccountController(userManager.Object, signInManager.Object);

                string testRedirect = "/";
                //Actual
                var actual = await accaunt.Login(loginModel, testRedirect);

                //Assert
                var actualVuewResult = actual as ViewResult;

                NAssert.IsInstanceOf(typeof(ViewResult), actual);
                NAssert.IsAssignableFrom(typeof(UserLoginViewModel), actualVuewResult.ViewData.Model);
                NAssert.True(actualVuewResult.ViewData.ModelState.ErrorCount > 0);
            }
Example #2
0
            public async Task AutheficationWhenValidData_ExpectedOKModel()
            {
                //Arrange
                var loginModel = new UserLoginViewModel()
                {
                    Email      = "*****@*****.**",
                    Password   = "",
                    RememberMe = false
                };

                var userManager = FakeTestingService.MockUserManager <User>(_users);

                userManager.Setup(m => m.FindByEmailAsync(It.IsAny <string>()))
                .ReturnsAsync(_users[0]);
                var signInManager = FakeTestingService.MockSightInManager <User>(userManager.Object);

                signInManager.Setup(m =>
                                    m.PasswordSignInAsync(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <bool>(), It.IsAny <bool>()))
                .ReturnsAsync(SignInResult.Success);


                var accaunt = new preparation.Controllers.AccountController(userManager.Object, signInManager.Object);

                string testRedirect = "/";
                //Actual
                var actual = await accaunt.Login(loginModel, testRedirect);

                //Assert
                var actualVuewResult = Assert.IsType <RedirectToActionResult>(actual);
            }