public async Task UserServiceLogin_ValidatesAndLogsIn() { var username = "******"; var password = "******"; var wrongPassword = "******"; var hashedPassword = "******"; Moq.Mock <IUserRepository> userRepositoryMock = new Moq.Mock <IUserRepository>(); Moq.Mock <IPasswordService> passwordServiceMock = new Moq.Mock <IPasswordService>(); IOptions <JwtSettings> jwtSettingsMock = Options.Create <JwtSettings>(new JwtSettings { JwtSecret = "fedaf7d8863b48e197b9287d492b708e" }); userRepositoryMock.Setup(mock => mock.FindByUsername(username)).Returns(Task.Run(() => new User(Guid.NewGuid(), username, hashedPassword))); passwordServiceMock.Setup(mock => mock.VerifyPassword(wrongPassword, hashedPassword)).Returns(false); passwordServiceMock.Setup(mock => mock.VerifyPassword(password, hashedPassword)).Returns(true); var userService = new UserServiceImpl(userRepositoryMock.Object, passwordServiceMock.Object, jwtSettingsMock); await Assert.ThrowsAnyAsync <Exception>(async() => await userService.Login(null, null)); await Assert.ThrowsAnyAsync <Exception>(async() => await userService.Login(username, wrongPassword)); var authenticatedUser = await userService.Login(username, password); userRepositoryMock .Verify(mock => mock.FindByUsername(username), Times.Exactly(2)); Assert.Equal(username, authenticatedUser.Username); }
public async Task UserServiceSignUp_ValidatesInputAndDoesSignUp() { var username = "******"; var password = "******"; Moq.Mock <IUserRepository> userRepositoryMock = new Moq.Mock <IUserRepository>(); Moq.Mock <IPasswordService> passwordServiceMock = new Moq.Mock <IPasswordService>(); IOptions <JwtSettings> jwtSettingsMock = Options.Create <JwtSettings>(new JwtSettings { JwtSecret = "anySecret" }); var userService = new UserServiceImpl(userRepositoryMock.Object, passwordServiceMock.Object, jwtSettingsMock); await Assert.ThrowsAnyAsync <Exception>(async() => await userService.Signup("", "")); await Assert.ThrowsAnyAsync <Exception>(async() => await userService.Signup(null, null)); await Assert.ThrowsAnyAsync <Exception>(async() => await userService.Signup("lt6", "password")); await Assert.ThrowsAnyAsync <Exception>(async() => await userService.Signup("username", "lt6")); await userService.Signup(username, password); passwordServiceMock .Verify(mock => mock.HashPassword(password), Times.Once()); userRepositoryMock .Verify(mock => mock.Create(It.IsAny <User>()), Times.Once()); }
protected override bool IsAuthorized(HttpActionContext actionContext) { bool isAuthorized = false; string token; UserServiceImpl service; long id = -1; Dictionary <string, object> values; service = new UserServiceImpl(); var authorization = actionContext.Request.Headers.Authorization; if (CheckHelper.IsFilled(authorization) && CheckHelper.IsFilled(authorization.Scheme)) { token = authorization.Scheme; try { string payload = JWT.JsonWebToken.Decode(token, AppConstants.JWT_SECRET_KEY); values = JsonConvert.DeserializeObject <Dictionary <string, object> >(payload); id = Convert.ToInt64(values["Id"]); isAuthorized = service.isAuthorized(id, Role, ForbiddenRole); } catch (Exception) { isAuthorized = Anonymous; } } else { isAuthorized = Anonymous; } return(isAuthorized); }
protected void btnsubmit_Click(object sender, EventArgs e) { UserDto userRegister = new UserDto(); userRegister.UserName = txtuname.Text; userRegister.Password = txtpsw.Text; userRegister.Name = txtname.Text; userRegister.MobileNo = txtmobile.Text; userRegister.EmailId = txtemail.Text; UserService Service = new UserServiceImpl(); bool insert = Service.AddUser(userRegister); if (insert) { //lblstatus.Text = "<b style='color:red'>User detailes has been inserted successfully!!!</b>"; ClientScript.RegisterStartupScript(Page.GetType(), "validation", "<script language='javascript'>alert('User detailes has been instantiate successfully.')</script>"); txtuname.Text = string.Empty; txtpsw.Text = string.Empty; txtname.Text = string.Empty; txtmobile.Text = string.Empty; txtemail.Text = string.Empty; } else { //lblstatus.Text = "<b style='color:red'>User detailes insertion failed!!!</b>"; ClientScript.RegisterStartupScript(Page.GetType(), "validation", "<script language='javascript'>alert('User detailes insertion failed.')</script>"); } //Response.Redirect("~/Login.aspx"); }
public void UserNotLoggedInTest() { Guid id = Guid.NewGuid(); var userService = new UserServiceImpl(null); UserDTO resultUser = userService.GetUserLoggedIn(id); }
public void LogInSuccessfullyTest() { LoginDTO loginUser = new LoginDTO(); loginUser.UserName = "******"; loginUser.Password = "******"; UserDTO userDTO = new UserDTO(); userDTO.Name = "Pepe"; userDTO.LastName = "Perez"; userDTO.UserName = "******"; userDTO.Phone = 091234567; userDTO.Password = "******"; userDTO.Role = "Administrador"; var mockUserDAO = new Mock <UserDAO>(); mockUserDAO.Setup(us => us.LogIn(loginUser)).Returns(userDTO); var userService = new UserServiceImpl(mockUserDAO.Object); UserLoggedDTO result = userService.LogIn(loginUser); userService.LogOut(result.Token); }
public void LogOutUserErrorTest() { Guid id = Guid.NewGuid(); var userService = new UserServiceImpl(null); userService.LogOut(id); }
public void ValidateLogin(string username, string password) { Console.WriteLine("Validating log in"); if (string.IsNullOrEmpty(username)) { throw new Exception("Enter username"); } if (string.IsNullOrEmpty(password)) { throw new Exception("Enter password"); } ClaimsIdentity identity = new ClaimsIdentity(); try { User user = UserServiceImpl.ValidateUser(username, password); identity = SetupClaimsForUser(user); string serialisedData = JsonSerializer.Serialize(user); jsRuntime.InvokeVoidAsync("sessionStorage.setItem", "currentUser", serialisedData); cachedUser = user; } catch (Exception e) { throw new Exception("Identity claim failed"); } NotifyAuthenticationStateChanged(Task.FromResult(new AuthenticationState(new ClaimsPrincipal(identity)))); }
protected void btnlogin_Click(object sender, EventArgs e) { UserDto dto = new UserDto(); dto.UserName = Request.Form["txtuname"]; dto.Password = Request.Form["txtpsw"]; dto.Name = Request.Form["txtname"]; UserService service = new UserServiceImpl(); bool validUser = service.ValidatUser(dto); if (validUser) { Session["UserName"] = dto.UserName; Session["Password"] = dto.Password; Session["Name"] = dto.Name; Response.Redirect("DataBoundFile.aspx"); } else { //lblstatus = "<b style='color:red'>Please check your UserName and Password!!!</b>"; //Response.Output.Write(lblstatus); ClientScript.RegisterStartupScript(Page.GetType(), "validation", "<script language='javascript'>alert('Invalid Username and Password')</script>"); txtuname = ""; txtpsw = ""; } }
public Service(CommunicatorDbContex db) { FriendRelation = new FriendRelationServiceImpl(db); Message = new MessageSerciveImpl(db); Payment = new PaymentServiceImpl(db); User = new UserServiceImpl(db); }
public void doCreateTest() { User user = new User(); user.username = "******"; user.password = "******"; UserService service = new UserServiceImpl(); service.doCreate(user); }
public IUserService GetUserService() { IUserService userService = flyWeightPool["UserService"] as IUserService; if (userService == null) { userService = new UserServiceImpl(); flyWeightPool.Add("UserService", userService); } return(userService); }
public void LogInErrorTest() { LoginDTO loginUser = new LoginDTO(); loginUser.UserName = "******"; loginUser.Password = "******"; var mockUserDAO = new Mock <UserDAO>(); UserDTO userDTO = null; mockUserDAO.Setup(us => us.LogIn(loginUser)).Returns(userDTO); var userService = new UserServiceImpl(mockUserDAO.Object); UserLoggedDTO result = userService.LogIn(loginUser); }
public void ErrorCreatingUserWithSameUserNameTest() { Role role = new Role(Roles.ADMINISTRATOR); User user = new User("Carlos", "Perez", "Carlitos", 091234567, "Password", role); UserDTO userDTO = new UserDTO(); userDTO.Name = "Carlos"; userDTO.LastName = "Perez"; userDTO.UserName = "******"; userDTO.Phone = 091234567; userDTO.Password = "******"; userDTO.Role = "Administrador"; var mockUserDAO = new Mock <UserDAO>(); mockUserDAO.Setup(us => us.FindUserByUserName("Carlitos")).Returns(userDTO); var userService = new UserServiceImpl(mockUserDAO.Object); userService.AddUser(userDTO); }
public UserController() { server = IocManager.Instance.Resolve <UserServiceImpl>(); server.GetValues(); }
public static void Main(string[] args) { IUserService iUserService = new UserServiceImpl(); OutputTextToConsole output = (string text) => Console.WriteLine(text); RowCreated += iUserService.ShowMessageEvent; int?nullableVariable = null; for (int i = 0; i < USERS_COUNT; i++) { output("set User name"); iUserService.CreateNewUsers(Console.ReadLine()); output("\r\n"); RowCreated("---- EVENT - Was created empty row ----"); } output("\r\n"); output("Count of the element: " + iUserService.GetCountUsers()); int counter = 1; List <User> users = iUserService.ReplaceUserSetToList(); iUserService.SortingList(users); foreach (var user in users) { iUserService.SetKeysInArray(counter); output(counter + ": Name: " + user.Name + "\r\n" + "Age: " + user.Age + "\r\n"); counter++; } var tuple = (users[0].Age, users[1].Age); int calculateSumOfAges = iUserService.CalculateSumOfAges(tuple); output("Sum of the ages for first and second user: "******"\r\n"); iUserService.DeleteUsersLowerThan10Years(Console.ReadLine()); output("Users older than 10 years: " + users.Count + "\r\n"); ListUserToConsole(users); ReflectionForFindMyCustomAttribute(); try { //Admin admin = new Admin(); } catch (ExceptionCreatingInstance ex) { Console.WriteLine("Error: " + ex.Message); } AddUsersToList(users); ListUserToConsole(users); var selectedTeams = from t in users // определяем каждый объект из teams как t where t.Age < 10 //фильтрация по критерию orderby t // упорядочиваем по возрастанию select t; // выбираем объект foreach (User s in selectedTeams) { Console.WriteLine("Name: " + s.Name + "\r\n" + "Age: " + s.Age + "\r\n"); } Console.ReadKey(); }
public UserController(UserUtil userUtil, UserServiceImpl userService) { _userUtil = userUtil; _userService = userService; }