Ejemplo n.º 1
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.º 2
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.º 3
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.º 4
0
 public void Initialize_should_create_the_database_folder_if_it_does_not_exist()
 {
     var store = new DocumentStore() { DataLocation = TestSetup.DataDir, DatabaseName = "NonExistingDatabase" };
     var fileNameProvider = new DocumentFileNameProvider(TestSetup.DataDir, "NonExistingDatabase");
     using (var session = store.OpenSession())
     {
         fileNameProvider.DatabaseDirectory.Exists.Should().BeTrue();
     }
 }
Ejemplo n.º 5
0
 public void Get_should_throw_DocumentNotFoundException_for_non_existing_document()
 {
     var store = new DocumentStore { DataLocation = TestSetup.DataDir, DatabaseName = TestSetup.DatabaseName };
     var key = Guid.Parse("98CD87C0-1631-4CB9-BFC6-306CCBD15C8F");
     using (var session = store.OpenSession())
     {
         session.Invoking(x => x.Get<TestDocument>(key.ToString())).ShouldThrow<DocumentNotFoundException>();
     }
 }
Ejemplo n.º 6
0
        public void OpenSession_should_return_a_new_session()
        {
            var store = new DocumentStore { DataLocation = TestSetup.DataDir, DatabaseName = TestSetup.DatabaseName };

            using (var session = store.OpenSession())
            {
                session.Should().NotBeNull();
                session.Should().BeAssignableTo<IDocumentSession>();
            }
        }
Ejemplo n.º 7
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.º 8
0
 public void OpenSession_should_throw_exception_if_datadirectory_is_not_specified()
 {
     var store = new DocumentStore { DatabaseName = TestSetup.DatabaseName };
     store.Invoking(x => x.OpenSession()).ShouldThrow<ArgumentException>();
 }
Ejemplo n.º 9
0
 public void Initialize_should_throw_exception_when_datadirectory_does_not_exist()
 {
     const string invalidPath = @"c:\invalid_path";
     var store = new DocumentStore { DataLocation = invalidPath, DatabaseName = TestSetup.DatabaseName };
     store.Invoking(x => x.OpenSession()).ShouldThrow<DirectoryNotFoundException>();
 }
Ejemplo n.º 10
0
 public void Ctor_with_connection_string_name_should_set_properties()
 {
     var store = new DocumentStore("connectionName");
     store.DataLocation.Should().Be(@"c:\temp");
     store.DatabaseName.Should().Be("TestDB");
 }
Ejemplo n.º 11
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.º 12
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.º 13
0
 public void TryGet_should_return_false_for_a_non_existing_document()
 {
     var store = new DocumentStore { DataLocation = TestSetup.DataDir, DatabaseName = TestSetup.DatabaseName };
     var nonExistingKey = "193BEFBE-911E-433D-82EF-D22F1C6D43F2";
     using (var session = store.OpenSession())
     {
         TestDocument document;
         session.TryGet(nonExistingKey, out document).Should().BeFalse();
     }
 }
Ejemplo n.º 14
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();
        }