public void UserCanViewTheirCurrentDetails() { var userDetails = new UserDetailsResponseDTO { Id = Guid.NewGuid(), Username = "******", Name = "John Polling", Email = "*****@*****.**" }; var authenticatedUser = new AuthenticatedUserDTO {Id = Guid.NewGuid(), Type = UserType.Administrator}; var fields = new List<FormField> { new FormField {Id = "Id"}, new FormField {Id = "Username"}, new FormField {Id = "Name"}, new FormField {Id = "Email"} }; Context.Session["user"] = authenticatedUser; With.Mocks(mockery) .Expecting(() => { Expect.Call(userService.LoadDetails(authenticatedUser.Id)).Return(userDetails); Expect.Call(() => readerService.ReadViewModelProperties()); Expect.Call(readerService.FormFields).Return(fields); }) .Verify(() => controller.Show()); Assert.AreEqual(userDetails, controller.PropertyBag["details"]); Assert.AreEqual(fields, controller.PropertyBag["fields"]); Assert.AreEqual("/Shared/Form", controller.SelectedViewName); }
public void CanReturnAuthenicatedUser() { var authenticationRequest = new AuthenticationRequestDTO { Username = "******", Password = "******" }; var result = new AuthenticatedUserDTO(); With.Mocks(mockery) .Expecting(() => Expect.Call(userRepository.FindOne(new UserByUsernameAndPassword(authenticationRequest.Username, authenticationRequest.Password))).IgnoreArguments().Return(new MembraneUser { Id = Guid.NewGuid(), Username = "******", Password = "******", Type = new MembraneUserType { Id = Guid.NewGuid(), Type = UserType.Administrator }})) .Verify(() => result = service.AuthenticateUser(authenticationRequest)); Assert.AreEqual(UserType.Administrator, result.Type); }
private void DoSuccessFullLogin(AuthenticatedUserDTO authenticatedUser, UserType role, string redirectPath) { var defaultCulture = new CultureDTO {Id = Guid.NewGuid(), Name = "English"}; With.Mocks(mockery) .Expecting(() => { Expect.Call(authenticationService.AuthenticateUser(authenticationRequest)).Return(authenticatedUser); Expect.Call(formsAuthentication.Encrypt(null)).IgnoreArguments(); Expect.Call(cultureService.GetDefaultCulture()).Return(defaultCulture); }) .Verify(() => controller.Login(authenticationRequest)); Assert.IsTrue(Context.CurrentUser.Identity.IsAuthenticated); Assert.IsTrue(Context.CurrentUser.IsInRole(role.ToString())); Assert.AreEqual(defaultCulture, Context.Session["Culture"]); Assert.AreEqual(redirectPath, Response.RedirectedTo); }
private void createAuthenticationTicket(AuthenticatedUserDTO user) { // Set up user var ticket = new FormsAuthenticationTicket(1, user.Id.ToString(), DateTime.Now, DateTime.Now.AddMinutes(30), true, user.Type.ToString(), FormsAuthentication.FormsCookiePath); var hash = formsAuthentication.Encrypt(ticket); var cookie = new HttpCookie(formsAuthentication.FormsCookieName, hash); if (ticket.IsPersistent) cookie.Expires = ticket.Expiration; Context.CurrentUser = user; Context.Session["user"] = user; }