public void Create_Get_AsksForCreateView()
        {
            RoleAdminController controller = GetNewRoleAdminController(null, null);

            ViewResult result = controller.Create() as ViewResult;

            Assert.AreEqual("Create", result.ViewName);
        }
        public async Task Create_Post_ModelStateIsValidAndIdentityResultNotSucceeded_AsksForCreateView()
        {
            Mock <RoleStore <AppRole> > roleStore   = new Mock <RoleStore <AppRole> >();
            Mock <AppRoleManager>       roleManager = new Mock <AppRoleManager>(roleStore.Object);

            roleManager.Setup(m => m.CreateAsync(It.IsAny <AppRole>())).ReturnsAsync(IdentityResult.Failed(""));
            RoleAdminController controller = GetNewRoleAdminController(null, roleManager.Object);

            ViewResult result = (await controller.Create("")) as ViewResult;

            Assert.AreEqual("Create", result.ViewName);
        }
        public async Task Create_Post_ModelStateIsValidAndIdentityResultSucceeded_RedirectToIndex()
        {
            Mock <RoleStore <AppRole> > roleStore   = new Mock <RoleStore <AppRole> >();
            Mock <AppRoleManager>       roleManager = new Mock <AppRoleManager>(roleStore.Object);

            roleManager.Setup(m => m.CreateAsync(It.IsAny <AppRole>())).ReturnsAsync(IdentityResult.Success);
            RoleAdminController controller = GetNewRoleAdminController(null, roleManager.Object);

            RedirectToRouteResult result = (await controller.Create("")) as RedirectToRouteResult;

            Assert.AreEqual("Index", result.RouteValues["action"]);
        }
        public async Task Create_Post_ModelStateIsInvalid_AsksForCreateView()
        {
            Mock <RoleStore <AppRole> > roleStore   = new Mock <RoleStore <AppRole> >();
            Mock <AppRoleManager>       roleManager = new Mock <AppRoleManager>(roleStore.Object);
            RoleAdminController         controller  = GetNewRoleAdminController(null, roleManager.Object);

            controller.ModelState.AddModelError("", "Error");

            ViewResult result = (await controller.Create("")) as ViewResult;

            Assert.AreEqual("Create", result.ViewName);
        }
        public async Task Create_Post_ModelStateIsValidAndIdentityResultNotSucceeded_AddsErrorToModelState()
        {
            Mock <RoleStore <AppRole> > roleStore   = new Mock <RoleStore <AppRole> >();
            Mock <AppRoleManager>       roleManager = new Mock <AppRoleManager>(roleStore.Object);

            roleManager.Setup(m => m.CreateAsync(It.IsAny <AppRole>())).ReturnsAsync(IdentityResult.Failed("Custom Error"));
            RoleAdminController controller = GetNewRoleAdminController(null, roleManager.Object);

            ViewResult result = (await controller.Create("")) as ViewResult;

            Assert.AreEqual(1, controller.ModelState.Count);
            Assert.AreEqual("Custom Error", controller.ModelState.Values.First().Errors.First().ErrorMessage);
        }