Beispiel #1
0
        public async Task hard_delete_by_document_and_tenant_by_string()
        {
            var doc1 = new StringDoc {
                Id = "big"
            };

            theSession.ForTenant("read").Store(doc1);
            theSession.ForTenant("blue").Store(doc1);

            await theSession.SaveChangesAsync();

            theSession.ForTenant("red").HardDelete(doc1);

            using var query = theStore.QuerySession();

            var redCount = await query.Query <StringDoc>().Where(x => x.TenantIsOneOf("red"))
                           .CountAsync();

            redCount.ShouldBe(0);

            var blueCount = await query.Query <StringDoc>().Where(x => x.TenantIsOneOf("blue"))
                            .CountAsync();

            blueCount.ShouldBe(1);
        }
Beispiel #2
0
        public void apply_updates_via_the_actual_document()
        {
            var stringDoc1 = new StringDoc {Id = "Foo"};
            var stringDoc2 = new StringDoc {Id = "Bar"};
            var user1 = new User();
            var user2 = new User();
            var int1 = new IntDoc {Id = 1};
            var int2 = new IntDoc {Id = 2};
            var long1 = new LongDoc {Id = 3};
            var long2 = new LongDoc {Id = 4};

            var uow1 = theContainer.GetInstance<UnitOfWork>();
            uow1.Store(user1, user2);
            uow1.Store(stringDoc1, stringDoc2);
            uow1.Store(int1, int2);
            uow1.Store(long1, long2);
            var batch1 = theContainer.GetInstance<UpdateBatch>();
            uow1.ApplyChanges(batch1);


            var uow2 = theContainer.GetInstance<UnitOfWork>();
            uow2.Delete(stringDoc2);
            uow2.Delete(user2);
            uow2.Delete(int2);
            uow2.Delete(long2);
            var batch2 = theContainer.GetInstance<UpdateBatch>();
            uow2.ApplyChanges(batch2);

            theSession.Query<StringDoc>().Single().Id.ShouldBe(stringDoc1.Id);
            theSession.Query<User>().Single().Id.ShouldBe(user1.Id);
            theSession.Query<IntDoc>().Single().Id.ShouldBe(int1.Id);
            theSession.Query<LongDoc>().Single().Id.ShouldBe(long1.Id);
        }
Beispiel #3
0
        public async Task hard_delete_by_linq()
        {
            var doc1 = new StringDoc {
                Id = "red", Size = "big"
            };
            var doc2 = new StringDoc {
                Id = "blue", Size = "small"
            };
            var doc3 = new StringDoc {
                Id = "green", Size = "big"
            };
            var doc4 = new StringDoc {
                Id = "purple", Size = "medium"
            };

            theSession.Store(doc1, doc2, doc3, doc4);
            await theSession.SaveChangesAsync();

            theSession.HardDeleteWhere <StringDoc>(x => x.Size == "big");
            await theSession.SaveChangesAsync();

            assertDocumentIsHardDeleted <StringDoc>(theSession, "red");
            assertDocumentIsHardDeleted <StringDoc>(theSession, "green");

            var count = await theSession.Query <StringDoc>().Where(x => x.MaybeDeleted()).CountAsync();

            count.ShouldBe(2);
        }
Beispiel #4
0
        public async Task can_delete_a_document_by_id_and_tenant_string()
        {
            var target = new StringDoc {
                Id = Guid.NewGuid().ToString()
            };

            using (var session = theStore.LightweightSession("Red"))
            {
                session.Store(target);
                await session.SaveChangesAsync();
            }

            using (var session = theStore.LightweightSession("Blue"))
            {
                session.Store(target);
                await session.SaveChangesAsync();
            }

            using (var session = theStore.LightweightSession())
            {
                session.Logger = new TestOutputMartenLogger(_output);
                session.ForTenant("Blue").Delete <StringDoc>(target.Id);
                await session.SaveChangesAsync();
            }

            var red = theStore.QuerySession("Blue");

            (await red.LoadAsync <StringDoc>(target.Id)).ShouldBeNull();

            var blue = theStore.QuerySession("Red");

            (await blue.LoadAsync <StringDoc>(target.Id)).ShouldNotBeNull();
        }
Beispiel #5
0
        public async Task can_use_custom_codegen()
        {
            StoreOptions(opts =>
            {
                opts.Schema.For <StringDoc>().IdStrategy(new String2IdGeneration());
            });

            var doc = new StringDoc();

            theSession.Store(doc);
            await theSession.SaveChangesAsync();
        }
Beispiel #6
0
        public void hard_delete_a_document_row_state_string()
        {
            using var session = theStore.OpenSession();
            var doc = new StringDoc {
                Id = Guid.NewGuid().ToString()
            };

            session.Store(doc);
            session.SaveChanges();

            session.HardDelete <StringDoc>(doc.Id);
            session.SaveChanges();

            assertDocumentIsHardDeleted <StringDoc>(session, doc.Id);
        }
        public async Task stream_by_string_id_hit()
        {
            var doc = new StringDoc {
                Id = Guid.NewGuid().ToString()
            };

            theSession.Store(doc);
            await theSession.SaveChangesAsync();

            var stream = new MemoryStream();
            var found  = await theSession.Json.StreamById <StringDoc>(doc.Id, stream);

            found.ShouldBeTrue();

            var target = deserialize <StringDoc>(stream);

            target.Id.ShouldBe(doc.Id);
        }