Exemplo n.º 1
0
        public async Task WillDeleteOldRevisions()
        {
            var company = new Company {
                Name = "Company #1"
            };

            using (var store = GetDocumentStore())
            {
                await VersioningHelper.SetupVersioning(store);

                using (var session = store.OpenAsyncSession())
                {
                    await session.StoreAsync(company);

                    await session.SaveChangesAsync();

                    for (var i = 0; i < 10; i++)
                    {
                        company.Name = "Company #2: " + i;
                        await session.SaveChangesAsync();
                    }
                }

                using (var session = store.OpenAsyncSession())
                {
                    var revisions = await session.Advanced.GetRevisionsForAsync <Company>(company.Id);

                    Assert.Equal(5, revisions.Length);
                    Assert.Equal("Company #2: 5", revisions[0].Name);
                    Assert.Equal("Company #2: 9", revisions[4].Name);
                }
            }
        }
Exemplo n.º 2
0
        public async Task CanGetAllRevisionsFor()
        {
            var company = new Company {
                Name = "Company Name"
            };

            using (var store = GetDocumentStore())
            {
                await VersioningHelper.SetupVersioning(store);

                using (var session = store.OpenAsyncSession())
                {
                    await session.StoreAsync(company);

                    await session.SaveChangesAsync();
                }
                using (var session = store.OpenAsyncSession())
                {
                    var company3 = await session.LoadAsync <Company>(company.Id);

                    company3.Name = "Hibernating Rhinos";
                    await session.SaveChangesAsync();
                }
                using (var session = store.OpenAsyncSession())
                {
                    var companiesRevisions = await session.Advanced.GetRevisionsForAsync <Company>(company.Id);

                    Assert.Equal(2, companiesRevisions.Length);
                    Assert.Equal("Company Name", companiesRevisions[0].Name);
                    Assert.Equal("Hibernating Rhinos", companiesRevisions[1].Name);
                }
            }
        }
Exemplo n.º 3
0
        public async Task CanExcludeEntitiesFromVersioning()
        {
            var user = new User {
                Name = "User Name"
            };
            var comment = new Comment {
                Name = "foo"
            };

            using (var store = GetDocumentStore())
            {
                await VersioningHelper.SetupVersioning(store);

                using (var session = store.OpenAsyncSession())
                {
                    await session.StoreAsync(user);

                    await session.StoreAsync(comment);

                    await session.SaveChangesAsync();
                }

                using (var session = store.OpenAsyncSession())
                {
                    Assert.Empty(await session.Advanced.GetRevisionsForAsync <Comment>(comment.Id));
                    var users = await session.Advanced.GetRevisionsForAsync <User>(user.Id);

                    Assert.Equal(1, users.Length);
                }
            }
        }
Exemplo n.º 4
0
        public async Task GetRevisionsOfNotExistKey()
        {
            using (var store = GetDocumentStore())
            {
                await VersioningHelper.SetupVersioning(store);

                using (var session = store.OpenAsyncSession())
                {
                    var companiesRevisions = await session.Advanced.GetRevisionsForAsync <Company>("companies/1");

                    Assert.Equal(0, companiesRevisions.Length);
                }
            }
        }
Exemplo n.º 5
0
        public async Task WillCreateRevisionIfExplicitlyRequested()
        {
            var product = new Product {
                Description = "A fine document db", Quantity = 5
            };

            using (var store = GetDocumentStore())
            {
                await VersioningHelper.SetupVersioning(store);

                using (var session = store.OpenAsyncSession())
                {
                    await session.StoreAsync(product);

                    await session.SaveChangesAsync();
                }
                using (var session = store.OpenAsyncSession())
                {
                    product.Description = "desc 2";
                    await session.StoreAsync(product);

                    session.Advanced.ExplicitlyVersion(product);
                    await session.SaveChangesAsync();
                }
                using (var session = store.OpenAsyncSession())
                {
                    product.Description = "desc 3";
                    await session.StoreAsync(product);

                    await session.SaveChangesAsync();
                }

                using (var session = store.OpenAsyncSession())
                {
                    var products = await session.Advanced.GetRevisionsForAsync <Product>(product.Id);

                    Assert.Equal("desc 2", products.Single().Description);
                }
            }
        }
