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); }
public async Task RegisterWhenDataInvalid_ExpectedNotChangeBD() { //Arrange var userManager = FakeTestingService.MockUserManager <User>(_users); userManager.Setup(_ => _.CreateAsync(It.IsAny <User>(), It.IsAny <string>())).ReturnsAsync(IdentityResult.Failed()); var signInManager = FakeTestingService.MockSightInManager <User>(userManager.Object); var accaunt = new preparation.Controllers.AccountController(userManager.Object, signInManager.Object); var regModel = new UserRegisterViewModel() { Address = "test", AgreementConfirm = false, Country = "test", Email = "test", FirstName = "test", Password = "******", Username = "******", Surname = "test", PasswordConfirm = "test" }; string testRedirect = "/"; //Actual var actual = await accaunt.Register(regModel, testRedirect); //Assert Assert.Equal(2, _users.Count); var model = Assert.IsType <ViewResult>(actual); Assert.IsAssignableFrom <UserRegisterViewModel>(model.ViewData.Model); }
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); }
public async Task RegisterWhenValidData_ExpectedOKBeheivior() { //Arrange var userManager = FakeTestingService.MockUserManager <User>(_users); var signInManager = FakeTestingService.MockSightInManager <User>(userManager.Object); var accaunt = new preparation.Controllers.AccountController(userManager.Object, signInManager.Object); var regModel = new UserRegisterViewModel() { Address = "test", AgreementConfirm = false, Country = "test", Email = "test", FirstName = "test", Password = "******", Username = "******", Surname = "test", PasswordConfirm = "test" }; string testRedirect = "/"; int expectedCount = 3; //Actual var actual = await accaunt.Register(regModel, testRedirect); //Assert Assert.Equal(expectedCount, _users.Count); }