public async Task EditExistingRole()
        {
            var role = new Assessment.Models.Role {
                Name = "Test", Id = Guid.NewGuid().ToString(),
            };
            var expectedRoleCount = applicationDbContext.Roles.Count() + 1;
            var actualRoleCount   = -1;

            await controller.Create(role);

            role.Name = "Updated Test";
            var view = await controller.Edit(role.Id, role);

            var result = view as RedirectToActionResult;

            var updatedRole = await applicationDbContext.Roles
                              .AsNoTracking()
                              .Where(x => x.Id == role.Id)
                              .FirstOrDefaultAsync();

            actualRoleCount = applicationDbContext.Roles.Count();

            Assert.IsNotNull(result);
            Assert.AreEqual(role.Name, updatedRole.Name);
            Assert.AreEqual(expectedRoleCount, actualRoleCount);
        }
        public async Task <IActionResult> Create(Assessment.Models.Role role)
        {
            if (ModelState.IsValid)
            {
                role.Id = Guid.NewGuid().ToString();
                var result = await _roleManager.CreateAsync(role);

                if (result.Succeeded)
                {
                    return(RedirectToAction(nameof(Index)));
                }
            }
            return(View(nameof(Create), role));
        }
        public async Task DeleteExistingRole()
        {
            var role = new Assessment.Models.Role {
                Name = "Test", Id = Guid.NewGuid().ToString(),
            };
            var expectedRoleCount = applicationDbContext.Roles.Count();
            var actualRoleCount   = -1;

            await controller.Create(role);

            var view = await controller.DeleteConfirmed(role.Id);

            var result = view as RedirectToActionResult;

            actualRoleCount = applicationDbContext.Roles.Count();

            Assert.IsNotNull(result);
            Assert.AreEqual(expectedRoleCount, actualRoleCount);
        }
        public async Task <IActionResult> Edit(string id, Assessment.Models.Role role)
        {
            if (id != role.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    var r = await _roleManager.FindByIdAsync(id);

                    if (r == null)
                    {
                        return(NotFound());
                    }

                    r.Name           = role.Name;
                    r.NormalizedName = role.Name.ToUpperInvariant();
                    r.Description    = role.Description;

                    var result = await _roleManager.UpdateAsync(r);

                    if (result.Succeeded)
                    {
                        return(RedirectToAction(nameof(Index)));
                    }
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!RoleExists(role.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
            }
            return(View(nameof(Edit), role));
        }