Пример #1
0
        public void DocumentWriter()
        {
            var size  = 5;
            var pages = TestSetup.GeneratePages(size, false);
            var repos = new ObjectiksOf();


            repos.TruncateOf <Pages>();

            var count_before = repos.Count <Pages>();

            Assert.IsTrue(count_before == 0);

            using (var writer = repos.WriterOf <Pages>())
            {
                writer.UseFormatting();

                foreach (var page in pages)
                {
                    writer.AddDocument(page);
                }

                writer.SubmitChanges();
            }

            var count_after = repos.Count <Pages>();



            Assert.IsTrue(count_after == size);
        }
Пример #2
0
        public void DocumentReader()
        {
            var pages = TestSetup.GeneratePages(10, false);

            var repos = new ObjectiksOf();

            var get_pages = repos.TypeOf <Pages>().ToList();
            var meta      = repos.GetTypeMeta <Pages>();

            //get page count..
            var numberOfRecordBefore = repos.Count <Pages>();

            //all pages remove..
            var numberOfRecordDelete = repos.TypeOf <Pages>().Delete();

            Assert.IsTrue(numberOfRecordBefore == numberOfRecordDelete);

            var numberOfRecordAfter = repos.Count <Pages>();

            //check delete success..
            Assert.IsTrue(numberOfRecordAfter == 0);

            //add pages..
            using (var writer = repos.WriterOf <Pages>())
            {
                writer.UseFormatting();
                writer.AddDocuments(pages);
                writer.SubmitChanges();
            }

            var list = repos.TypeOf <Pages>().ToList();

            Assert.IsTrue(list.Count == pages.Count);

            var userPages = repos
                            .TypeOf <Pages>()
                            .KeyOf("FakeKeyOf")
                            .ToList();

            Assert.IsTrue(userPages.Count == 0);

            var keyOfTag = list[0].Tag;
            var keyOfTagNumberOfCount = list.Count(l => l.Tag == keyOfTag);

            Debug.WriteLine($"KeyOf:{keyOfTag}");

            var keyOfPages = repos.TypeOf <Pages>().KeyOf(keyOfTag).ToList();

            Assert.IsTrue(keyOfPages.Count == keyOfTagNumberOfCount);
        }
Пример #3
0
        public void DocumentTransactionGlobalParalelTest()
        {
            var size  = 500;
            var pages = TestSetup.GeneratePages(size, false);
            var repos = new ObjectiksOf();

            repos.TruncateOf <Pages>();
            repos.TruncateOf <Tags>();

            var result = Parallel.ForEach(pages, page =>
            {
                using (var trans = repos.BeginTransaction())
                {
                    try
                    {
                        using (var pageWriter = repos.WriterOf <Pages>())
                        {
                            pageWriter.UseFormatting();
                            pageWriter.AddDocument(page);
                            pageWriter.SubmitChanges();
                        }

                        trans.Commit();
                    }
                    catch (Exception ex)
                    {
                        trans.Rollback(ex);
                    }
                }
            });

            var logs = DocumentLogger.Logs;

            Assert.IsTrue(repos.Count <Pages>() == size);
        }
Пример #4
0
        public void DocumentTransactionInternalTest()
        {
            var size  = 50;
            var pages = TestSetup.GeneratePages(size, false);
            var repos = new ObjectiksOf();

            repos.TruncateOf <Pages>();

            using (var writer = repos.WriterOf <Pages>())
            {
                writer.AddDocuments(pages);
                writer.SubmitChanges();
            }

            Assert.IsTrue(repos.Count <Pages>() == size);
        }
Пример #5
0
        public void DocumentBulkWritePartial()
        {
            var size  = 50;
            var pages = TestSetup.GeneratePages(size, false);
            var repos = new ObjectiksOf();

            repos.TruncateOf <Pages>();

            using (var writer = repos.WriterOf <Pages>())
            {
                writer.UsePartialStore(25);
                writer.UseFormatting();
                writer.AddDocuments(pages);
                writer.SubmitChanges();
            }

            Assert.IsTrue(repos.Count <Pages>() == size);
        }
Пример #6
0
        public void DocumentBulkWrite()
        {
            var size  = 500;
            var pages = TestSetup.GeneratePages(size, false);
            var repos = new ObjectiksOf();

            //removes
            repos.TruncateOf <Pages>();

            using (var writer = repos.WriterOf <Pages>())
            {
                writer.UseFormatting();
                writer.AddDocuments(pages);
                writer.SubmitChanges();
            }

            var numberOfRecord = repos.Count <Pages>();

            Assert.True(numberOfRecord == size);
        }
