public async Task DeleteAsync_should_remove_entity_id_from_parent()
        {
            using var store = new RavenDbTestDriverWrapper().GetDocumentStore();

            var entity = new TEntity
            {
                Id         = Guid.NewGuid().ToString(),
                IdentityId = "test"
            };
            var identity = new Entity.IdentityResource
            {
                Id = "test",
            };
            var collection = GetCollection(identity);

            collection.Add(new TEntity
            {
                Id = $"{typeof(TEntity).Name.ToLowerInvariant()}/{entity.Id}"
            });

            using var s1 = store.OpenAsyncSession();
            await s1.StoreAsync(identity, $"{nameof(Entity.IdentityResource).ToLowerInvariant()}/{identity.Id}");

            await s1.StoreAsync(entity, $"{typeof(TEntity).Name.ToLowerInvariant()}/{entity.Id}");

            await s1.SaveChangesAsync();

            var loggerMock = new Mock <ILogger <AdminStore <TEntity> > >();

            using var session = store.OpenAsyncSession();

            var sut = CreateSut(session, loggerMock.Object);


            await sut.DeleteAsync(entity.Id);

            using var s2 = store.OpenAsyncSession();
            var updated = await s2.LoadAsync <Entity.IdentityResource>($"{nameof(Entity.IdentityResource).ToLowerInvariant()}/test");

            var updatedCollection = GetCollection(updated);

            Assert.DoesNotContain(updatedCollection, i => i.Id == $"{typeof(TEntity).Name.ToLowerInvariant()}/{entity.Id}");
        }
示例#2
0
        public static IdentityResource ToIdentity(this Entity.IdentityResource identity)
        {
            if (identity == null)
            {
                return(null);
            }

            return(new IdentityResource
            {
                Description = identity.Description,
                DisplayName = identity.DisplayName,
                Emphasize = identity.Emphasize,
                Enabled = identity.Enabled,
                Name = identity.Id,
                Properties = identity.Properties.ToDictionary(p => p.Key, p => p.Value),
                Required = identity.Required,
                ShowInDiscoveryDocument = identity.ShowInDiscoveryDocument,
                UserClaims = identity.IdentityClaims.Select(c => c.Type).ToList()
            });
        }
示例#3
0
        public static IdentityResource ToIdentity(this Entity.IdentityResource identity)
        {
            if (identity == null)
            {
                return(null);
            }
            var cultureId = CultureInfo.CurrentCulture.Name;
            var resources = identity.Resources;

            return(new IdentityResource
            {
                Description = resources.FirstOrDefault(r => r.ResourceKind == Entity.EntityResourceKind.Description &&
                                                       r.CultureId == cultureId)?.Value ?? identity.Description,
                DisplayName = resources.FirstOrDefault(r => r.ResourceKind == Entity.EntityResourceKind.DisplayName &&
                                                       r.CultureId == cultureId)?.Value ?? identity.DisplayName,
                Emphasize = identity.Emphasize,
                Enabled = identity.Enabled,
                Name = identity.Id,
                Properties = identity.Properties.ToDictionary(p => p.Key, p => p.Value),
                Required = identity.Required,
                ShowInDiscoveryDocument = identity.ShowInDiscoveryDocument,
                UserClaims = identity.IdentityClaims.Select(c => c.Type).ToList()
            });
        }
 protected abstract ICollection <TEntity> GetCollection(Entity.IdentityResource identity);