Beispiel #1
0
        public void attached_version_document_should_not_have_history()
        {
            using (var session = new TemporarySession())
            {
                var config = Documents.Configure <TestDocUniqueVersioned>();

                var testObject = new TestDocUniqueVersioned {
                    Name = "hello world 1"
                };

                config.KeepHistory = 10;

                var result = session.Documents.Save(testObject);

                testObject.Name = "Hello World 2";

                result = session.Documents.Save(testObject);

                testObject.Name = "Hello World 3";

                result = session.Documents.Save(testObject);

                testObject = session.Documents.Get <TestDocUniqueVersioned>(result.Id);

                Assert.That(testObject._Attachments, Is.Not.Null);
                Assert.That(testObject._Attachments.Count, Is.EqualTo(2));

                var version1 = session.Documents.GetDocumentAttachment <TestDocUniqueVersioned>(result.Id, testObject._Attachments.First().Key);
                version1._Attachments.ShouldBe(null);

                var version2 = session.Documents.GetDocumentAttachment <TestDocUniqueVersioned>(result.Id, testObject._Attachments.Skip(1).First().Key);
                version2._Attachments.ShouldBe(null);
            }
        }
Beispiel #2
0
        public void should_be_able_to_delete_a_documents_and_add_another_with_same_key()
        {
            using (var session = new TemporarySession())
            {
                Documents.Configure <TestDocUnique>()
                .UniqueConstraint = unique => unique.Name;

                var testObject = new TestDocUnique {
                    Name = "hello world"
                };

                var result = session.Documents.Save <TestDocUnique>(testObject);

                Console.Write(result.Id);

                session.Delete(testObject);

                var conflictDOc = new TestDocUnique {
                    Name = "hello world"
                };

                var result2 = session.Documents.Save(conflictDOc);

                Assert.AreNotEqual(result.Id, result2.Id);
            }
        }
Beispiel #3
0
        public void should_use_configuration_database_when_specified()
        {
            using (var session = new TemporarySession())
            {
                using (var anotherSession = new TemporarySession())
                {
                    Documents.Configure <TestDoc>(database: anotherSession.DatabaseName);

                    var testObject = new TestDoc {
                        Text = "hello world"
                    };

                    var info = session.Save(testObject, "test");

                    var fromDb = session.Get <JObject>(info.Id);
                    fromDb.ShouldBe(null);


                    session.DatabaseName.ShouldBe(session.DefaultDatabase);

                    var fromDb2 = session.Get <TestDoc>(info.Id);
                    fromDb2.ShouldNotBe(null);

                    var info2 = session.Documents.Save(testObject);

                    info2.Id.ShouldBe(info.Id);

                    session.DatabaseName.ShouldBe(session.DefaultDatabase);
                }
            }
        }
Beispiel #4
0
        public void should_save_a_document_attachment()
        {
            using (var session = new TemporarySession())
            {
                var config = Documents.Configure <TestDocUnique>();
                config.TypeName = "testdocunique";

                var testObject = new TestDocUnique {
                    Name = "hello world"
                };

                var result = session.Documents.Save <TestDocUnique>(testObject);

                var    data64String   = "VGhpcyBpcyBhIGJhc2U2NCBlbmNvZGVkIHRleHQ=";
                var    bytes          = Convert.FromBase64String(data64String);
                string attachmentName = "testAttachment";

                result = session.Documents.PutAttachment(result.Id, result.Revision, attachmentName, "text/plain", bytes);

                var bytesStored = session.Documents.GetAttachment(result.Id, attachmentName);

                var doc = Convert.ToBase64String(bytesStored);

                Console.WriteLine(Encoding.UTF8.GetString(bytesStored));

                Assert.That(doc, Is.EqualTo(data64String));

                session.Documents.DeleteAttachment(result.Id, result.Revision, attachmentName);

                Assert.That(session.Documents.GetAttachment(result.Id, attachmentName), Is.Null);
            }
        }