Exemplo n.º 6
0
        public async Task ServerSaveBundlesAfterRestart()
        {
            var path    = NewDataPath();
            var company = new Company {
                Name = "Company Name"
            };

            using (var store = GetDocumentStore(path: path, deleteDbAfterDispose: false))
            {
                await VersioningHelper.SetupVersioning(store);

                using (var session = store.OpenAsyncSession())
                {
                    await session.StoreAsync(company);

                    await session.SaveChangesAsync();
                }
                using (var session = store.OpenAsyncSession())
                {
                    var company3 = await session.LoadAsync <Company>(company.Id);

                    company3.Name = "Hibernating Rhinos";
                    await session.SaveChangesAsync();
                }
            }

            using (var store = GetDocumentStore(path: path))
            {
                using (var session = store.OpenAsyncSession())
                {
                    var companiesRevisions = await session.Advanced.GetRevisionsForAsync <Company>(company.Id);

                    Assert.Equal(2, companiesRevisions.Length);
                    Assert.Equal("Company Name", companiesRevisions[0].Name);
                    Assert.Equal("Hibernating Rhinos", companiesRevisions[1].Name);
                }
            }
        }
Exemplo n.º 7
0
        public async Task CanCheckIfDocumentIsVersioned()
        {
            var company = new Company {
                Name = "Company Name"
            };

            using (var store = GetDocumentStore())
            {
                await VersioningHelper.SetupVersioning(store);

                using (var session = store.OpenAsyncSession())
                {
                    await session.StoreAsync(company);

                    await session.SaveChangesAsync();
                }
                using (var session = store.OpenAsyncSession())
                {
                    var company3 = await session.LoadAsync <Company>(company.Id);

                    Assert.Equal("Versioned", session.Advanced.GetMetadataFor(company3)["@flags"]);
                }
            }
        }
Exemplo n.º 8
0
        public async Task WillDeleteRevisionsIfDeleted_OnlyIfPurgeOnDeleteIsTrue()
        {
            using (var store = GetDocumentStore())
            {
                await VersioningHelper.SetupVersioning(store);

                using (var session = store.OpenAsyncSession())
                {
                    var company = new Company {
                        Name = "Hibernaitng Rhinos "
                    };
                    var user = new User {
                        Name = "Fitzchak "
                    };
                    await session.StoreAsync(company);

                    await session.StoreAsync(user);

                    await session.SaveChangesAsync();
                }
                for (int i = 0; i < 10; i++)
                {
                    using (var session = store.OpenAsyncSession())
                    {
                        var company = await session.LoadAsync <Company>("companies/1");

                        var user = await session.LoadAsync <User>("users/1");

                        company.Name += i;
                        user.Name    += i;
                        await session.StoreAsync(company);

                        await session.StoreAsync(user);

                        await session.SaveChangesAsync();
                    }
                }

                using (var session = store.OpenAsyncSession())
                {
                    var company = await session.LoadAsync <Company>("companies/1");

                    var user = await session.LoadAsync <User>("users/1");

                    Assert.NotNull(company);
                    Assert.NotNull(user);
                    session.Delete(company);
                    session.Delete(user);
                    await session.SaveChangesAsync();
                }
                using (var session = store.OpenAsyncSession())
                {
                    var companies = await session.Advanced.GetRevisionsForAsync <Company>("companies/1");

                    var users = await session.Advanced.GetRevisionsForAsync <User>("users/1");

                    Assert.Equal(5, companies.Length);
                    Assert.Empty(users);
                }

                using (var session = store.OpenAsyncSession())
                {
                    await session.StoreAsync(new Company { Name = "New Company" }, "companies/1");

                    await session.StoreAsync(new User { Name = "New User" }, "users/1");

                    await session.SaveChangesAsync();
                }
                using (var session = store.OpenAsyncSession())
                {
                    var companies = await session.Advanced.GetRevisionsForAsync <Company>("companies/1");

                    var users = await session.Advanced.GetRevisionsForAsync <User>("users/1");

                    Assert.Equal(5, companies.Length);
                    Assert.Equal("New Company", companies.Last().Name);
                    Assert.Equal(1, users.Length);
                }
            }
        }