Esempio n. 1
0
        public ActionResult Add(AddUserVM newUser)
        {
            IEnumerable <IdentityRole> roles = roleAppService.GetALL();

            newUser.AllRoles = roles;
            if (ModelState.IsValid == false)
            {
                return(View(newUser));
            }
            string         roleName = Request["Role"];
            IdentityResult result   = userAppService.AddUser(newUser);

            if (result.Succeeded)
            {
                ApplicationUserIdentity identityUser = userAppService.Find(newUser.UserName, newUser.PasswordHash);
                userAppService.AssignToRole(identityUser.Id, roleName);
                TempData["Msg"] = "New User Added Successfully";
                return(RedirectToAction("Index"));
            }
            else
            {
                ModelState.AddModelError("", result.Errors.FirstOrDefault());
                return(View(newUser));
            }
        }
        public void Should_Get_By_Id()
        {
            var service    = new UserService(_repository);
            var appService = new UserAppService(service, _mapper);
            var actual     = appService.Find(a => a.Id == fakeData[0].Id).FirstOrDefault();

            Assert.NotNull(actual);

            var changed = appService.GetById(actual.Id);

            Assert.NotNull(changed);
        }
        public void Dever_Encontrar_Usuario_Find()
        {
            var service    = new UserService(_repository);
            var appService = new UserAppService(service, _mapper);

            var user = fakeData.FirstOrDefault();

            Assert.NotNull(user);

            var actual = appService.Find(e => e.Email == user.Email);

            Assert.NotNull(actual);

            Assert.Equal(user.Name, actual.FirstOrDefault().Name);
        }