Пример #1
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);
        }
Пример #2
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);
        }