public void Account_GetToken_Member_Success()
        {
            IList <Claim> memberClaim = new List <Claim>()
            {
                new Claim(ClaimTypes.Role, "Member")
            };

            _userManager.Setup(x => x.GetClaimsAsync(It.IsAny <ApplicationUser>())).ReturnsAsync(memberClaim);
            Controllers.AccountController accountController = new Controllers.AccountController(_userManager.Object,
                                                                                                _signInManager.Object,
                                                                                                _emailSender.Object,
                                                                                                _logger.Object,
                                                                                                _config,
                                                                                                _contextAccessor.Object,
                                                                                                _userRepository.Object,
                                                                                                new MemoryCache(new MemoryCacheOptions()));
            var actionResult = accountController.GetToken();
            var objectResult = actionResult.Result as OkObjectResult;

            Assert.IsNotNull(objectResult.Value);
            JwtSecurityToken token = DeserializeToken(objectResult);
            var claim = token.Claims.Where(c => c.Type == ClaimTypes.Role);

            Assert.IsTrue(claim.FirstOrDefault().Value == "Member");
        }
        public void TestAccountControllerRegister()
        {
            Controllers.AccountController controler = new Controllers.AccountController();
            ViewResult result = controler.Register() as ViewResult;

            Assert.IsNotNull(result);
        }
 public void TestAccountControllerLogin()
 {
     Controllers.AccountController controler = new Controllers.AccountController();
     string     url    = "TEST";
     ViewResult result = controler.Login(url) as ViewResult;
     // Assert.AreEqual(url, result.ViewBag.ReturnUrl); // ERROR?
 }
        public void TestAccountControllerLogOff()
        {
            Controllers.AccountController controller = new Controllers.AccountController();
            ActionResult result = controller.LogOff() as ActionResult;

            Assert.IsInstanceOfType(result, typeof(RedirectToRouteResult));
            RedirectToRouteResult routeResult = result as RedirectToRouteResult;

            Assert.AreEqual(routeResult.RouteValues["action"], "Index");
        }
        public void TestAccountControllerResetPassword()
        {
            Controllers.AccountController controler = new Controllers.AccountController();
            string     code1   = "TEST";
            string     code2   = null;
            ViewResult result1 = controler.ResetPassword(code1) as ViewResult;
            ViewResult result2 = controler.ResetPassword(code2) as ViewResult;

            Assert.IsNotNull(result1);
            Assert.AreEqual("Error", result2.ViewName);
        }
示例#6
0
        public static async System.Threading.Tasks.Task <bool> CreateUserIfNotExists(Controllers.AccountController ctrl, string username, string password)
        {
            if (ctrl.SignInManager.UserManager.FindByEmail(username) == null)
            {
                var user = new Models.ApplicationUser {
                    UserName = username, Email = password
                };
                await ctrl.SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false);

                return(true);
            }
            return(false);
        }
        public void NavigateToPostPage()
        {
            K21T3_Team1_PPC3129Entities get = new K21T3_Team1_PPC3129Entities();

            Controllers.AccountController user = new Controllers.AccountController();

            var controller = new PropertyAgencyController();

            var moqContext = new Moq.Mock <ControllerContext>();
            var moqSession = new Moq.Mock <HttpSessionStateBase>();

            moqContext.Setup(c => c.HttpContext.Session).Returns(moqSession.Object);

            var us = get.USER.FirstOrDefault(x => x.Email == "*****@*****.**");

            //user.ControllerContext = moqContext.Object;

            controller.ControllerContext = moqContext.Object;
            moqSession.Setup(s => s["UserRole"]).Returns(us.Role);
            moqSession.Setup(s => s["UserID"]).Returns(us.ID);

            _result = controller.Index();
        }
