public async Task DeleteIdentityResourceAsync() { using (var context = new IdentityServerConfigurationDbContext(_dbContextOptions, _storeOptions)) { var identityResourceRepository = GetIdentityResourceRepository(context); //Generate random new identity resource var identityResource = IdentityResourceMock.GenerateRandomIdentityResource(0); //Add new identity resource await identityResourceRepository.AddIdentityResourceAsync(identityResource); //Get new identity resource var newIdentityResource = await context.IdentityResources.Where(x => x.Id == identityResource.Id).SingleAsync(); //Assert new identity resource newIdentityResource.ShouldBeEquivalentTo(identityResource, options => options.Excluding(o => o.Id)); //Delete identity resource await identityResourceRepository.DeleteIdentityResourceAsync(newIdentityResource); //Get deleted identity resource var deletedIdentityResource = await context.IdentityResources.Where(x => x.Id == identityResource.Id).SingleOrDefaultAsync(); //Assert if it not exist deletedIdentityResource.Should().BeNull(); } }
public async Task UpdateIdentityResourceAsync() { using (var context = new IdentityServerConfigurationDbContext(_dbContextOptions, _storeOptions)) { var identityResourceRepository = GetIdentityResourceRepository(context); //Generate random new identity resource var identityResource = IdentityResourceMock.GenerateRandomIdentityResource(0); //Add new identity resource await identityResourceRepository.AddIdentityResourceAsync(identityResource); //Get new identity resource var newIdentityResource = await context.IdentityResources.Where(x => x.Id == identityResource.Id).SingleOrDefaultAsync(); //Assert new identity resource newIdentityResource.ShouldBeEquivalentTo(identityResource, options => options.Excluding(o => o.Id)); //Detached the added item context.Entry(newIdentityResource).State = EntityState.Detached; //Generete new identity resource with added item id var updatedIdentityResource = IdentityResourceMock.GenerateRandomIdentityResource(newIdentityResource.Id); //Update identity resource await identityResourceRepository.UpdateIdentityResourceAsync(updatedIdentityResource); //Get updated identity resource var updatedIdentityResourceEntity = await context.IdentityResources.Where(x => x.Id == updatedIdentityResource.Id).SingleAsync(); //Assert updated identity resource updatedIdentityResource.ShouldBeEquivalentTo(updatedIdentityResourceEntity); } }
public async Task GetIdentityResourcePropertyAsync() { using (var context = new IdentityServerConfigurationDbContext(_dbContextOptions, _storeOptions)) { var identityResourceRepository = GetIdentityResourceRepository(context); //Generate random new identity resource without id var identityResource = IdentityResourceMock.GenerateRandomIdentityResource(0); //Add new identity resource await identityResourceRepository.AddIdentityResourceAsync(identityResource); //Get new identity resource var resource = await identityResourceRepository.GetIdentityResourceAsync(identityResource.Id); //Assert new identity resource resource.ShouldBeEquivalentTo(identityResource, options => options.Excluding(o => o.Id).Excluding(o => o.UserClaims)); resource.UserClaims.ShouldBeEquivalentTo(identityResource.UserClaims, option => option.Excluding(x => x.SelectedMemberPath.EndsWith("Id")) .Excluding(x => x.SelectedMemberPath.EndsWith("IdentityResource"))); //Generate random new identity resource property var identityResourceProperty = IdentityResourceMock.GenerateRandomIdentityResourceProperty(0); //Add new identity resource property await identityResourceRepository.AddIdentityResourcePropertyAsync(resource.Id, identityResourceProperty); //Get new identity resource property var resourceProperty = await identityResourceRepository.GetIdentityResourcePropertyAsync(identityResourceProperty.Id); resourceProperty.ShouldBeEquivalentTo(identityResourceProperty, options => options.Excluding(o => o.Id).Excluding(x => x.IdentityResource)); } }
public async Task AddIdentityResourcePropertyAsync() { using (var context = new IdentityServerConfigurationDbContext(_dbContextOptions, _storeOptions)) { var identityResourceRepository = GetIdentityResourceRepository(context); //Generate random new identity resource without id var identityResource = IdentityResourceMock.GenerateRandomIdentityResource(0); //Add new identity resource await identityResourceRepository.AddIdentityResourceAsync(identityResource); //Get new identity resource var resource = await identityResourceRepository.GetIdentityResourceAsync(identityResource.Id); //Assert new identity resource resource.Should().BeEquivalentTo(identityResource, options => options.Excluding(o => o.Id)); //Generate random new identity resource property var identityResourceProperty = IdentityResourceMock.GenerateRandomIdentityResourceProperty(0); //Add new identity resource property await identityResourceRepository.AddIdentityResourcePropertyAsync(resource.Id, identityResourceProperty); //Get new identity resource property var resourceProperty = await context.IdentityResourceProperties.Where(x => x.Id == identityResourceProperty.Id) .SingleOrDefaultAsync(); resourceProperty.Should().BeEquivalentTo(identityResourceProperty, options => options.Excluding(o => o.Id).Excluding(x => x.IdentityResource)); } }
public async Task GetIdentityResourcePropertyAsync() { using (var context = new AdminDbContext(_dbContextOptions, _storeOptions, _operationalStore)) { var identityResourceRepository = GetIdentityResourceRepository(context); //Generate random new identity resource without id var identityResource = IdentityResourceMock.GenerateRandomIdentityResource(0); //Add new identity resource await identityResourceRepository.AddIdentityResourceAsync(identityResource); //Get new identity resource var resource = await identityResourceRepository.GetIdentityResourceAsync(identityResource.Id); //Assert new identity resource resource.ShouldBeEquivalentTo(identityResource, options => options.Excluding(o => o.Id)); //Generate random new identity resource property var identityResourceProperty = IdentityResourceMock.GenerateRandomIdentityResourceProperty(0); //Add new identity resource property await identityResourceRepository.AddIdentityResourcePropertyAsync(resource.Id, identityResourceProperty); //Get new identity resource property var resourceProperty = await identityResourceRepository.GetIdentityResourcePropertyAsync(identityResourceProperty.Id); resourceProperty.ShouldBeEquivalentTo(identityResourceProperty, options => options.Excluding(o => o.Id).Excluding(x => x.IdentityResource)); } }
public async Task GetScopesIdentityResourceAsync() { IClientRepository clientRepository = new ClientDapperRepository(_configuration); IIdentityResourceRepository identityResourceRepository = new IdentityResourceDapperRepository(_configuration); var identityResource = IdentityResourceMock.GenerateRandomIdentityResource(); await identityResourceRepository.AddIdentityResourceAsync(identityResource); var identityScopes = await clientRepository.GetScopesAsync(identityResource.Name); identityScopes[0].Should().Be(identityResource.Name); }
public async Task GetScopesIdentityResourceAsync() { using (var context = new IdentityServerConfigurationDbContext(_dbContextOptions, _storeOptions)) { var clientRepository = GetClientRepository(context); var identityResourceRepository = GetIdentityResourceRepository(context); var identityResource = IdentityResourceMock.GenerateRandomIdentityResource(0); await identityResourceRepository.AddIdentityResourceAsync(identityResource); var identityScopes = await clientRepository.GetScopesAsync(identityResource.Name); identityScopes[0].Should().Be(identityResource.Name); } }
public async Task GetScopesIdentityResourceAsync() { using (var context = new AdminDbContext(_dbContextOptions, _storeOptions, _operationalStore)) { IClientRepository clientRepository = new ClientRepository(context); IIdentityResourceRepository identityResourceRepository = new IdentityResourceRepository(context); var identityResource = IdentityResourceMock.GenerateRandomIdentityResource(0); await identityResourceRepository.AddIdentityResourceAsync(identityResource); var identityScopes = await clientRepository.GetScopesAsync(identityResource.Name); identityScopes[0].Should().Be(identityResource.Name); } }
public void CanMapIdentityResourceToModel() { //Generate entity var identityResource = IdentityResourceMock.GenerateRandomIdentityResource(1); //Try map to DTO var identityResourceDto = identityResource.ToModel(); //Asert identityResourceDto.Should().NotBeNull(); identityResource.Should().BeEquivalentTo(identityResourceDto, options => options.Excluding(o => o.UserClaims)); //Assert collection identityResource.UserClaims.Select(x => x.Type).Should().BeEquivalentTo(identityResourceDto.UserClaims); }
public async Task GetIdentityResourceAsync() { using (var context = new ConfigurationDbContext(_dbContextOptions, _storeOptions, _operationalStore)) { IIdentityResourceRepository identityResourceRepository = new IdentityResourceRepository(context); //Generate random new identity resource var identityResource = IdentityResourceMock.GenerateRandomIdentityResource(0); //Add new identity resource await identityResourceRepository.AddIdentityResourceAsync(identityResource); //Get new identity resource var newIdentityResource = await identityResourceRepository.GetIdentityResourceAsync(identityResource.Id); //Assert new identity resource newIdentityResource.ShouldBeEquivalentTo(identityResource, options => options.Excluding(o => o.Id)); } }
public async Task AddIdentityResourceAsync() { using (var context = new AdminDbContext(_dbContextOptions, _storeOptions, _operationalStore)) { var identityResourceRepository = GetIdentityResourceRepository(context); //Generate random new identity resource var identityResource = IdentityResourceMock.GenerateRandomIdentityResource(0); //Add new identity resource await identityResourceRepository.AddIdentityResourceAsync(identityResource); //Get new identity resource var newIdentityResource = await context.IdentityResources.Where(x => x.Id == identityResource.Id).SingleAsync(); //Assert new identity resource newIdentityResource.ShouldBeEquivalentTo(identityResource, options => options.Excluding(o => o.Id)); } }
public async Task GetIdentityResourceAsync() { using (var context = new IdentityServerConfigurationDbContext(_dbContextOptions, _storeOptions)) { var identityResourceRepository = GetIdentityResourceRepository(context); //Generate random new identity resource var identityResource = IdentityResourceMock.GenerateRandomIdentityResource(0); //Add new identity resource await identityResourceRepository.AddIdentityResourceAsync(identityResource); //Get new identity resource var newIdentityResource = await identityResourceRepository.GetIdentityResourceAsync(identityResource.Id); //Assert new identity resource newIdentityResource.Should().BeEquivalentTo(identityResource, options => options.Excluding(o => o.Id).Excluding(o => o.UserClaims)); newIdentityResource.UserClaims.Should().BeEquivalentTo(identityResource.UserClaims, option => option.Excluding(x => x.Path.EndsWith("Id")) .Excluding(x => x.Path.EndsWith("IdentityResource"))); } }