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

            var entity = new Entity.RelyingPartyClaimMapping
            {
                Id             = Guid.NewGuid().ToString(),
                RelyingPartyId = "test"
            };
            var parent = new Entity.RelyingParty
            {
                Id = "test",
            };
            var collection = GetCollection(parent);

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

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

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

            await s1.SaveChangesAsync();

            var loggerMock = new Mock <ILogger <AdminStore <Entity.RelyingPartyClaimMapping> > >();

            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.RelyingParty> ($"{nameof(Entity.RelyingParty).ToLowerInvariant()}/test");

            var updatedCollection = GetCollection(updated);

            Assert.DoesNotContain(updatedCollection, i => i.Id == $"{typeof(Entity.RelyingPartyClaimMapping).Name.ToLowerInvariant()}/{entity.Id}");
        }
 private static ICollection <Entity.RelyingPartyClaimMapping> GetCollection(Entity.RelyingParty provider)
 {
     provider.ClaimMappings ??= new List <Entity.RelyingPartyClaimMapping>();
     return(provider.ClaimMappings);
 }
Example #3
0
        private static void SeedRelyingPartyClaimMappings(IAdminStore <Entity.RelyingPartyClaimMapping> relyingPartyClaimMappingStore, Entity.RelyingParty relyingParty)
        {
            if (relyingParty.ClaimMappings == null)
            {
                return;
            }

            foreach (var mapping in relyingParty.ClaimMappings)
            {
                relyingPartyClaimMappingStore.CreateAsync(new Entity.RelyingPartyClaimMapping
                {
                    FromClaimType  = mapping.FromClaimType,
                    Id             = Guid.NewGuid().ToString(),
                    RelyingPartyId = relyingParty.Id,
                    ToClaimType    = mapping.ToClaimType
                }).GetAwaiter().GetResult();
            }
        }