Пример #7
0
        public void DocumentTransactionInternalParalelTest()
        {
            var size  = 50;
            var pages = TestSetup.GeneratePages(size, false);
            var repos = new ObjectiksOf();

            repos.TruncateOf <Pages>();
            repos.TruncateOf <Tags>();

            var result = Parallel.ForEach(pages, page =>
            {
                using (var pageWriter = repos.WriterOf <Pages>())
                {
                    pageWriter.UseFormatting();
                    pageWriter.AddDocument(page);
                    pageWriter.SubmitChanges();
                }
            });

            Assert.IsTrue(repos.Count <Pages>() == size);
        }
Пример #8
0
        public void DocumentTransactionTest()
        {
            var size  = 5;
            var pages = TestSetup.GeneratePages(size, false);
            var repos = new ObjectiksOf();

            //truncate types..
            using (var trans = repos.BeginTransaction())
            {
                try
                {
                    using (var pageWriter = repos.WriterOf <Pages>())
                    {
                        pageWriter.Truncate();
                    }

                    using (var tagWriter = repos.WriterOf <Tags>())
                    {
                        tagWriter.Truncate();
                    }

                    trans.Commit();
                }
                catch (Exception ex)
                {
                    trans.Rollback(ex);
                }
            }

            using (var trans = repos.BeginTransaction())
            {
                try
                {
                    var tag = new Tags
                    {
                        Name = "Tag1"
                    };

                    using (var tagWriter = repos.WriterOf <Tags>())
                    {
                        tagWriter.UseFormatting();
                        tagWriter.AddDocument(tag);
                        tagWriter.SubmitChanges();
                    }

                    using (var pageWriter = repos.WriterOf <Pages>())
                    {
                        pageWriter.UseFormatting();
                        pageWriter.AddDocuments(pages);
                        pageWriter.SubmitChanges();
                    }

                    trans.Commit();
                }
                catch (Exception ex)
                {
                    trans.Rollback(ex);
                }
            }

            var count = repos.Count <Pages>();

            Assert.IsTrue(count == size);
            Assert.IsTrue(repos.Count <Tags>() == 1);
        }
Пример #9
0
        public void DocumentWorkOfUserOfKeyOfPrimaryOf()
        {
            var repos = new ObjectiksOf();

            repos.TruncateOf <Pages>();

            var pages = TestSetup.GeneratePages(10, false, true);

            using (var writer = repos.WriterOf <Pages>())
            {
                writer.UseFormatting();
                writer.AddDocuments(pages);
                writer.SubmitChanges();
            }

            Assert.IsTrue(pages.Count == repos.Count <Pages>());

            var select_first  = pages[0];
            var select_second = pages[1];

            var workOfResults = repos
                                .TypeOf <Pages>()
                                .WorkOf(select_first.WorkSpaceRef)
                                .ToList();

            int workOfResultsCheckCount = pages.Count(p => p.WorkSpaceRef == select_first.WorkSpaceRef);

            Assert.IsTrue(workOfResults.Count == workOfResultsCheckCount);

            var keyOfResults = repos
                               .TypeOf <Pages>()
                               .KeyOf(select_first.Tag)
                               .ToList();

            int keyOfResultsCheckCount = pages.Count(p => p.Tag == select_first.Tag);

            Assert.IsTrue(keyOfResults.Count == keyOfResultsCheckCount);

            var primaryOfResults = repos
                                   .TypeOf <Pages>()
                                   .PrimaryOf(select_first.Id)
                                   .PrimaryOf(select_second.Id)
                                   .Any()
                                   .ToList();

            int primaryOfResultsCheckCount = pages.Count(p => p.Id == select_first.Id || p.Id == select_second.Id);

            Assert.IsTrue(primaryOfResults.Count == primaryOfResultsCheckCount);

            var primaryOfFirstResult = repos
                                       .TypeOf <Pages>()
                                       .PrimaryOf(select_first.Id)
                                       .First();

            Assert.NotNull(primaryOfFirstResult);

            var multiple = repos
                           .TypeOf <Pages>()
                           .WorkOf(select_first.WorkSpaceRef)
                           .KeyOf(select_first.Tag)
                           .PrimaryOf(select_first.Id)
                           .PrimaryOf(select_second.Id)
                           .Any()
                           .ToList();

            int multipleCheckCount = pages.Count(
                p => p.WorkSpaceRef == select_first.WorkSpaceRef &&
                p.Tag.Contains(select_first.Tag) &&
                (p.Id == select_first.Id || p.Id == select_second.Id)
                );

            Assert.IsTrue(multiple.Count == multipleCheckCount);
        }