Beispiel #5
0
        public void should_save_only_create_history_if_something_changes()
        {
            using (var session = new TemporarySession())
            {
                var config = Documents.Configure <TestDocUniqueVersioned>();

                var testObject = new TestDocUniqueVersioned {
                    Name = "hello world"
                };

                var result = session.Documents.Save <TestDocUniqueVersioned>(testObject);

                config.KeepHistory = 10;

                result = session.Documents.Save <TestDocUniqueVersioned>(testObject);

                result = session.Documents.Save <TestDocUniqueVersioned>(testObject);

                testObject = session.Documents.Get <TestDocUniqueVersioned>(result.Id);

                Assert.That(testObject._Attachments, Is.Null);

                testObject.Name = "Rock Out";

                result = session.Documents.Save <TestDocUniqueVersioned>(testObject);

                testObject = session.Documents.Get <TestDocUniqueVersioned>(result.Id);

                Assert.That(testObject._Attachments, Is.Not.Null);
                Assert.That(testObject._Attachments.Count, Is.EqualTo(1));
            }
        }
Beispiel #6
0
        public void x()
        {
            Documents.Configure <Port>((info, port) => port.Id = info.Id).UniqueConstraint = p => "--" + p.Slug;

            using (var session = new CouchSession(new Uri("http://127.0.0.1:5984"), "cruiseme"))
            {
                var results = session.Design("ports").ViewDocs <Port>("by_slug");
            }
        }
Beispiel #7
0
        public void should_be_able_hook_into_pre_and_post_save_events()
        {
            using (var session = new TemporarySession())
            {
                var config = Documents.Configure <TestDocUnique>();


                int           counter = 0, onSavingCounter = 0, onSavedCounter = 0;
                string        onSavedId = String.Empty, onSavingId = String.Empty, onSavingRevision = String.Empty, onSavedRevision = String.Empty;
                TestDocUnique onSavingObj = null, onSavedObj = null;

                config.OnSaving = (id, rev, obj) =>
                {
                    onSavingCounter  = counter++;
                    onSavingId       = id;
                    onSavingRevision = rev;
                    onSavingObj      = obj;
                };

                config.OnSaved = (id, rev, obj) =>
                {
                    onSavedCounter  = counter++;
                    onSavedId       = id;
                    onSavedRevision = rev;
                    onSavedObj      = obj;
                };

                var testObject = new TestDocUnique {
                    Name = "hello world"
                };

                var result = session.Documents.Save <TestDocUnique>(testObject);

                result.Id.ShouldBe(onSavedId);
                result.Id.ShouldBe(onSavingId);

                onSavingRevision.ShouldBe(null);
                result.Revision.ShouldBe(onSavedRevision);

                testObject.ShouldBe(onSavingObj);
                testObject.ShouldBe(onSavedObj);
            }
        }
Beispiel #8
0
        public void should_be_able_to_soft_delete_a_document()
        {
            using (var session = new TemporarySession())
            {
                var config = Documents.Configure <TestDocUnique>();
                config.TypeName = "testdocunique";

                var testObject = new TestDocUnique {
                    Name = "hello world"
                };

                var result = session.Documents.Save <TestDocUnique>(testObject);

                Console.Write(result.Id);

                session.Documents.Delete(testObject);

                Console.WriteLine("x");
            }
        }
Beispiel #9
0
        public void should_be_able_to_use_a_custom_documet_type()
        {
            using (var session = new TemporarySession())
            {
                var config = Documents.Configure <TestDocUnique>();
                config.TypeName = "testdocunique";

                var testObject = new TestDocUnique {
                    Name = "hello world"
                };

                var result = session.Documents.Save <TestDocUnique>(testObject);

                Console.Write(result.Id);

                var testObjectFromDb = session.Documents.Get <JObject>(result.Id);

                Assert.AreEqual("testdocunique", testObjectFromDb["type"].ToString());
            }
        }
Beispiel #10
0
        public void should_be_able_to_use_a_slight_of_hand_with_my_types_id()
        {
            using (var session = new TemporarySession())
            {
                var config = Documents.Configure <TestDocUnique>();
                config.CreateId  = unique => "TestDocUnique-" + unique.Name;
                config.ResolveId = s => "TestDocUnique-" + s;

                var testObject = new TestDocUnique {
                    Name = "hello world"
                };

                var result = session.Documents.Save <TestDocUnique>(testObject);

                Console.Write(result.Id);

                var testObjectFromDb = session.Documents.Get <TestDocUnique>("hello world");

                Assert.NotNull(testObjectFromDb);
            }
        }
