Пример #1
0
        public async Task Should_restore_states_for_all_contents()
        {
            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(new RefToken(RefTokenType.Subject, "123")), 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);
        }
Пример #2
0
        public async Task Should_replace_asset_url_in_content()
        {
            var me = new RefToken(RefTokenType.Subject, "123");

            var newAssetsUrl    = "https://new.squidex.com/api/assets";
            var newAssetsUrlApp = "https://old.squidex.com/api/assets/my-new-app";

            var oldAssetsUrl    = "https://old.squidex.com/api/assets";
            var oldAssetsUrlApp = "https://old.squidex.com/api/assets/my-old-app";

            var reader = A.Fake <IBackupReader>();

            A.CallTo(() => urlGenerator.AssetContentBase())
            .Returns(newAssetsUrl);

            A.CallTo(() => urlGenerator.AssetContentBase(appId.Name))
            .Returns(newAssetsUrlApp);

            A.CallTo(() => reader.ReadJsonAsync <BackupContents.Urls>(A <string> ._))
            .Returns(new BackupContents.Urls
            {
                Assets    = oldAssetsUrl,
                AssetsApp = oldAssetsUrlApp
            });

            var data =
                new NamedContentData()
                .AddField("asset",
                          new ContentFieldData()
                          .AddValue("en", $"Asset: {oldAssetsUrlApp}/my-asset.jpg.")
                          .AddValue("it", $"Asset: {oldAssetsUrl}/my-asset.jpg."))
                .AddField("assetsInArray",
                          new ContentFieldData()
                          .AddValue("iv",
                                    JsonValue.Array(
                                        $"Asset: {oldAssetsUrlApp}/my-asset.jpg.")))
                .AddField("assetsInObj",
                          new ContentFieldData()
                          .AddValue("iv",
                                    JsonValue.Object()
                                    .Add("asset", $"Asset: {oldAssetsUrlApp}/my-asset.jpg.")));

            var updateData =
                new NamedContentData()
                .AddField("asset",
                          new ContentFieldData()
                          .AddValue("en", $"Asset: {newAssetsUrlApp}/my-asset.jpg.")
                          .AddValue("it", $"Asset: {newAssetsUrl}/my-asset.jpg."))
                .AddField("assetsInArray",
                          new ContentFieldData()
                          .AddValue("iv",
                                    JsonValue.Array(
                                        $"Asset: {newAssetsUrlApp}/my-asset.jpg.")))
                .AddField("assetsInObj",
                          new ContentFieldData()
                          .AddValue("iv",
                                    JsonValue.Object()
                                    .Add("asset", $"Asset: {newAssetsUrlApp}/my-asset.jpg.")));

            var context = new RestoreContext(appId.Id, new UserMapping(me), reader, DomainId.NewGuid());

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

            await sut.RestoreEventAsync(Envelope.Create(new ContentUpdated
            {
                Data = data
            }), context);

            Assert.Equal(updateData, data);
        }
Пример #3
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);
        }