예제 #1
0
        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);
        }
예제 #2
0
        public ActionResult NewTranslator(UserModel model)
        {
            if (model.IsValidForNewTranslator())
            {

                return Redirect("/admin/users");
            }

            model.Msg = "bir sorun oluştu...";
            return View(model);
        }
예제 #3
0
        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;
        }
예제 #4
0
 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;
 }
예제 #5
0
        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);
        }
예제 #6
0
        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) });
        }
예제 #7
0
        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");
        }
예제 #8
0
        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) });
        }
예제 #9
0
        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) });
        }
예제 #10
0
        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");
        }
예제 #11
0
        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) });

        }
예제 #12
0
        /// <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);
        }
예제 #13
0
        /// <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);
        }
예제 #14
0
        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);
        }
예제 #15
0
 public ViewResult NewTranslator()
 {
     var model = new UserModel();
     return View(model);
 }
예제 #16
0
 public ActionResult New()
 {
     var model = new UserModel();
     return View(model);
 }
예제 #17
0
        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) });
        }
예제 #18
0
        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) });
        }
예제 #19
0
        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");
        }
예제 #20
0
        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");
        }