Example #1
0
        public async Task DeleteRoleAsync()
        {
            using (var context = new AdminDbContext(_dbContextOptions, _storeOptions, _operationalStore))
            {
                var testUserManager = GetTestUserManager(context);
                var testRoleManager = GetTestRoleManager(context);

                IIdentityRepository identityRepository = new IdentityRepository(context, testUserManager, testRoleManager);
                var localizerIdentityResource          = new IdentityServiceResources();

                IIdentityService identityService = new IdentityService(identityRepository, localizerIdentityResource);

                //Generate random new role
                var roleDto = IdentityDtoMock.GenerateRandomRole(Guid.NewGuid());

                await identityService.CreateRoleAsync(roleDto);

                //Get new role
                var role = await context.Roles.Where(x => x.Name == roleDto.Name).SingleOrDefaultAsync();

                roleDto.Id = role.Id;

                var newRoleDto = await identityService.GetRoleAsync(roleDto);

                //Assert new role
                roleDto.Should().BeEquivalentTo(newRoleDto);

                //Remove role
                await identityService.DeleteRoleAsync(newRoleDto);

                //Try Get Removed role
                var removeRole = await context.Roles.Where(x => x.Id == role.Id)
                                 .SingleOrDefaultAsync();

                //Assert removed role
                removeRole.Should().BeNull();
            }
        }