Ejemplo n.º 1
0
        public void Rollback_of_a_delete_should_not_have_deleted_the_document()
        {
            var store = new DocumentStore { DataLocation = TestSetup.DataDir, DatabaseName = TestSetup.DatabaseName };
            var fileNameProvider = new DocumentFileNameProvider(TestSetup.DataDir, TestSetup.DatabaseName);

            var document = new TestDocument
            {
                SomeInt = 1,
                SomeString = "Stringaling"
            };
            var key = "2A4E55A8-B01B-4EB5-9EC5-C2DD49304098";

            using (var session = store.OpenSession())
            {
                session.Save(document, key);
            }

            fileNameProvider.GetDocumentFile<TestDocument>(key).Exists.Should().BeTrue();

            using (var trx = new TransactionScope())
            {
                using (var session = store.OpenSession())
                {
                    session.Delete<TestDocument>(key);
                }
                Transaction.Current.Rollback();
            }

            var fileThatShouldNotHaveBeenDeleted = fileNameProvider.GetDocumentFile<TestDocument>(key);
            fileThatShouldNotHaveBeenDeleted.Exists.Should().BeTrue();
            TestSetup.SafeDeleteDocument(fileNameProvider.GetDocumentFile<TestDocument>(key).FullName);
        }
Ejemplo n.º 2
0
        public void Delete_should_delete_the_document()
        {
            var store = new DocumentStore { DataLocation = TestSetup.DataDir, DatabaseName = TestSetup.DatabaseName };
            var fileNameProvider = new DocumentFileNameProvider(TestSetup.DataDir, TestSetup.DatabaseName);
            var key = "E9B014D3-DD3C-4B20-9736-2C0970CE67A8";
            TestSetup.SafeDeleteDocument(fileNameProvider.GetDocumentFile<TestDocument>(key).FullName);

            var document = new TestDocument
            {
                SomeInt = 1,
                SomeString = "Stringaling"
            };

            using (var session = store.OpenSession())
            {
                session.Save(document, key);
            }

            fileNameProvider.GetDocumentFile<TestDocument>(key).Exists.Should().BeTrue();

            using (var session = store.OpenSession())
            {
                session.Delete<TestDocument>(key);
            }

            fileNameProvider.GetDocumentFile<TestDocument>(key).Exists.Should().BeFalse();
        }
Ejemplo n.º 3
0
        public void Get_should_retrieve_the_document_with_data_intact()
        {
            var store = new DocumentStore { DataLocation = TestSetup.DataDir, DatabaseName = TestSetup.DatabaseName };
            var fileNameProvider = new DocumentFileNameProvider(TestSetup.DataDir, TestSetup.DatabaseName);
            var key = "C4F3112E-03F6-4F73-8EA8-D93058D5F8B4";
            TestSetup.SafeDeleteDocument(fileNameProvider.GetDocumentFile<TestDocument>(key).FullName);
            var document = new TestDocument
            {
                SomeInt = 1,
                SomeString = "Stringaling",
                SomeSubClassProperty = new TestDocument.SomeSubClass()
            };

            using (var session = store.OpenSession())
            {
                session.Save(document, key);
            }

            TestDocument retrievedDocument;
            using (var session = store.OpenSession())
            {
                retrievedDocument = session.Get<TestDocument>(key);
            }

            retrievedDocument.SomeInt.Should().Be(1);
            retrievedDocument.SomeString.Should().Be("Stringaling");
            retrievedDocument.SomeSubClassProperty.Should().BeOfType<TestDocument.SomeSubClass>();
        }
Ejemplo n.º 4
0
        public void Lock_should_lock_the_file()
        {
            var fileNameProvider = new DocumentFileNameProvider(TestSetup.DataDir, TestSetup.DatabaseName);
            var key = "7966FBDA-D8A6-4F6D-AFD9-DE00968ED6D4";
            IDocumentFile tempFile = fileNameProvider.GetDocumentFile<TestDocument>(key);

            IDocumentFile documentFile1 = new DocumentFile(tempFile.FullName, new FakeDateTime());
            IDocumentFile documentFile2 = new DocumentFile(tempFile.FullName, new FakeDateTime());

            documentFile1.Lock();
            documentFile2.Invoking(x => x.Lock()).ShouldThrow<DocumentFileTimeoutException>();
        }
