コード例 #1
0
        public async Task RestoreAsync(RestoreContext context)
        {
            await RestoreTagsAsync(context);

            if (assetIds.Count > 0)
            {
                await rebuilder.InsertManyAsync <AssetDomainObject, AssetState>(async target =>
                {
                    foreach (var id in assetIds)
                    {
                        await target(id);
                    }
                });
            }

            if (assetFolderIds.Count > 0)
            {
                await rebuilder.InsertManyAsync <AssetFolderDomainObject, AssetFolderState>(async target =>
                {
                    foreach (var id in assetFolderIds)
                    {
                        await target(id);
                    }
                });
            }
        }
コード例 #2
0
        public async Task RestoreAsync(RestoreContext context)
        {
            await RestoreTagsAsync(context);

            if (assetIds.Count > 0)
            {
                await rebuilder.InsertManyAsync <AssetDomainObject, AssetState>(assetIds);
            }

            if (assetFolderIds.Count > 0)
            {
                await rebuilder.InsertManyAsync <AssetFolderDomainObject, AssetFolderState>(assetFolderIds);
            }
        }
コード例 #3
0
        public async Task RestoreAsync(RestoreContext context,
                                       CancellationToken ct)
        {
            await RestoreTagsAsync(context, ct);

            if (assetIds.Count > 0)
            {
                await rebuilder.InsertManyAsync <AssetDomainObject, AssetDomainObject.State>(assetIds, BatchSize, ct);
            }

            if (assetFolderIds.Count > 0)
            {
                await rebuilder.InsertManyAsync <AssetFolderDomainObject, AssetFolderDomainObject.State>(assetFolderIds, BatchSize, ct);
            }
        }
コード例 #4
0
        public async Task Should_complete_reservation_with_previous_token()
        {
            const string appName = "my-app";

            var context = CreateRestoreContext();

            A.CallTo(() => appsIndex.ReserveAsync(appId, appName, ct))
            .Returns("Reservation");

            await sut.RestoreEventAsync(Envelope.Create(new AppCreated
            {
                Name = appName
            }), context, ct);

            await sut.CompleteRestoreAsync(context, appName);

            A.CallTo(() => appsIndex.RemoveReservationAsync("Reservation", default))
            .MustHaveHappened();

            A.CallTo(() => appsIndex.RegisterAsync(appId, appName, default))
            .MustHaveHappened();

            A.CallTo(() => rebuilder.InsertManyAsync <AppDomainObject, AppDomainObject.State>(A <IEnumerable <DomainId> > .That.Is(appId), 1, default))
            .MustHaveHappened();
        }
コード例 #5
0
        public async Task CompleteRestoreAsync(RestoreContext context, string appName)
        {
            await rebuilder.InsertManyAsync <AppDomainObject, AppDomainObject.State>(Enumerable.Repeat(context.AppId, 1), 1, default);

            await appsIndex.RegisterAsync(context.AppId, appName);

            await appsIndex.RemoveReservationAsync(appReservation);
        }
コード例 #6
0
 public async Task RestoreAsync(RestoreContext context,
                                CancellationToken ct)
 {
     if (ruleIds.Count > 0)
     {
         await rebuilder.InsertManyAsync <RuleDomainObject, RuleDomainObject.State>(ruleIds, BatchSize, ct);
     }
 }
コード例 #7
0
ファイル: BackupContents.cs プロジェクト: seamys/squidex
        public async Task RestoreAsync(RestoreContext context)
        {
            var ids = contentIdsBySchemaId.Values.SelectMany(x => x);

            if (ids.Any())
            {
                await rebuilder.InsertManyAsync <ContentDomainObject, ContentDomainObject.State>(ids, BatchSize);
            }
        }
