Exemplo n.º 1
0
        public async Task Should_restore_indices_for_all_non_deleted_schemas()
        {
            var appId = Guid.NewGuid();

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

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

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

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

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

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

            Dictionary <string, Guid>?newIndex = null;

            A.CallTo(() => index.RebuildAsync(appId, A <Dictionary <string, Guid> > ._))
            .Invokes(new Action <Guid, Dictionary <string, Guid> >((_, i) => newIndex = i));

            await sut.RestoreAsync(context);

            Assert.Equal(new Dictionary <string, Guid>
            {
                [schemaId1.Name] = schemaId1.Id,
                [schemaId2.Name] = schemaId2.Id
            }, newIndex);
        }
Exemplo n.º 2
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);
        }