public void CreateUser_CreateNormalUser_CountPlusOne()
        {
            var repository = DependencyResolver.Current.GetService<IRepository>();

            var controller = DependencyResolver.Current.GetService<webTemplate.Areas.Default.Controllers.UserController>();

            var countBefore = repository.Users.Count();
            var httpContext = new MockHttpContext().Object;

            var route = new RouteData();

            route.Values.Add("controller", "User");
            route.Values.Add("action", "Register");
            route.Values.Add("area", "Default");

            ControllerContext context = new ControllerContext(new RequestContext(httpContext, route), controller);
            controller.ControllerContext = context;

            controller.Session.Add(CaptchaImage.CaptchaValueKey, "1111");

            var registerUserView = new RegisterUserView()
            {
                ID = 0,
                Email = "*****@*****.**",
                Password = "******",
                ConfirmPassword = "******",
                Captcha = "1111",
            };

            Validator.ValidateObject<RegisterUserView>(registerUserView);
            controller.Register(registerUserView);

            var countAfter = repository.Users.Count();
            Assert.AreEqual(countBefore + 1, countAfter);
        }
예제 #2
0
 public void Validate_EmailIsAlreadyExists_Fail()
 {
     var registerUserView = new RegisterUserView()
     {
         ID = 0,
         Email = "*****@*****.**",
         Password = "******",
         ConfirmPassword = "******",
         Captcha = "1111"
     };
     Validator.ValidateObject<RegisterUserView>(registerUserView);
 }
예제 #3
0
 public void Validate_ConfirmPasswordIsEmpty_Fail()
 {
     var registerUserView = new RegisterUserView()
     {
         ID = 0,
         Email = "*****@*****.**",
         Password = "******",
         ConfirmPassword = "",
         Captcha = "1111"
     };
     Validator.ValidateObject<RegisterUserView>(registerUserView);
 }
        public void Index_AskForDefaultPage_GetViewResult()
        {
            var controller = new webTemplate.Areas.Default.Controllers.UserController();

            var registerUserView = new RegisterUserView()
            {
                ID = 0,
                Email = "*****@*****.**",
                Password = "******",
                ConfirmPassword = "******",
                Captcha = "1111"
            };
        }
예제 #5
0
 public void Validate_EmailIsAlreadyExistsButCanEdit_PassValidate()
 {
     var registerUserView = new RegisterUserView()
     {
         ID = 2,
         Email = "*****@*****.**",
         Password = "******",
         ConfirmPassword = "******",
         Captcha = "1111"
     };
     Validator.ValidateObject<RegisterUserView>(registerUserView);
     Assert.IsNotNull(registerUserView);
 }
        public void Register_CaptchaIsInCorrect_Fail()
        {
            var httpContext = new MockHttpContext().Object;
            var controller = DependencyResolver.Current.GetService<Areas.Default.Controllers.UserController>();
            var route = new RouteData();
            route.Values.Add("controller", "User");
            route.Values.Add("action", "Register");
            route.Values.Add("area", "Default");

            ControllerContext context = new ControllerContext(new RequestContext(httpContext, route), controller);
            controller.ControllerContext = context;

            controller.Session.Add(CaptchaImage.CaptchaValueKey, "1112");
            var registerUserView = new RegisterUserView()
            {
                ID = 0,
                Captcha = "1111"
            };
            controller.Register(registerUserView);
        }
예제 #7
0
        public ActionResult Register(RegisterUserView registerUserView)
        {
            if (Session[CaptchaImage.CaptchaValueKey] as string != registerUserView.Captcha)
            {
                ModelState.AddModelError("Captcha", GlobalRes.captcha_error);
            }
            if (ModelState.IsValid)
            {
                var user = (User)ModelMapper.Map(registerUserView, typeof(RegisterUserView), typeof(User));
                Repository.CreateUser(user);

                NotifyMail.SendNotify("Register_" + CurrentLangCode, user.Email,
                                      format => string.Format(format, HostName),
                                      format => string.Format(format, CurrentLangCode, user.ActivatedLink, HostName));
                return View("RegisterSuccess", user);
            }
            return View(registerUserView);
        }
예제 #8
0
 public ActionResult Register()
 {
     var registerUserView = new RegisterUserView();
     return View(registerUserView);
 }
예제 #9
0
 public void Validate_EmailIsNotCorrect_Fail()
 {
     var registerUserView = new RegisterUserView()
     {
         ID = 0,
         Email = "chernikov",
         Password = "******",
         ConfirmPassword = "******",
         Captcha = "1111"
     };
     Validator.ValidateObject<RegisterUserView>(registerUserView);
 }
예제 #10
0
        public void Validate_EmailIsEmpty_Fail()
        {
            var registerUserView = new RegisterUserView()
            {
                ID = 0,

                Email = string.Empty,
                Password = "******",
                ConfirmPassword = "******",
                Captcha = "1111"
            };
            Validator.ValidateObject<RegisterUserView>(registerUserView);
        }