コード例 #8
0
        public async Task Should_restore_states_for_all_contents()
        {
            var me = new RefToken(RefTokenType.Subject, "123");

            var schemaId1 = NamedId.Of(DomainId.NewGuid(), "my-schema1");
            var schemaId2 = NamedId.Of(DomainId.NewGuid(), "my-schema2");

            var contentId1 = DomainId.NewGuid();
            var contentId2 = DomainId.NewGuid();
            var contentId3 = DomainId.NewGuid();

            var context = new RestoreContext(appId.Id, new UserMapping(me), A.Fake <IBackupReader>(), DomainId.NewGuid());

            await sut.RestoreEventAsync(ContentEvent(new ContentCreated
            {
                ContentId = contentId1,
                SchemaId = schemaId1
            }), context);

            await sut.RestoreEventAsync(ContentEvent(new ContentCreated
            {
                ContentId = contentId2,
                SchemaId = schemaId1
            }), context);

            await sut.RestoreEventAsync(ContentEvent(new ContentCreated
            {
                ContentId = contentId3,
                SchemaId = schemaId2
            }), context);

            await sut.RestoreEventAsync(ContentEvent(new ContentDeleted
            {
                ContentId = contentId2,
                SchemaId = schemaId1
            }), context);

            await sut.RestoreEventAsync(Envelope.Create(new SchemaDeleted
            {
                SchemaId = schemaId2
            }), context);

            var rebuildContents = new HashSet <DomainId>();

            A.CallTo(() => rebuilder.InsertManyAsync <ContentDomainObject, ContentState>(A <IEnumerable <DomainId> > ._, A <CancellationToken> ._))
            .Invokes((IEnumerable <DomainId> source, CancellationToken _) => rebuildContents.AddRange(source));

            await sut.RestoreAsync(context);

            Assert.Equal(new HashSet <DomainId>
            {
                DomainId.Combine(appId.Id, contentId1),
                DomainId.Combine(appId.Id, contentId2)
            }, rebuildContents);
        }
コード例 #9
0
ファイル: BackupAssetsTests.cs プロジェクト: vmnet04/squidex
        public async Task Should_restore_states_for_all_assets()
        {
            var assetId1 = Guid.NewGuid();
            var assetId2 = Guid.NewGuid();

            var context = CreateRestoreContext();

            await sut.RestoreEventAsync(Envelope.Create(new AssetCreated
            {
                AssetId = assetId1
            }), context);

            await sut.RestoreEventAsync(Envelope.Create(new AssetCreated
            {
                AssetId = assetId2
            }), context);

            await sut.RestoreEventAsync(Envelope.Create(new AssetDeleted
            {
                AssetId = assetId2
            }), context);

            var rebuildAssets = new HashSet <Guid>();

            var add = new Func <Guid, Task>(id =>
            {
                rebuildAssets.Add(id);

                return(Task.CompletedTask);
            });

            A.CallTo(() => rebuilder.InsertManyAsync <AssetDomainObject, AssetState>(A <IdSource> ._, A <CancellationToken> ._))
            .Invokes((IdSource source, CancellationToken _) => source(add));

            await sut.RestoreAsync(context);

            Assert.Equal(new HashSet <Guid>
            {
                assetId1,
                assetId2
            }, rebuildAssets);
        }
コード例 #10
0
 public async Task RestoreAsync(RestoreContext context)
 {
     if (contentIdsBySchemaId.Count > 0)
     {
         await rebuilder.InsertManyAsync <ContentDomainObject, ContentState>(async target =>
         {
             foreach (var contentId in contentIdsBySchemaId.Values.SelectMany(x => x))
             {
                 await target(contentId);
             }
         });
     }
 }
コード例 #11
0
        public async Task Should_restore_indices_for_all_non_deleted_rules()
        {
            var ruleId1 = DomainId.NewGuid();
            var ruleId2 = DomainId.NewGuid();
            var ruleId3 = DomainId.NewGuid();

            var context = new RestoreContext(appId.Id, new UserMapping(RefToken.User("123")), A.Fake <IBackupReader>(), DomainId.NewGuid());

            await sut.RestoreEventAsync(AppEvent(new RuleCreated
            {
                RuleId = ruleId1
            }), context, ct);

            await sut.RestoreEventAsync(AppEvent(new RuleCreated
            {
                RuleId = ruleId2
            }), context, ct);

            await sut.RestoreEventAsync(AppEvent(new RuleCreated
            {
                RuleId = ruleId3
            }), context, ct);

            await sut.RestoreEventAsync(AppEvent(new RuleDeleted
            {
                RuleId = ruleId3
            }), context, ct);

            var rebuildAssets = new HashSet <DomainId>();

            A.CallTo(() => rebuilder.InsertManyAsync <RuleDomainObject, RuleDomainObject.State>(A <IEnumerable <DomainId> > ._, A <int> ._, ct))
            .Invokes(x => rebuildAssets.AddRange(x.GetArgument <IEnumerable <DomainId> >(0) !));

            await sut.RestoreAsync(context, ct);

            Assert.Equal(new HashSet <DomainId>
            {
                DomainId.Combine(appId, ruleId1),
                DomainId.Combine(appId, ruleId2)
            }, rebuildAssets);
        }