Ejemplo n.º 5
0
        public void Rollback_of_a_save_should_not_have_saved_a_new_document()
        {
            var store = new DocumentStore { DataLocation = TestSetup.DataDir, DatabaseName = TestSetup.DatabaseName };
            var fileNameProvider = new DocumentFileNameProvider(TestSetup.DataDir, TestSetup.DatabaseName);

            var document = new TestDocument
            {
                SomeInt = 1,
                SomeString = "Stringaling"
            };
            var key = "B8343419-F8CE-4993-A2E8-6DB763D5AEF1";
            TestSetup.SafeDeleteDocument(fileNameProvider.GetDocumentFile<TestDocument>(key).FullName);

            using (var trx = new TransactionScope())
            {
                using (var session = store.OpenSession())
                {
                    session.Save(document, key);
                    Transaction.Current.Rollback();
                }
            }

            fileNameProvider.GetDocumentFile<TestDocument>(key).Exists.Should().BeFalse();
        }
Ejemplo n.º 6
0
        public void Save_multiple_documents_in_the_same_transaction_should_save_all_documents()
        {
            var fileNameProvider = new DocumentFileNameProvider(TestSetup.DataDir, TestSetup.DatabaseName);
            var guids = new List<Guid>();
            for (int i = 0; i < 10; i++)
            {
                guids.Add(Guid.NewGuid());
            }

            using (var trx = new TransactionScope(TransactionScopeOption.RequiresNew))
            {
                var store = new DocumentStore { DataLocation = TestSetup.DataDir, DatabaseName = TestSetup.DatabaseName };
                using (var session = store.OpenSession())
                {
                    foreach (var guid in guids)
                    {
                        var document = new TestDocument { SomeString = "blaha" };
                        session.Save(document, guid.ToString());
                    }
                }
                trx.Complete();
            }

            foreach (var guid in guids)
            {
                fileNameProvider.GetDocumentFile<TestDocument>(guid.ToString()).Exists.Should().BeTrue();
                fileNameProvider.GetDocumentFile<TestDocument>(guid.ToString()).Delete();
            }
        }
Ejemplo n.º 7
0
        public void Save_should_be_able_to_save_two_different_types_of_documents_with_the_same_key()
        {
            var store = new DocumentStore { DataLocation = TestSetup.DataDir, DatabaseName = TestSetup.DatabaseName };
            var fileNameProvider = new DocumentFileNameProvider(TestSetup.DataDir, TestSetup.DatabaseName);
            var key = "B4996416-DF48-4F6F-B9F5-04AD151974D6";
            TestSetup.SafeDeleteDocument(fileNameProvider.GetDocumentFile<TestDocument>(key).FullName);
            TestSetup.SafeDeleteDocument(fileNameProvider.GetDocumentFile<TestDocument2>(key).FullName);

            var document = new TestDocument
            {
                SomeInt = 1,
                SomeString = "Stringaling",
                SomeSubClassProperty = new TestDocument.SomeSubClass()
            };
            var document2 = new TestDocument2 {AString = "AString"};

            using (var session = store.OpenSession())
            {
                session.Save(document, key);
                session.Save(document2, key);
            }

            TestDocument readDocument;
            TestDocument2 reaDocument2;

            using (var session = store.OpenSession())
            {
                readDocument = session.Get<TestDocument>(key);
                reaDocument2 = session.Get<TestDocument2>(key);
            }

            readDocument.Should().BeOfType<TestDocument>();
            reaDocument2.Should().BeOfType<TestDocument2>();
        }
Ejemplo n.º 8
0
        public void Save_should_save_a_new_document_if_it_does_not_exist()
        {
            var store = new DocumentStore { DataLocation = TestSetup.DataDir, DatabaseName = TestSetup.DatabaseName };
            var fileNameProvider = new DocumentFileNameProvider(TestSetup.DataDir, TestSetup.DatabaseName);
            var key = "77874B42-8093-450D-ADF1-861C55FB232C";
            TestSetup.SafeDeleteDocument(fileNameProvider.GetDocumentFile<TestDocument>(key).FullName);

            var document = new TestDocument
            {
                SomeInt = 1,
                SomeString = "Stringaling",
                SomeSubClassProperty = new TestDocument.SomeSubClass { SomeDouble = 1.1 }
            };

            using (var session = store.OpenSession())
            {
                session.Save(document, key);
            }

            fileNameProvider.GetDocumentFile<TestDocument>(key).Exists.Should().BeTrue();
            fileNameProvider.GetDocumentFile<TestDocument>(key).Delete();
        }