public async Task DeleteIdentityResource() { //Get Services var serviceProvider = GetServices(); var dbContext = serviceProvider.GetRequiredService <IdentityServerConfigurationDbContext>(); var identityResourceService = serviceProvider.GetRequiredService <IIdentityResourceService>(); // Get controller var controller = PrepareConfigurationController(serviceProvider); var identityResourceDto = IdentityResourceDtoMock.GenerateRandomIdentityResource(0); await identityResourceService.AddIdentityResourceAsync(identityResourceDto); var identityResourceId = await dbContext.IdentityResources.Where(x => x.Name == identityResourceDto.Name).Select(x => x.Id).SingleOrDefaultAsync(); identityResourceId.Should().NotBe(0); identityResourceDto.Id = identityResourceId; var result = await controller.IdentityResourceDelete(identityResourceDto); // Assert var viewResult = Assert.IsType <RedirectToActionResult>(result); viewResult.ActionName.Should().Be("IdentityResources"); var identityResource = await dbContext.IdentityResources.Where(x => x.Id == identityResourceDto.Id).SingleOrDefaultAsync(); identityResource.Should().BeNull(); }
public async Task UpdateIdentityResourceAsync() { using (var context = new IdentityServerConfigurationDbContext(_dbContextOptions, _storeOptions)) { var identityResourceService = GetIdentityResourceService(context); //Generate random new identity resource var identityResourceDto = IdentityResourceDtoMock.GenerateRandomIdentityResource(0); await identityResourceService.AddIdentityResourceAsync(identityResourceDto); //Get new identity resource var identityResource = await context.IdentityResources.Where(x => x.Name == identityResourceDto.Name).SingleOrDefaultAsync(); var newIdentityResourceDto = await identityResourceService.GetIdentityResourceAsync(identityResource.Id); //Assert new identity resource identityResourceDto.ShouldBeEquivalentTo(newIdentityResourceDto, options => options.Excluding(o => o.Id)); //Detached the added item context.Entry(identityResource).State = EntityState.Detached; //Generete new identity resuorce with added item id var updatedIdentityResource = IdentityResourceDtoMock.GenerateRandomIdentityResource(identityResource.Id); //Update identity resuorce await identityResourceService.UpdateIdentityResourceAsync(updatedIdentityResource); var updatedIdentityResourceDto = await identityResourceService.GetIdentityResourceAsync(identityResource.Id); //Assert updated identity resuorce updatedIdentityResource.ShouldBeEquivalentTo(updatedIdentityResourceDto, options => options.Excluding(o => o.Id)); } }
public async Task RemoveIdentityResourceAsync() { using (var context = new AdminDbContext(_dbContextOptions, _storeOptions, _operationalStore)) { IIdentityResourceRepository identityResourceRepository = new IdentityResourceRepository(context); var localizerIdentityResourceMock = new Mock <IIdentityResourceServiceResources>(); var localizerIdentityResource = localizerIdentityResourceMock.Object; IIdentityResourceService identityResourceService = new IdentityResourceService(identityResourceRepository, localizerIdentityResource); //Generate random new identity resource var identityResourceDto = IdentityResourceDtoMock.GenerateRandomIdentityResource(0); await identityResourceService.AddIdentityResourceAsync(identityResourceDto); //Get new identity resource var identityResource = await context.IdentityResources.Where(x => x.Name == identityResourceDto.Name).SingleOrDefaultAsync(); var newIdentityResourceDto = await identityResourceService.GetIdentityResourceAsync(identityResource.Id); //Assert new identity resource identityResourceDto.ShouldBeEquivalentTo(newIdentityResourceDto, options => options.Excluding(o => o.Id)); //Remove identity resource await identityResourceService.DeleteIdentityResourceAsync(newIdentityResourceDto); //Try Get Removed identity resource var removeIdentityResource = await context.IdentityResources.Where(x => x.Id == identityResource.Id) .SingleOrDefaultAsync(); //Assert removed identity resource removeIdentityResource.Should().BeNull(); } }
public async Task RemoveIdentityResourceAsync() { using (var context = new IdentityServerConfigurationDbContext(_dbContextOptions, _storeOptions)) { var identityResourceService = GetIdentityResourceService(context); //Generate random new identity resource var identityResourceDto = IdentityResourceDtoMock.GenerateRandomIdentityResource(0); await identityResourceService.AddIdentityResourceAsync(identityResourceDto); //Get new identity resource var identityResource = await context.IdentityResources.Where(x => x.Name == identityResourceDto.Name).SingleOrDefaultAsync(); var newIdentityResourceDto = await identityResourceService.GetIdentityResourceAsync(identityResource.Id); //Assert new identity resource identityResourceDto.ShouldBeEquivalentTo(newIdentityResourceDto, options => options.Excluding(o => o.Id)); //Remove identity resource await identityResourceService.DeleteIdentityResourceAsync(newIdentityResourceDto); //Try Get Removed identity resource var removeIdentityResource = await context.IdentityResources.Where(x => x.Id == identityResource.Id) .SingleOrDefaultAsync(); //Assert removed identity resource removeIdentityResource.Should().BeNull(); } }
public async Task GetIdentityResourceAsync() { using (var context = new IdentityServerConfigurationDbContext(_dbContextOptions, _storeOptions)) { var identityResourceRepository = GetIdentityResourceRepository(context); var localizerIdentityResourceMock = new Mock <IIdentityResourceServiceResources>(); var localizerIdentityResource = localizerIdentityResourceMock.Object; var identityResourceService = GetIdentityResourceService(identityResourceRepository, localizerIdentityResource); //Generate random new identity resource var identityResourceDto = IdentityResourceDtoMock.GenerateRandomIdentityResource(0); await identityResourceService.AddIdentityResourceAsync(identityResourceDto); //Get new identity resource var identityResource = await context.IdentityResources.Where(x => x.Name == identityResourceDto.Name).SingleOrDefaultAsync(); var newIdentityResourceDto = await identityResourceService.GetIdentityResourceAsync(identityResource.Id); //Assert new identity resource identityResourceDto.Should().BeEquivalentTo(newIdentityResourceDto, options => options.Excluding(o => o.Id)); } }
public async Task DeleteIdentityResourcePropertyAsync() { using (var context = new IdentityServerConfigurationDbContext(_dbContextOptions, _storeOptions)) { var identityResourceRepository = GetIdentityResourceRepository(context); var localizerIdentityResourceMock = new Mock <IIdentityResourceServiceResources>(); var localizerIdentityResource = localizerIdentityResourceMock.Object; var identityResourceService = GetIdentityResourceService(identityResourceRepository, localizerIdentityResource); //Generate random new identity resource var resourceDto = IdentityResourceDtoMock.GenerateRandomIdentityResource(0); await identityResourceService.AddIdentityResourceAsync(resourceDto); //Get new identity resource var resource = await context.IdentityResources.Where(x => x.Name == resourceDto.Name).SingleOrDefaultAsync(); var identityResourceDto = await identityResourceService.GetIdentityResourceAsync(resource.Id); //Assert new identity resource resourceDto.Should().BeEquivalentTo(identityResourceDto, options => options.Excluding(o => o.Id)); //Generate random new identity resource Property var identityResourcePropertiesDto = IdentityResourceDtoMock.GenerateRandomIdentityResourceProperty(0, resource.Id); //Add new identity resource Property await identityResourceService.AddIdentityResourcePropertyAsync(identityResourcePropertiesDto); //Get inserted identity resource Property var property = await context.IdentityResourceProperties.Where(x => x.Value == identityResourcePropertiesDto.Value && x.IdentityResource.Id == resource.Id) .SingleOrDefaultAsync(); //Map entity to model var propertiesDto = property.ToModel(); //Get new identity resource Property var resourcePropertiesDto = await identityResourceService.GetIdentityResourcePropertyAsync(property.Id); //Assert resourcePropertiesDto.Should().BeEquivalentTo(propertiesDto, options => options.Excluding(o => o.IdentityResourcePropertyId) .Excluding(o => o.IdentityResourceName)); //Delete identity resource Property await identityResourceService.DeleteIdentityResourcePropertyAsync(resourcePropertiesDto); //Get removed identity resource Property var identityResourceProperty = await context.IdentityResourceProperties.Where(x => x.Id == property.Id).SingleOrDefaultAsync(); //Assert after delete it identityResourceProperty.Should().BeNull(); } }
public void CanMapIdentityResourceDtoToEntity() { //Generate DTO var identityResourceDto = IdentityResourceDtoMock.GenerateRandomIdentityResource(1); //Try map to entity var identityResource = identityResourceDto.ToEntity(); identityResource.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 GetIdentityResourcePropertyAsync() { using (var context = new IdentityServerConfigurationDbContext(_dbContextOptions, _storeOptions)) { var identityResourceService = GetIdentityResourceService(context); //Generate random new identity resource var identityResource = IdentityResourceDtoMock.GenerateRandomIdentityResource(0); await identityResourceService.AddIdentityResourceAsync(identityResource); //Get new identity resource var resource = await context.IdentityResources.Where(x => x.Name == identityResource.Name).SingleOrDefaultAsync(); var identityResourceDto = await identityResourceService.GetIdentityResourceAsync(resource.Id); //Assert new identity resource identityResource.ShouldBeEquivalentTo(identityResourceDto, options => options.Excluding(o => o.Id)); //Generate random new identity resource property var identityResourceProperty = IdentityResourceDtoMock.GenerateRandomIdentityResourceProperty(0, resource.Id); //Add new identity resource property await identityResourceService.AddIdentityResourcePropertyAsync(identityResourceProperty); //Get inserted identity resource property var property = await context.IdentityResourceProperties.Where(x => x.Value == identityResourceProperty.Value && x.IdentityResource.Id == resource.Id) .SingleOrDefaultAsync(); //Map entity to model var propertyDto = property.ToModel(); //Get new identity resource property var resourcePropertiesDto = await identityResourceService.GetIdentityResourcePropertyAsync(property.Id); //Assert resourcePropertiesDto.ShouldBeEquivalentTo(propertyDto, options => options.Excluding(o => o.IdentityResourcePropertyId) .Excluding(o => o.IdentityResourceName)); } }
public async Task UpdateIdentityResourceAsync() { using (var context = new AdminDbContext(_dbContextOptions, _storeOptions, _operationalStore)) { IIdentityResourceRepository identityResourceRepository = new IdentityResourceRepository(context); var localizerIdentityResourceMock = new Mock <IIdentityResourceServiceResources>(); var localizerIdentityResource = localizerIdentityResourceMock.Object; IIdentityResourceService identityResourceService = new IdentityResourceService(identityResourceRepository, localizerIdentityResource); //Generate random new identity resource var identityResourceDto = IdentityResourceDtoMock.GenerateRandomIdentityResource(0); await identityResourceService.AddIdentityResourceAsync(identityResourceDto); //Get new identity resource var identityResource = await context.IdentityResources.Where(x => x.Name == identityResourceDto.Name).SingleOrDefaultAsync(); var newIdentityResourceDto = await identityResourceService.GetIdentityResourceAsync(identityResource.Id); //Assert new identity resource identityResourceDto.Should().BeEquivalentTo(newIdentityResourceDto, options => options.Excluding(o => o.Id)); //Detached the added item context.Entry(identityResource).State = EntityState.Detached; //Generete new identity resuorce with added item id var updatedIdentityResource = IdentityResourceDtoMock.GenerateRandomIdentityResource(identityResource.Id); //Update identity resuorce await identityResourceService.UpdateIdentityResourceAsync(updatedIdentityResource); var updatedIdentityResourceDto = await identityResourceService.GetIdentityResourceAsync(identityResource.Id); //Assert updated identity resuorce updatedIdentityResource.Should().BeEquivalentTo(updatedIdentityResourceDto, options => options.Excluding(o => o.Id)); } }
public async Task AddIdentityResource() { //Get Services var serviceProvider = GetServices(); var dbContext = serviceProvider.GetRequiredService <IdentityServerConfigurationDbContext>(); var identityResourceService = serviceProvider.GetRequiredService <IIdentityResourceService>(); // Get controller var controller = PrepareConfigurationController(serviceProvider); var identityResourceDto = IdentityResourceDtoMock.GenerateRandomIdentityResource(0); var result = await controller.IdentityResource(identityResourceDto); // Assert var viewResult = Assert.IsType <RedirectToActionResult>(result); viewResult.ActionName.Should().Be("IdentityResource"); var identityResource = await dbContext.IdentityResources.Where(x => x.Name == identityResourceDto.Name).SingleOrDefaultAsync(); var addedIdentityResource = await identityResourceService.GetIdentityResourceAsync(identityResource.Id); identityResourceDto.Should().BeEquivalentTo(addedIdentityResource, opts => opts.Excluding(x => x.Id)); }