public async Task<int?> Create(UserModel model) { var user = new User { Email = model.Email, PasswordHash = model.Password }; _userRepo.Create(user); if (!_userRepo.SaveChanges()) return null; return await Task.FromResult(user.Id); }
public ActionResult NewTranslator(UserModel model) { if (model.IsValidForNewTranslator()) { return Redirect("/admin/users"); } model.Msg = "bir sorun oluştu..."; return View(model); }
public int? Create(UserModel model) { var user = new User { Email = model.Email, PasswordHash = model.Password }; _userRepo.Create(user); if (_userRepo.SaveChanges()) { return user.Id; } return null; }
public static UserModel MapUserToUserModel(User user) { var model = new UserModel { Email = user.Email, Id = user.Id, Name = user.Name, RoleName = user.RoleName, Language = user.Language, IsActive = user.IsActive, RoleId = user.RoleId }; return model; }
public void should_authenticate_user() { // Arrange var userModel = new UserModel { Email = "*****@*****.**", Password = "******" }; var userRepository = new Mock<IRepository<User>>(); // Act var userService = new UserService(userRepository.Object); var userId = userService.Create(userModel); // Assert userRepository.Verify(x => x.Create(It.IsAny<User>()), Times.Once); userRepository.Verify(x => x.SaveChanges(), Times.AtLeastOnce); Assert.NotNull(userId); }
public async void new_translator_should_return_with_app_model_if_model_is_invalid() { //arrange var inValidModel = new UserModel { Name = "test name" }; //act var sut = new AdminControllerBuilder().Build(); var view = await sut.NewTranslator(inValidModel) as ViewResult; //assert Assert.NotNull(view); Assert.NotNull(view.Model); Assert.IsAssignableFrom(typeof(UserModel), view.Model); sut.AssertPostAndAntiForgeryTokenAttribute("NewTranslator", new[] { typeof(UserModel) }); }
public ActionResult New(UserModel model) { if (!model.IsValidForNewDeveloper()) { model.Msg = "bir sorun oluştu"; return View(model); } var userId = _userService.Create(model); if (userId == null) { model.Msg = "bir sorun oluştu"; return View(model); } return Redirect("/user/apps"); }
public async void new_translator_should_return_with_app_model_if_model_is_invalid() { // Arrange var inValidModel = new UserModel { Name = "test name" }; // Act var controller = new AdminController(null, null, null); var view = await controller.NewTranslator(inValidModel) as ViewResult; // Assert Assert.NotNull(view); Assert.NotNull(view.Model); var model = view.Model as UserModel; Assert.NotNull(model); controller.AssertPostAttribute("NewTranslator", new[] { typeof(UserModel) }); }
public async void new_translator_should_redirect_if_model_is_valid() { // Arrange var validModel = new UserModel { Name = "test name", Email = "*****@*****.**" }; var userService = new Mock<IUserService>(); userService.Setup(x => x.Create(It.IsAny<UserModel>(), SetLocaleRole.Translator.Value)).Returns(() => Task.FromResult<int?>(1)); // Act var controller = new AdminController(userService.Object, null, null); var view = await controller.NewTranslator(validModel) as RedirectResult; // Assert Assert.NotNull(view); Assert.AreEqual(view.Url, "/admin/users"); userService.Verify(x => x.Create(It.IsAny<UserModel>(), SetLocaleRole.Translator.Value), Times.Once); controller.AssertPostAttribute("NewTranslator", new[] { typeof(UserModel) }); }
public async Task<ActionResult> NewTranslator(UserModel model) { if (!model.IsValidForNewTranslator()) { model.Msg = "bir sorun oluştu..."; return View(model); } model.Password = Guid.NewGuid().ToString().Replace("-", string.Empty); model.Language = Thread.CurrentThread.CurrentUICulture.Name; var userId = await _userService.Create(model, SetLocaleRole.Translator.Value); if (userId == null) { model.Msg = "bir sorun oluştu..."; return View(model); } //send mail to translator to welcome and ask for reset password return Redirect("/admin/users"); }
public async void new_translator_should_redirect_if_model_is_valid() { //arrange var validModel = new UserModel { Name = "test name", Email = "*****@*****.**" }; var userService = new Mock<IUserService>(); userService.Setup(x => x.Create(It.IsAny<UserModel>(), SetLocaleRole.Translator.Value)).Returns(() => Task.FromResult<int?>(1)); //act var sut = new AdminControllerBuilder().WithUserService(userService.Object) .Build(); var view = await sut.NewTranslator(validModel) as RedirectResult; //assert Assert.NotNull(view); Assert.AreEqual(view.Url, "/admin/users"); Assert.IsInstanceOf<BaseController>(sut); userService.Verify(x => x.Create(It.IsAny<UserModel>(), SetLocaleRole.Translator.Value), Times.Once); sut.AssertPostAndAntiForgeryTokenAttribute("NewTranslator", new[] { typeof(UserModel) }); }
/// <summary> /// /// </summary> /// <param name="model"></param> /// <param name="roleId">default is 3 - SetLocaleRole.Developer.Value </param> /// <returns></returns> public async Task<int?> Create(UserModel model, int roleId = 3) { var img = GravatarHelper.GetGravatarURL(model.Email, 55, "mm"); var user = new User { Email = model.Email, Name = model.Name, PasswordHash = BCrypt.Net.BCrypt.HashPassword(model.Password), ImageUrl = img, RoleId = roleId, RoleName = SetLocaleRole.GetString(roleId), IsActive = true, Language = model.Language }; _userRepo.Create(user); if (!_userRepo.SaveChanges()) return null; return await Task.FromResult(user.Id); }
/// <summary> /// /// </summary> /// <param name="model"></param> /// <param name="roleId">default is 3 - SetLocaleRole.Developer.Value </param> /// <returns></returns> public async Task<int?> Create(UserModel model, int roleId = 3) { var img = GravatarHelper.GetGravatarURL(model.Email, 55, "mm"); var user = new User { Email = model.Email, Name = model.Name, PasswordHash = BCrypt.Net.BCrypt.HashPassword(model.Password), ImageUrl = img, RoleId = roleId, RoleName = SetLocaleRole.GetString(roleId), IsActive = true, Language = model.Language }; _userRepo.Create(user); if (roleId == SetLocaleRole.Developer.Value) { var app = new App { UserEmail = model.Email, Name = model.Name, Url = "example.com", IsActive = true, Tokens = new List<Token> { new Token {Key = Guid.NewGuid().ToString().Replace("-", string.Empty), UsageCount = 0,IsAppActive = true} } }; _appRepository.Create(app); _appRepository.SaveChanges(); } if (!_userRepo.SaveChanges()) return null; return await Task.FromResult(user.Id); }
public void should_create_a_user() { //arrange var userModel = new UserModel { Email = "*****@*****.**", Password = "******" }; var userRepository = new Mock<IRepository<User>>(); userRepository.Setup(x => x.Create(It.IsAny<User>())).Returns(It.IsAny<User>()); userRepository.Setup(x => x.SaveChanges()).Returns(true); var appRepository = new Mock<IRepository<App>>(); appRepository.Setup(x => x.Create(It.IsAny<App>())).Returns(It.IsAny<App>()); appRepository.Setup(x => x.SaveChanges()).Returns(true); //act var userService = new UserService(userRepository.Object, appRepository.Object); var userId = userService.Create(userModel); //assert Assert.NotNull(userId); userRepository.Verify(x => x.Create(It.IsAny<User>()), Times.Once); userRepository.Verify(x => x.SaveChanges(), Times.AtLeastOnce); }
public ViewResult NewTranslator() { var model = new UserModel(); return View(model); }
public ActionResult New() { var model = new UserModel(); return View(model); }
public async void new_should_return_with_user_model_if_model_is_invalid() { //arrange var invalidModel = new UserModel { Name = "test name" }; //act var sut = new UserControllerBuilder().Build(); var view = await sut.New(invalidModel) as ViewResult; //assert Assert.NotNull(view); var model = view.Model; Assert.NotNull(model); Assert.IsAssignableFrom(typeof(UserModel), model); sut.AssertPostAndAntiForgeryTokenAttribute("New", new[] { typeof(UserModel) }); sut.AssertAllowAnonymousAttribute("New", new[] { typeof(UserModel) }); }
public async void new_should_redirect_if_model_is_valid() { //arrange var validModel = new UserModel { Name = "test name", Email = "*****@*****.**", Password = "******" }; var userService = new Mock<IUserService>(); userService.Setup(x => x.Create(It.IsAny<UserModel>(), SetLocaleRole.Developer.Value)).Returns(() => Task.FromResult<int?>(1)); var formsAuthenticationService = new Mock<IFormsAuthenticationService>(); formsAuthenticationService.Setup(x => x.SignIn(string.Format("{0}|{1}|{2}", 1, validModel.Name, validModel.Email), true)); //act var sut = new UserControllerBuilder().WithUserService(userService.Object) .WithFormsAuthenticationService(formsAuthenticationService.Object) .Build(); var view = await sut.New(validModel); //assert Assert.NotNull(view); Assert.AreEqual(((RedirectResult)view).Url, "/user/apps"); userService.Verify(x => x.Create(It.IsAny<UserModel>(), SetLocaleRole.Developer.Value), Times.Once); sut.AssertPostAndAntiForgeryTokenAttribute("New", new[] { typeof(UserModel) }); sut.AssertAllowAnonymousAttribute("New", new[] { typeof(UserModel) }); }
public async Task<ActionResult> New(UserModel model) { if (!model.IsValidForNewDeveloper()) { model.Msg = "bir sorun oluştu"; return View(model); } model.Language = Thread.CurrentThread.CurrentUICulture.Name; var userId = await _userService.Create(model); if (userId == null) { model.Msg = "bir sorun oluştu"; return View(model); } _formsAuthenticationService.SignIn(string.Format("{0}|{1}|{2}", userId, model.Name, model.Email), true); return Redirect("/user/apps"); }
public async Task<ActionResult> New(UserModel model) { if (!model.IsValidForNewDeveloper()) { model.Msg = "bir sorun oluştu"; return View(model); } model.Language = Thread.CurrentThread.CurrentUICulture.Name; var userId = await _userService.Create(model); if (userId == null) { model.Msg = "bir sorun oluştu"; return View(model); } return Redirect("/user/apps"); }