Ejemplo n.º 1
0
        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();
            }
        }
Ejemplo n.º 2
0
        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.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));
            }
        }