public User SetupDatabase(SetupVariables setupVariables, out Exception exception) { exception = null; try { _setupRepository.SetupDatabase(); } catch (Exception exc) { exception = exc; return null; } var settings = _settingsManager.Current; settings.ForumTitle = setupVariables.ForumTitle; settings.SmtpServer = setupVariables.SmtpServer; settings.SmtpPort = setupVariables.SmtpPort; settings.MailerAddress = setupVariables.MailerAddress; settings.UseSslSmtp = setupVariables.UseSslSmtp; settings.UseEsmtp = setupVariables.UseEsmtp; settings.SmtpUser = setupVariables.SmtpUser; settings.SmtpPassword = setupVariables.SmtpPassword; _settingsManager.SaveCurrent(); var user = _userService.CreateUser(setupVariables.Name, setupVariables.Email, setupVariables.Password, true, ""); user.Roles = new List<string> {PermanentRoles.Admin, PermanentRoles.Moderator}; var profile = new Profile(user.UserID) { IsTos = true, IsSubscribed = true, TimeZone = setupVariables.ServerTimeZone, IsDaylightSaving = setupVariables.ServerDaylightSaving, ShowDetails = true }; _profileService.Create(profile); var edit = new UserEdit(user, profile); _userService.EditUser(user, edit, false, false, null, null, "", user); PopForumsActivation.StartServicesIfRunningInstance(); return user; }
public void EditUserNewPhoto() { var service = GetMockedUserService(); var user = new User(1, DateTime.MinValue); user.Roles = new List<string>(); var userEdit = new UserEdit(); var returnedProfile = GetReturnedProfile(userEdit); _mockProfileRepo.Setup(p => p.GetProfile(1)).Returns(returnedProfile); _mockProfileRepo.Setup(p => p.Update(It.IsAny<Profile>())).Returns(true); var photo = new Mock<HttpPostedFileBase>(); photo.Setup(a => a.ContentLength).Returns(100); var stream = new MemoryStream(new byte[] { 1, 2, 1 }); photo.Setup(a => a.InputStream).Returns(stream); _mockUserImageRepo.Setup(a => a.SaveNewImage(1, 0, true, It.IsAny<byte[]>(), It.IsAny<DateTime>())).Returns(12); service.EditUser(user, userEdit, false, false, null, photo.Object, "123", user); _mockUserImageRepo.Verify(a => a.SaveNewImage(1, 0, true, It.IsAny<byte[]>(), It.IsAny<DateTime>()), Times.Once()); }
public void EditUserNoDeletePhoto() { var service = GetMockedUserService(); var user = new User(1, DateTime.MinValue); user.Roles = new List<string>(); var userEdit = new UserEdit(); var returnedProfile = GetReturnedProfile(userEdit); returnedProfile.ImageID = 3; _mockProfileRepo.Setup(p => p.GetProfile(1)).Returns(returnedProfile); var profile = new Profile(); _mockProfileRepo.Setup(p => p.Update(It.IsAny<Profile>())).Callback<Profile>(p => profile = p); service.EditUser(user, userEdit, false, false, null, null, "123", user); _mockProfileRepo.Verify(p => p.Update(It.IsAny<Profile>()), Times.Once()); Assert.AreEqual(3, profile.ImageID); }
public void EditUserRemoveRole() { var service = GetMockedUserService(); var user = new User(1, DateTime.MinValue); user.Roles = new List<string> { "Admin", "Moderator" }; var userEdit = new UserEdit { Roles = new[] { "SomethingElse" } }; _mockProfileRepo.Setup(p => p.GetProfile(1)).Returns(GetReturnedProfile(userEdit)); service.EditUser(user, userEdit, false, false, null, null, "123", user); _mockRoleRepo.Verify(r => r.ReplaceUserRoles(1, userEdit.Roles), Times.Once()); _mockSecurityLogService.Verify(s => s.CreateLogEntry(It.IsAny<User>(), user, "123", "Admin", SecurityLogType.UserRemovedFromRole), Times.Once()); _mockSecurityLogService.Verify(s => s.CreateLogEntry(It.IsAny<User>(), user, "123", "Moderator", SecurityLogType.UserRemovedFromRole), Times.Once()); }
public void EditUserNewPassword() { var service = GetMockedUserService(); var user = new User(1, DateTime.MinValue); user.Roles = new List<string>(); var userEdit = new UserEdit { NewPassword = "******" }; _mockProfileRepo.Setup(p => p.GetProfile(1)).Returns(GetReturnedProfile(userEdit)); service.EditUser(user, userEdit, false, false, null, null, "123", user); _mockUserRepo.Verify(u => u.SetHashedPassword(user, It.IsAny<string>(), It.IsAny<Guid>()), Times.Once()); }
public void EditUserNewEmail() { var service = GetMockedUserService(); var user = new User(1, DateTime.MinValue) { Email = "*****@*****.**" }; user.Roles = new List<string>(); var userEdit = new UserEdit { NewEmail = "*****@*****.**" }; _mockProfileRepo.Setup(p => p.GetProfile(1)).Returns(GetReturnedProfile(userEdit)); service.EditUser(user, userEdit, false, false, null, null, "123", user); _mockUserRepo.Verify(u => u.ChangeEmail(user, "*****@*****.**"), Times.Once()); }
public void EditUserApprovalChange() { var service = GetMockedUserService(); var user = new User(1, DateTime.MinValue) {IsApproved = false}; user.Roles = new List<string>(); var userEdit = new UserEdit {IsApproved = true}; _mockProfileRepo.Setup(p => p.GetProfile(1)).Returns(GetReturnedProfile(userEdit)); service.EditUser(user, userEdit, false, false, null, null, "123", user); _mockUserRepo.Verify(u => u.UpdateIsApproved(user, true), Times.Once()); }
private Profile GetReturnedProfile(UserEdit userEdit) { return new Profile(1) { IsSubscribed = userEdit.IsSubscribed, ShowDetails = userEdit.ShowDetails, IsPlainText = userEdit.IsPlainText, HideVanity = userEdit.HideVanity, TimeZone = userEdit.TimeZone, IsDaylightSaving = userEdit.IsDaylightSaving, Signature = userEdit.Signature, Location = userEdit.Location, Dob = userEdit.Dob, Web = userEdit.Web, Aim = userEdit.Aim, Icq = userEdit.Icq, YahooMessenger = userEdit.YahooMessenger, Facebook = userEdit.Facebook, Twitter = userEdit.Twitter }; }
public void EditUserProfileOnly() { var service = GetMockedUserService(); var user = new User(1, DateTime.MinValue); user.Roles = new List<string>(); var userEdit = new UserEdit(); var profile = new Profile(); var returnedProfile = GetReturnedProfile(userEdit); _mockProfileRepo.Setup(p => p.GetProfile(1)).Returns(returnedProfile); _mockProfileRepo.Setup(p => p.Update(It.IsAny<Profile>())).Callback<Profile>(p => profile = p); service.EditUser(user, userEdit, false, false, null, null, "123", user); _mockUserRepo.Verify(u => u.ChangeEmail(It.IsAny<User>(), It.IsAny<string>()), Times.Never()); _mockUserRepo.Verify(u => u.ChangeName(It.IsAny<User>(), It.IsAny<string>()), Times.Never()); _mockUserRepo.Verify(u => u.SetHashedPassword(It.IsAny<User>(), It.IsAny<string>(), It.IsAny<Guid>()), Times.Never()); _mockProfileRepo.Verify(p => p.Update(It.IsAny<Profile>()), Times.Once()); }
public void UserEditPhotosNewPhoto() { var service = GetMockedUserService(); var user = new User(1, DateTime.MinValue); var userEdit = new UserEdit(); var returnedProfile = GetReturnedProfile(userEdit); _mockProfileRepo.Setup(p => p.GetProfile(1)).Returns(returnedProfile); _mockProfileRepo.Setup(p => p.Update(It.IsAny<Profile>())).Returns(true); var photo = new Mock<HttpPostedFileBase>(); photo.Setup(a => a.ContentLength).Returns(100); var stream = new MemoryStream(new byte[] { 1, 2, 1 }); photo.Setup(a => a.InputStream).Returns(stream); _mockUserImageRepo.Setup(a => a.SaveNewImage(1, 0, true, It.IsAny<byte[]>(), It.IsAny<DateTime>())).Returns(12); _mockSettingsManager.Setup(s => s.Current.UserImageMaxHeight).Returns(1); _mockSettingsManager.Setup(s => s.Current.UserImageMaxWidth).Returns(1); _mockSettingsManager.Setup(s => s.Current.IsNewUserImageApproved).Returns(true); service.EditUserProfileImages(user, false, false, null, photo.Object); _mockUserImageRepo.Verify(a => a.SaveNewImage(1, 0, true, It.IsAny<byte[]>(), It.IsAny<DateTime>()), Times.Once()); _mockUserImageRepo.Verify(u => u.DeleteImagesByUserID(user.UserID)); }
public void UserEditPhotosNoDeletePhoto() { var service = GetMockedUserService(); var user = new User(1, DateTime.MinValue); var userEdit = new UserEdit(); var returnedProfile = GetReturnedProfile(userEdit); returnedProfile.ImageID = 3; _mockProfileRepo.Setup(p => p.GetProfile(1)).Returns(returnedProfile); var profile = new Profile(); _mockProfileRepo.Setup(p => p.Update(It.IsAny<Profile>())).Callback<Profile>(p => profile = p); service.EditUserProfileImages(user, false, false, null, null); _mockProfileRepo.Verify(p => p.Update(It.IsAny<Profile>()), Times.Once()); _mockUserImageRepo.Verify(u => u.DeleteImagesByUserID(user.UserID), Times.Never()); Assert.AreEqual(3, profile.ImageID); }
public ActionResult EditUser(int id, UserEdit userEdit) { var user = this.CurrentUser(); var targetUser = _userService.GetUser(id); if (targetUser == null) throw new Exception(String.Format("UserID {0} not found.", id)); var avatarFile = Request.Files["avatarFile"]; var photoFile = Request.Files["photoFile"]; _userService.EditUser(targetUser, userEdit, userEdit.DeleteAvatar, userEdit.DeleteImage, avatarFile, photoFile, HttpContext.Request.UserHostAddress, user); return RedirectToAction("EditUserSearch"); }
public ActionResult EditUser(int id) { var user = _userService.GetUser(id); if (user == null) throw new Exception(String.Format("UserID {0} not found.", id)); var profile = _profileService.GetProfileForEdit(user); var model = new UserEdit(user, profile); return View(model); }
public void EditUser(User targetUser, UserEdit userEdit, bool removeAvatar, bool removePhoto, HttpPostedFileBase avatarFile, HttpPostedFileBase photoFile, string ip, User user) { if (!String.IsNullOrWhiteSpace(userEdit.NewEmail)) ChangeEmail(targetUser, userEdit.NewEmail, user, ip, userEdit.IsApproved); if (!String.IsNullOrWhiteSpace(userEdit.NewPassword)) SetPassword(targetUser, userEdit.NewPassword, ip, user); if (targetUser.IsApproved != userEdit.IsApproved) UpdateIsApproved(targetUser, userEdit.IsApproved, user, ip); var profile = _profileRepository.GetProfile(targetUser.UserID); profile.IsSubscribed = userEdit.IsSubscribed; profile.ShowDetails = userEdit.ShowDetails; profile.IsPlainText = userEdit.IsPlainText; profile.HideVanity = userEdit.HideVanity; profile.TimeZone = userEdit.TimeZone; profile.IsDaylightSaving = userEdit.IsDaylightSaving; profile.Signature = _textParsingService.ForumCodeToHtml(userEdit.Signature); profile.Location = userEdit.Location; profile.Dob = userEdit.Dob; profile.Web = userEdit.Web; profile.Aim = userEdit.Aim; profile.Icq = userEdit.Icq; profile.YahooMessenger = userEdit.YahooMessenger; profile.Facebook = userEdit.Facebook; profile.Twitter = userEdit.Twitter; if (removeAvatar) profile.AvatarID = null; if (removePhoto) profile.ImageID = null; _profileRepository.Update(profile); var newRoles = userEdit.Roles ?? new string[0]; _roleRepository.ReplaceUserRoles(targetUser.UserID, newRoles); foreach (var role in targetUser.Roles) if (!newRoles.Contains(role)) _securityLogService.CreateLogEntry(user, targetUser, ip, role, SecurityLogType.UserRemovedFromRole); foreach (var role in newRoles) if (!targetUser.Roles.Contains(role)) _securityLogService.CreateLogEntry(user, targetUser, ip, role, SecurityLogType.UserAddedToRole); if (avatarFile != null && avatarFile.ContentLength > 0) { var avatarID = _userAvatarRepository.SaveNewAvatar(targetUser.UserID, avatarFile.GetBytes(), DateTime.UtcNow); profile.AvatarID = avatarID; _profileRepository.Update(profile); } if (photoFile != null && photoFile.ContentLength > 0) { var imageID = _userImageRepository.SaveNewImage(targetUser.UserID, 0, true, photoFile.GetBytes(), DateTime.UtcNow); profile.ImageID = imageID; _profileRepository.Update(profile); } }
public void EditUser() { var controller = GetController(); var context = new HttpContextHelper(); var mockFileCollection = new Mock<HttpFileCollectionBase>(); var avatar = new Mock<HttpPostedFileBase>(); var photo = new Mock<HttpPostedFileBase>(); mockFileCollection.Setup(f => f["avatarFile"]).Returns(avatar.Object); mockFileCollection.Setup(f => f["photoFile"]).Returns(photo.Object); context.MockRequest.Setup(r => r.Files).Returns(mockFileCollection.Object); controller.ControllerContext = new ControllerContext(context.MockContext.Object, new RouteData(), controller); var targetUser = new User(1, DateTime.MinValue); var user = new User(2, DateTime.MinValue); var userEdit = new UserEdit {DeleteAvatar = true, DeleteImage = true}; _userService.Setup(u => u.GetUser(1)).Returns(targetUser); controller.SetUser(user); controller.EditUser(1, userEdit); _userService.Verify(u => u.EditUser(targetUser, userEdit, true, true, avatar.Object, photo.Object, It.IsAny<string>(), user), Times.Once()); }