コード例 #12
0
        public async Task Should_restore_indices_for_all_non_deleted_schemas()
        {
            var schemaId1 = NamedId.Of(DomainId.NewGuid(), "my-schema1");
            var schemaId2 = NamedId.Of(DomainId.NewGuid(), "my-schema2");
            var schemaId3 = NamedId.Of(DomainId.NewGuid(), "my-schema3");

            var context = new RestoreContext(appId.Id, new UserMapping(RefToken.User("123")), A.Fake <IBackupReader>(), DomainId.NewGuid());

            await sut.RestoreEventAsync(AppEvent(new SchemaCreated
            {
                SchemaId = schemaId1
            }), context, ct);

            await sut.RestoreEventAsync(AppEvent(new SchemaCreated
            {
                SchemaId = schemaId2
            }), context, ct);

            await sut.RestoreEventAsync(AppEvent(new SchemaCreated
            {
                SchemaId = schemaId3
            }), context, ct);

            await sut.RestoreEventAsync(AppEvent(new SchemaDeleted
            {
                SchemaId = schemaId3
            }), context, ct);

            var rebuildContents = new HashSet <DomainId>();

            A.CallTo(() => rebuilder.InsertManyAsync <SchemaDomainObject, SchemaDomainObject.State>(A <IEnumerable <DomainId> > ._, A <int> ._, ct))
            .Invokes(x => rebuildContents.AddRange(x.GetArgument <IEnumerable <DomainId> >(0) !));

            await sut.RestoreAsync(context, ct);

            Assert.Equal(new HashSet <DomainId>
            {
                DomainId.Combine(appId, schemaId1.Id),
                DomainId.Combine(appId, schemaId2.Id)
            }, rebuildContents);
        }
コード例 #13
0
        public async Task Should_restore_states_for_all_contents()
        {
            var appId = Guid.NewGuid();

            var schemaId1 = NamedId.Of(Guid.NewGuid(), "my-schema1");
            var schemaId2 = NamedId.Of(Guid.NewGuid(), "my-schema2");

            var contentId1 = Guid.NewGuid();
            var contentId2 = Guid.NewGuid();
            var contentId3 = Guid.NewGuid();

            var context = new RestoreContext(appId, new UserMapping(new RefToken(RefTokenType.Subject, "123")), A.Fake <IBackupReader>());

            await sut.RestoreEventAsync(Envelope.Create(new ContentCreated
            {
                ContentId = contentId1,
                SchemaId  = schemaId1
            }), context);

            await sut.RestoreEventAsync(Envelope.Create(new ContentCreated
            {
                ContentId = contentId2,
                SchemaId  = schemaId1
            }), context);

            await sut.RestoreEventAsync(Envelope.Create(new ContentCreated
            {
                ContentId = contentId3,
                SchemaId  = schemaId2
            }), context);

            await sut.RestoreEventAsync(Envelope.Create(new ContentDeleted
            {
                ContentId = contentId2,
                SchemaId  = schemaId1
            }), context);

            await sut.RestoreEventAsync(Envelope.Create(new SchemaDeleted
            {
                SchemaId = schemaId2
            }), context);

            var rebuildContents = new HashSet <Guid>();

            var add = new Func <Guid, Task>(id =>
            {
                rebuildContents.Add(id);

                return(TaskHelper.Done);
            });

            A.CallTo(() => rebuilder.InsertManyAsync <ContentDomainObject, ContentState>(A <IdSource> ._, A <CancellationToken> ._))
            .Invokes((IdSource source, CancellationToken _) => source(add));

            await sut.RestoreAsync(context);

            Assert.Equal(new HashSet <Guid>
            {
                contentId1,
                contentId2
            }, rebuildContents);
        }