示例#8
0
        public ActionResult Create(UserMerchantViewModel userMerchantViewModel, HttpPostedFileBase file)
        {
            logger.Info("Create Post Method Start" + " at " + DateTime.UtcNow);
            EasyPayContext dbContext = new EasyPayContext();
            string path = utils.SaveFile(file);
            Merchant thisMerchant = new Merchant();
            RegisterModel registerModel = new RegisterModel();

            if (userMerchantViewModel != null)
            {
                thisMerchant.Address = registerModel.Address = userMerchantViewModel.Merchant.Address;
                thisMerchant.CategoryId = userMerchantViewModel.Merchant.CategoryId;
                thisMerchant.City = registerModel.City = userMerchantViewModel.Merchant.City;
                thisMerchant.ContactNo = userMerchantViewModel.Merchant.ContactNo;
                thisMerchant.EmailId = registerModel.Email = userMerchantViewModel.Merchant.EmailId;
                thisMerchant.LogoImagePath = path;
                thisMerchant.MerchantName = userMerchantViewModel.Merchant.MerchantName;
                thisMerchant.PostalCode = registerModel.PostalCode = userMerchantViewModel.Merchant.PostalCode;
                thisMerchant.State_StateID = Convert.ToInt32(userMerchantViewModel.RegisterModel.StateID);
                thisMerchant.Terms = userMerchantViewModel.Merchant.Terms;
                thisMerchant.URL = userMerchantViewModel.Merchant.URL;


                registerModel.UserName = userMerchantViewModel.RegisterModel.UserName;
                registerModel.StateID = userMerchantViewModel.RegisterModel.StateID;
                registerModel.Phone = userMerchantViewModel.Merchant.ContactNo;
                registerModel.Password = userMerchantViewModel.RegisterModel.Password;
                registerModel.ConfirmPassword = userMerchantViewModel.RegisterModel.Password;

                AccountController AccountController = new Controllers.AccountController();

                string dbToken = AccountController.RegisterUser(registerModel);
                var userId = dbContext.UserProfiles.Where(p => p.UserName == registerModel.UserName).Select(u => u.UserProfileId).FirstOrDefault();
                thisMerchant.UserProfileId = userId;
                dbContext.Merchants.Add(thisMerchant);
                WebSecurity.ConfirmAccount(userMerchantViewModel.RegisterModel.UserName, dbToken);

                dbContext.SaveChanges();
                logger.Info("Create Post Method New Merchant Created " + " at " + DateTime.UtcNow);
                //EasyPayContext dbContext1 = new EasyPayContext();
                //EasyPay.Models.Membership membership = dbContext1.Memberships.Where(m => m.UserId == userId).FirstOrDefault();
                ////var confirm = dbContext1.Memberships.Where(m => m.UserId == userId).FirstOrDefault();
                //if (membership.IsConfirmed == false)
                //{

                //    membership.IsConfirmed = true;
                //    dbContext1.SaveChanges();
                //}
                EasyPayContext dbContext2 = new EasyPayContext();
                string newRoleName = "Merchant";
                if (!Roles.RoleExists(newRoleName))
                {
                    logger.Info("Create new Role Merchant" + " at " + DateTime.UtcNow);
                    Roles.CreateRole(newRoleName);
                }
                var checkUserRole = dbContext2.UsersInRoles.ToList().FirstOrDefault(r => r.UserId == userId);
                if (checkUserRole == null)
                {
                    logger.Info("Assign role Merchant to User " + userId + " at " + DateTime.UtcNow);
                    dbContext2.UsersInRoles.Add(new UsersInRole()
                    {
                        RoleId = dbContext2.Roles.Where(r => r.RoleName == newRoleName).Select(r => r.RoleId).FirstOrDefault(),
                        UserId = userId
                        //RoleId=Roles.
                    });
                    dbContext2.SaveChanges();
                }
                logger.Info("Method End" + " at " + DateTime.UtcNow);
                return RedirectToAction("Index");
            }

            ViewBag.CategoryId = new SelectList(dbContext.Categories, "CategoryId", "CategoryName", userMerchantViewModel.Merchant.CategoryId);
            logger.Info("Create Method End" + " at " + DateTime.UtcNow);
            return View(userMerchantViewModel);
            //return View();
        }