Beispiel #11
0
        public void should_save_a_document_version_history_when_enabled()
        {
            using (var session = new TemporarySession())
            {
                var config = Documents.Configure <TestDocUniqueVersioned>();

                var testObject = new TestDocUniqueVersioned {
                    Name = "hello world"
                };

                var result = session.Documents.Save <TestDocUniqueVersioned>(testObject);

                config.KeepHistory = 10;

                testObject = new TestDocUniqueVersioned {
                    Name = "hello world 1"
                };

                result = session.Documents.Save <TestDocUniqueVersioned>(testObject);

                testObject.Name = "hello world";

                result = session.Documents.Save <TestDocUniqueVersioned>(testObject);

                testObject = session.Documents.Get <TestDocUniqueVersioned>(result.Id);

                Assert.That(testObject._Attachments, Is.Not.Null);
                Assert.That(testObject._Attachments.Count, Is.EqualTo(1));

                testObject.Name = "Rock Out";

                result = session.Documents.Save <TestDocUniqueVersioned>(testObject);


                testObject = session.Documents.Get <TestDocUniqueVersioned>(result.Id);

                Assert.That(testObject._Attachments, Is.Not.Null);
                Assert.That(testObject._Attachments.Count, Is.EqualTo(2));
            }
        }
Beispiel #12
0
        public void should_throw_an_exception_if_unique_constraint_violated()
        {
            using (var session = new TemporarySession())
            {
                Documents.Configure <TestDocUnique>()
                .UniqueConstraint = unique => unique.Name;

                var testObject = new TestDocUnique {
                    Name = "hello world"
                };

                var result = session.Documents.Save <TestDocUnique>(testObject);

                Console.Write(result.Id);

                var conflictDOc = new TestDocUnique {
                    Name = "hello world"
                };

                Assert.Throws <ArgumentException>(() => session.Documents.Save(conflictDOc));
            }
        }
Beispiel #13
0
        public void should_save_a_document_version_history_when_enabled_and_document_doesnt_have_attachment_property()
        {
            using (var session = new TemporarySession())
            {
                var config = Documents.Configure <TestDocUnique>();

                var testObject = new TestDocUnique {
                    Name = "hello world"
                };

                var result = session.Documents.Save <TestDocUnique>(testObject);

                config.KeepHistory = 10;

                testObject = new TestDocUnique {
                    Name = "hello world"
                };

                result = session.Documents.Save <TestDocUnique>(testObject);

                testObject.Name = "Hello World 2";

                result = session.Documents.Save <TestDocUnique>(testObject);

                var jObject = session.Documents.Get <JObject>(result.Id);

                Assert.That(jObject["_attachments"], Is.Not.Null);
                Assert.That(jObject["_attachments"].Children().Count(), Is.EqualTo(1));

                testObject.Name = "Rock Out";

                result = session.Documents.Save <TestDocUnique>(testObject);

                jObject = session.Documents.Get <JObject>(result.Id);

                Assert.That(jObject["_attachments"], Is.Not.Null);
                Assert.That(jObject["_attachments"].Children().Count(), Is.EqualTo(2));
            }
        }
Beispiel #14
0
        public void history_should_be_limited_to_keep_history_length()
        {
            using (var session = new TemporarySession())
            {
                var config = Documents.Configure <TestDocUnique>();

                var testObject = new TestDocUnique {
                    Name = "hello world"
                };

                var result = session.Documents.Save <TestDocUnique>(testObject);

                config.KeepHistory = 2;

                testObject = new TestDocUnique {
                    Name = "hello world"
                };

                result = session.Documents.Save <TestDocUnique>(testObject);

                testObject.Name = "Hello World 2";

                result = session.Documents.Save <TestDocUnique>(testObject);

                testObject.Name = "Hello World 3";

                result = session.Documents.Save <TestDocUnique>(testObject);

                testObject.Name = "Hello World 4";

                result = session.Documents.Save <TestDocUnique>(testObject);

                var jObject = session.Documents.Get <JObject>(result.Id);

                Assert.That(jObject["_attachments"], Is.Not.Null);
                Assert.That(jObject["_attachments"].Children().Count(), Is.EqualTo(2));
            }
        }