public void Setup() { this.projectRepositoryMock = new Mock<IProjectRepository>(); this.userRepositoryMock = new Mock<IUserRepository>(); this.projectProcessor = new ProjectProcessor(this.projectRepositoryMock.Object, this.userRepositoryMock.Object); this.users = new List<User> { new User { Id = 1, UserName = "******" } }; this.creator = new User { Id = 1, UserName = "******" }; this.project = new Project { Name = "Test project", Creator = creator, ProjectUsers = users }; this.projectRepositoryMock.Setup(it => it.GetAllUsersInProject(project.Id)).Returns(users); this.projectRepositoryMock.Setup(it => it.GetCreatorForProject(project.Id)).Returns(creator); }
public void Should_AddCorrectNews_WithHumanTaskHistoryAsParametr() { // arrange User user = new User { UserName = "******", Id = 2 }; HumanTaskHistory taskHistory = new HumanTaskHistory { Id = 1, Action = "Create", }; News news = new News { HumanTaskHistory = taskHistory, HumanTaskHistoryId = taskHistory.Id, Id = 1, IsRead = false, User = user, UserId = user.Id }; // act this.newsProcessor.AddNews(taskHistory, user); // assert this.newsRepositoryMock.Verify(mock => mock.AddNews(It.Is<News>(x => x.HumanTaskHistoryId == taskHistory.Id && x.UserId == user.Id && x.User == user && x.HumanTaskHistory == taskHistory)), Times.Once()); }
public ActionResult EditUser(User user) { if (this.ModelState.IsValid) { this.userRepository.UpdateUser(user); return this.RedirectToAction("UsersList"); } ModelState.AddModelError(string.Empty, "Wrong data!"); return this.View(user); }
public void AddNews(HumanTaskHistory taskHistory, User user) { var news = new News { HumanTaskHistory = taskHistory, IsRead = false, User = user, UserId = user.Id, HumanTaskHistoryId = taskHistory.Id, }; this.AddNews(news); }
public void Should_CreateProject() { // arrange const string Description = "simply description"; const string ProjectName = "NameProject"; const int UserId = 1; var user = new User { Id = UserId }; // act this.projectProcessor.CreateProject(user, ProjectName, Description); // assert this.projectRepositoryMock.Verify(x => x.Add(It.Is<Project>(it => it.CreatorId == UserId)), Times.Once()); }
public void ShouldNot_CreateNewUser_WhenThisUserAlreadyExist() { const string Username = "******"; const string Password = "******"; const string Email = "*****@*****.**"; const int Id = 100500; var user = new User { Id = Id, UserName = Username, Email = Email }; this.userRepositoryMock.Setup(x => x.GetByName(Username)).Returns(user); // act var result = userProcessor.CreateUser(Username, Password, Email, string.Empty, null, null); // assert Assert.AreEqual(result, false); }
public ActionResult Register(RegisterNewUserModel model) { if (ModelState.IsValid) { User user = new User() { Id = model.userId, UserName = model.UserName, Email = model.Email, Password = model.Password, RoleId = 2 }; userRepository.CreateUser(user); //FormsAuthentication.SetAuthCookie(model.UserName, false /* createPersistentCookie */); //TODO: redirect to view with relation employee with account return RedirectToAction("ConnectUserWithEmployee", "Admin"); } // If we got this far, something failed, redisplay form return View(model); }
public void Should_CreateTask_WhenMethodCreateTaskWasCalledWithAssignedId3() { // arreange User user = new User { Id = 1, UserName = "******" }; CreateTaskViewModel model = new CreateTaskViewModel { AssigneeId = 3, Description = "Description", Name = "Name" }; this.userProcessorMock.Setup(it => it.GetUserByName(null)).Returns(user); // act this.controller.CreateTask(model); // assert this.taskProcessorMock.Verify(x => x.CreateTask(It.Is<HumanTask>(it => it.AssigneeId == 3)), Times.Once()); }
/// <summary> /// The create user. /// </summary> /// <param name="userName"> /// The user name. /// </param> /// <param name="password"> /// The password. /// </param> /// <param name="email"> /// The email. /// </param> /// <param name="linkedInId"> /// The linked in id. /// </param> /// <param name="imageData"> /// The image data. /// </param> /// <param name="imageMimeType"> /// The image mime type. /// </param> /// <returns> /// The System.Boolean. /// </returns> public bool CreateUser(string userName, string password, string email, string linkedInId, byte[] imageData, string imageMimeType) { var user = this.userRepository.GetByName(userName); if (user != null) { return false; } var salt = this.cryptoProvider.CreateSalt(); var newUser = new User { UserName = userName, RoleId = 2, Credentials = new Credentials { Passwordhash = this.cryptoProvider.CreateCryptoPassword(password, salt), Salt = salt, IsVerify = true }, Email = email, LinkedInId = linkedInId, ImageData = imageData, ImageMimeType = imageMimeType }; this.userRepository.CreateUser(newUser); return true; }
/// <summary> /// The update user. /// </summary> /// <param name="user"> /// The user, which will be updated /// </param> public void UpdateUser(User user) { this.dataBaseContext.Entry(user).State = EntityState.Modified; this.dataBaseContext.SaveChanges(); }
/// <summary> /// The create new user. /// </summary> /// <param name="user"> /// The user. /// </param> public void CreateUser(User user) { this.dataBaseContext.Entry(user).State = EntityState.Added; this.dataBaseContext.SaveChanges(); }
public void Should_CreateNewsForUsers() { // arrange User creator = new User{UserName = "******", Id = 1}; User collaborator = new User { UserName = "******", Id = 2 }; this.projectProcessorMock.Setup(it => it.GetUsersAndCreatorInProject(1)).Returns(value: new List<User> {creator, collaborator}); HumanTaskHistory taskHistory = new HumanTaskHistory { Id = 1, Action = "Create" }; // act this.newsProcessor.CreateNewsForUsersInProject(taskHistory,1); // assert this.newsRepositoryMock.Verify(it => it.AddNews(It.IsAny<News>()), Times.Exactly(2)); }
public void ShouldNot_LogonUser_WhenSuchUserExistButNotVerify() { this.cryptoProvider = new CryptoProvider(); const string Username = "******"; const string Password = "******"; const string Email = "*****@*****.**"; const int Id = 100500; var salt = this.cryptoProvider.CreateSalt(); var user = new User { Id = Id, UserName = Username, Email = Email, Credentials = new Credentials { Salt = salt, Passwordhash = this.cryptoProvider.CreateCryptoPassword(Password, salt), IsVerify = false } }; this.userRepositoryMock.Setup(x => x.GetByName(Username)).Returns(user); // act var result = this.userProcessor.LogOnUser(Username, Password); // arrange Assert.AreEqual(result, false); }
/// <summary> /// The create default project. /// </summary> /// <param name="user"> /// The current user. /// </param> public void CreateDefaultProject(User user) { this.CreateProject(user, "Home Project", string.Empty); }
/// <summary> /// The create custom project with project name and description. /// </summary> /// <param name="user"> /// The user tied to project. /// </param> /// <param name="projectName"> /// The project name. /// </param> /// <param name="projectDescription"> /// The project description. /// </param> public void CreateProject(User user, string projectName, string projectDescription) { var project = new Project { CreatorId = user.Id, Creator = user, Created = DateTime.Now, Name = projectName, Description = projectDescription }; this.projectRepository.Add(project); }