Example #1
0
        public void Update_Multiple_CreatesCorrectly()
        {
            var conn = new CouchConnection("http://127.0.0.1", 5984);
            var svc = new CouchService(conn);
            var db = svc.GetDatabase("integrationtest");

            var card1 = new BusinessCard { Name = "Bob Smith", Employer = "GiantMart", JobTitle = "Manager" };
            var card2 = new BusinessCard { Name = "Jack Smith", Employer = "MediumMart", JobTitle = "Manager" };
            var card3 = new BusinessCard { Name = "Bill Smith", Employer = "TinyMart", JobTitle = "Manager" };

            var resp = db.AddMany(new[] {card1, card2, card3}).ToList();

            Assert.IsNotNull(resp);
            Assert.AreEqual(3, resp.Count);
            Assert.IsNotNull(db.RawResponse);
            Assert.AreEqual(HttpStatusCode.Created, db.RawResponse.StatusCode);

            card1 = db.Get<BusinessCard>(resp[0].Id);
            card2 = db.Get<BusinessCard>(resp[1].Id);
            card3 = db.Get<BusinessCard>(resp[2].Id);

            card1.JobTitle = "Chicken";
            card2.JobTitle = "Horse";
            card3.JobTitle = "Monkey";

            resp = db.SaveMany(new[] {card1, card2, card3}).ToList();

            Assert.AreEqual(3, resp.Count);
            Assert.IsTrue(resp[0].Revision.Contains("2-"));
            Assert.IsTrue(resp[1].Revision.Contains("2-"));
            Assert.IsTrue(resp[2].Revision.Contains("2-"));
            Assert.IsNotNull(db.RawResponse);
            Assert.AreEqual(HttpStatusCode.Created, db.RawResponse.StatusCode);
        }
Example #2
0
        public void KeyMatch_Array()
        {
            var conn = new CouchConnection("http://localhost:5984/");
            var svc = new CouchService(conn);
            var db = svc.GetDatabase("integrationtest");

            var query = new CouchViewQuery().Key(new[] { "apple", "orange" });

            var results = db.GetDesignDocument("example").ExecuteView<TestEntity>("arraytest", query);

            Debug.WriteLine("-----------------------------------------");

            if (results.IsOk)
            {
                if (results.HasResults)
                {
                    foreach (var result in results)
                    {
                        Debug.WriteLine("Name : " + result.name);
                    }
                }
                else
                {
                    Debug.WriteLine("No results found :(");
                }
            }
            else
            {
                Debug.WriteLine("Error: " + results.Response.ErrorType + " / " + results.Response.ErrorMessage);
            }

            Assert.IsTrue(results.IsOk);
            Assert.Greater(results.Count, 0);
        }
Example #3
0
        public void KeyMatch_Array_LimitZero_ShouldReturnTotals()
        {
            var conn = new CouchConnection("http://localhost:5984/");
            var svc = new CouchService(conn);
            var db = svc.GetDatabase("integrationtest");

            var query = new CouchViewQuery().Key(new[] { "apple", "orange" }).Limit(0);

            var results = db.GetDesignDocument("example").ExecuteView<TestEntity>("arraytest", query);

            Debug.WriteLine("-----------------------------------------");

            if (results.IsOk)
            {
                if (results.HasResults)
                {
                    foreach (var result in results)
                    {
                        Debug.WriteLine("Name : " + result.name);
                    }
                }
                else
                {
                    Debug.WriteLine("TotalRows : " + results.TotalRows);
                    Debug.WriteLine("Offset : " + results.Offset);
                }
            }
            else
            {
                Debug.WriteLine("Error: " + results.Response.ErrorType + " / " + results.Response.ErrorMessage);
            }

            Assert.Greater(results.TotalRows, 0);
            Assert.AreEqual(0, results.Count);
        }
Example #4
0
        public void Compact_NullObject_Throws()
        {
            _connectionMock = new Mock<ICouchConnection>(MockBehavior.Strict);
            _connectionMock.Setup(s => s.Post("unittest/_compact", null)).Returns(_errorMissingResponse.Object);

            var svc = new CouchService(_connectionMock.Object);
            Assert.Throws<ArgumentNullException>(() => svc.BeginDatabaseCompact(null));
        }
Example #5
0
        public void Database_CanGetStatus()
        {
            var conn = new CouchConnection("http://127.0.0.1", 5984);
            var svc = new CouchService(conn);
            var db = svc.GetDatabase("integrationtest");

            var status = db.Status();
            Assert.AreEqual("integrationtest", status.DatabaseName);
        }
Example #6
0
        public void Compact_Begin_Return()
        {
            _connectionMock = new Mock<ICouchConnection>(MockBehavior.Strict);
            _connectionMock.Setup(s => s.Post("unittest/_compact", null)).Returns(_successResponse.Object);

            var svc = new CouchService(_connectionMock.Object);
            var result = svc.BeginDatabaseCompact(svc.GetDatabase("unittest"));

            Assert.IsTrue(result.IsOk);
        }
        public void DropShow()
        {
            _connectionMock = new Mock<ICouchConnection>(MockBehavior.Strict);
            _connectionMock.Setup(x => x.Put("unittest/_design/example", "{\"_id\":\"_design/example\",\"_rev\":\"1234\",\"language\":\"javascript\",\"shows\":{},\"lists\":{},\"rewrites\":[],\"updates\":{}}")).Returns(_httpResponse.Object);

            var svc = new CouchService(_connectionMock.Object);
            var db = svc["unittest"];
            var dd = new CouchDesignDocument(_designDocumentDefinition, db);
            dd.DropShow("testShow");

            Assert.AreEqual(0, dd.Shows.Count);
        }
Example #8
0
        public void Add_Single_ReturnCodeIsCorrect()
        {
            var conn = new CouchConnection("http://127.0.0.1", 5984);
            var svc = new CouchService(conn);
            var db = svc.GetDatabase("integrationtest");

            var card = new BusinessCard { Name = "Bob Smith", Employer = "GiantMart", JobTitle = "Manager" };

            var resp = db.Add(card);

            Assert.IsNotNull(resp);
            Assert.IsNotNull(db.RawResponse);
            Assert.AreEqual(HttpStatusCode.Created, db.RawResponse.StatusCode);
        }
Example #9
0
        public void Add_Conflict_HandleError()
        {
            _connectionMock = new Mock<ICouchConnection>(MockBehavior.Strict);
            _connectionMock.Setup(s => s.Put("unittest/some_doc_id", It.IsAny<string>())).Returns(_addConflictDocumentResponse.Object);

            var svc = new CouchService(_connectionMock.Object);
            var db = svc.GetDatabase("unittest");
            var response = db.Add(new ExampleEntity { Id = "some_doc_id", Age = 22, IsAlive = false, Name = "Bob" });

            Assert.IsNotNull(response);
            Assert.IsFalse(response.IsOk);
            Assert.IsNullOrEmpty(response.Id);
            Assert.AreEqual("conflict", response.ErrorType);
            Assert.AreEqual("Document update conflict.", response.ErrorMessage);
        }
        public void CreateView()
        {
            _connectionMock = new Mock<ICouchConnection>(MockBehavior.Strict);

            var svc = new CouchService(_connectionMock.Object);
            var db = svc["unittest"];

            var dd = new CouchDesignDocument("example", db);
            var view = dd.CreateView("testView");

            Assert.IsAssignableFrom<CouchView>(view);
            Assert.IsNull(view.Map);
            Assert.IsNull(view.Reduce);
            Assert.IsTrue(view.HasPendingChanges);
            Assert.AreEqual("testView",view.Name);
        }
        public void CreateShow()
        {
            _connectionMock = new Mock<ICouchConnection>(MockBehavior.Strict);

            var svc = new CouchService(_connectionMock.Object);
            var db = svc["unittest"];

            var dd = new CouchDesignDocument("example", db);
            var show = dd.CreateShow("testShow");

            Assert.IsAssignableFrom<CouchShowHandler>(show);
            Assert.IsNull(show.Function);
            Assert.IsTrue(show.HasPendingChanges);
            Assert.AreEqual("testShow", show.Name);
            Assert.AreEqual(dd,show.DesignDocument);
            Assert.AreEqual("_design/example/_show/testShow", show.ToString());
        }
Example #12
0
        public void CacheObjectTest()
        {
            var conn = new CouchConnection("http://localhost:5984");

            var cache = new HttpRuntimeCache { ExpirationWindow = 5 };
            conn.Cache = cache;

            var svc = new CouchService(conn);
            var db = svc.GetDatabase("integrationtest");

            var resp = db.Get<BusinessCard>("d1d2bac2b4e65baf10be20bf08000189");
            Debug.WriteLine("Name : " + resp.Name);
            Debug.WriteLine("--------------------------------");

            var resp2 = db.Get<BusinessCard>("d1d2bac2b4e65baf10be20bf08000189");
            Debug.WriteLine("Name : " + resp2.Name);
            Debug.WriteLine("--------------------------------");
        }
Example #13
0
        public void Get_FieldsMissing_NotFoundFieldsShouldBeDefault()
        {
            _connectionMock = new Mock<ICouchConnection>(MockBehavior.Strict);
            _connectionMock.Setup(s => s.Get("unittest/abc123")).Returns(_missingFieldResponse.Object);

            var svc = new CouchService(_connectionMock.Object);
            var db = svc.GetDatabase("unittest");
            var result = db.Get<ExampleEntity>("abc123");

            Assert.IsNotNull(result);
            Assert.IsNull(result.Name);
            Assert.AreEqual(0, result.Age);
            Assert.False(result.IsAlive);
        }
Example #14
0
        public void Add_SimpleAddWithSpecifiedId_CreatesWithId()
        {
            _connectionMock = new Mock<ICouchConnection>(MockBehavior.Strict);
            _connectionMock.Setup(s => s.Put("unittest/some_doc_id", It.IsAny<string>())).Returns(_addDocumentResponse.Object);

            var svc = new CouchService(_connectionMock.Object);
            var db = svc.GetDatabase("unittest");
            var response = db.Add(new ExampleEntity { Id = "some_doc_id", Age = 22, IsAlive = false, Name = "Bob" });

            Assert.IsNotNull(response);
            Assert.IsTrue(response.IsOk);
            Assert.IsNotNullOrEmpty(response.Id);
            Assert.AreEqual("some_doc_id", response.Id);
        }
Example #15
0
        public void Get_GetRevision_SerializeNormally()
        {
            _connectionMock = new Mock<ICouchConnection>(MockBehavior.Strict);
            _connectionMock.Setup(s => s.Get("unittest/abc123?rev=946B7D1C")).Returns(_basicResponse.Object);

            var svc = new CouchService(_connectionMock.Object);
            var db = svc.GetDatabase("unittest");
            var result = db.Get<ExampleEntity>("abc123", "946B7D1C");

            Assert.IsNotNull(result);
            Assert.AreEqual(_exampleObject.Name, result.Name);
            Assert.AreEqual(_exampleObject.Age, result.Age);
            Assert.AreEqual(_exampleObject.IsAlive, result.IsAlive);
            Assert.AreEqual(_exampleObject.Revision, "946B7D1C");
        }
Example #16
0
 public void CreateDatabase_HeadCheck()
 {
     var svc = new CouchService("http://www.couchdbtest.com:5984");
     var db = svc.GetDatabase("monkeytennis");
 }
Example #17
0
        public void Get_IncludeRevisions_SerializeNormally()
        {
            _connectionMock = new Mock<ICouchConnection>(MockBehavior.Strict);
            _connectionMock.Setup(s => s.Get("unittest/abc123?revs=true")).Returns(_revisionsResponse.Object);

            var svc = new CouchService(_connectionMock.Object);
            var db = svc.GetDatabase("unittest");
            var result = db.Get<ExampleEntity>("abc123", CouchDocumentOptions.IncludeRevisions);

            Assert.IsNotNull(result);
            Assert.AreEqual(_exampleObject.Name, result.Name);
            Assert.AreEqual(3, result.Revisions.Start);
            Assert.AreEqual(3, result.Revisions.RevisionIds.Length);
        }
Example #18
0
        public void TempView_CanSerialize()
        {
            var conn = new CouchConnection("http://localhost:5984/");
            var svc = new CouchService(conn);
            var db = svc.GetDatabase("unittest");
            var temp = new CouchTempView { Map = "function(doc) {\n  emit(null, doc);\n}" };
            var results = db.ExecuteTempView<BusinessCard>(temp, new CouchViewQuery());

            if (results.IsOk)
            {
                if (results.HasResults)
                {
                    foreach (var result in results)
                    {
                        Debug.WriteLine(result.Name);
                    }
                }
                else
                {
                    Debug.WriteLine("Nothing found :(");
                }
            }
            else
            {
                Debug.WriteLine("Error: " + results.Response.ErrorType + " / " + results.Response.ErrorMessage);
            }
        }
        public void ExecuteView_EmptyResults_ShouldBeOk()
        {
            _connectionMock = new Mock<ICouchConnection>(MockBehavior.Strict);
            _connectionMock.Setup(x => x.Get("unittest/_design/example/_view/testView?key=%22apple%22")).Returns(_viewEmptyResults.Object);
            _connectionMock.Setup(x => x.Get("unittest/_design/example")).Returns(_viewDefinition.Object);

            var svc = new CouchService(_connectionMock.Object);

            var db = svc.GetDatabase("unittest");

            var query = new CouchViewQuery().Key("apple");

            var results = db.GetDesignDocument("example").ExecuteView<ExampleEntity>("testView", query);
            Assert.IsTrue(results.IsOk);
            Assert.IsFalse(results.HasResults);
            Assert.AreEqual(0, results.Count);
        }
Example #20
0
        public void List_CanExecuteCorrectly()
        {
            var conn = new CouchConnection("http://localhost:5984/");
            var svc = new CouchService(conn);
            var db = svc.GetDatabase("unittest");

            var result = db.GetDesignDocument("example").ExecuteList("htmlList", "test", new CouchViewQuery());

            Debug.WriteLine(result.Output);

            var query = new CouchViewQuery().Key("e99b84cd49824eaf90b5f5c164b39e12");
            result = db.GetDesignDocument("example").ExecuteList("htmlList", "test", query );

            Debug.WriteLine(result.Output);
        }
Example #21
0
        public void NewSyntax()
        {
            var conn = new CouchConnection("http://localhost:5984/");
            var svc = new CouchService(conn);
            var db = svc.GetDatabase("unittest");

            var doc = db.GetDesignDocument("example");

            //-[ View Execution ]---------------------------------------------

            var results = doc.ExecuteView<BusinessCard>("test", new CouchViewQuery());

            if (results.IsOk && results.HasResults)
            {
                foreach (var i in results)
                {
                    Debug.WriteLine(i.Name);
                }
            }

            //-[ Add New View ]---------------------------------------------

            //var newView = new CouchView("myNewView");
            //newView.Map = "function(test)";
            //newView.Reduce = "function(blah);
            //doc.Add(newView);
            //db.SaveChanges(doc);

            //-[ Edit Existing View ]---------------------------------------------

            //var oldView = doc.View("test");
            //Debug.WriteLine(oldView.Map);

            //doc.View("test").Map = "function(new)"; //Set HasChanges()

            //Debug.WriteLine(doc.View("test").Map);

            //db

            //-[ Show ]---------------------------------------------
            //var results = doc.ExecuteShow(doc.Show("test"));
            //var results = doc.ExecuteShow(doc.Show("test"),"docId");
            var showResults = doc.ExecuteShow("test", "e99b84cd49824eaf90b5f5c164b39e12", new NameValueCollection { { "format", "xml" } });

            if (showResults.IsOk)
            {
                Debug.WriteLine(showResults.Output);
            }
        }
        public void PublicCreate()
        {
            _connectionMock = new Mock<ICouchConnection>(MockBehavior.Strict);

            var svc = new CouchService(_connectionMock.Object);
            var db = svc["unittest"];

            var dd = new CouchDesignDocument("example", db);

            Assert.IsNotNull(dd);
            Assert.AreEqual("_design/example",dd.Id);
            Assert.AreEqual(0,dd.Views.Count);
            Assert.AreEqual(0,dd.Shows.Count);
            Assert.AreEqual(0,dd.Lists.Count);
            Assert.AreEqual(0,dd.RewriteRules.Count);
            Assert.AreEqual(0,dd.DocumentUpdaters.Count);
            Assert.IsTrue(dd.HasPendingChanges);
            Assert.AreEqual("javascript",dd.Language);
            Assert.IsNull(dd.Revision);
            Assert.AreEqual("example",dd.Name);
        }
        public void PublicCreate_WithDesignInName_ShouldFormatName()
        {
            _connectionMock = new Mock<ICouchConnection>(MockBehavior.Strict);

            var svc = new CouchService(_connectionMock.Object);
            var db = svc["unittest"];

            var dd = new CouchDesignDocument("_design/example", db);
            Assert.AreEqual("example", dd.Name);
        }
        public void InternalCreate_Full()
        {
            _connectionMock = new Mock<ICouchConnection>(MockBehavior.Strict);
            var svc = new CouchService(_connectionMock.Object);
            var db = svc["unittest"];

            var dd = new CouchDesignDocument(_designDocumentDefinition, db);

            Assert.AreEqual(_designDocumentDefinition.Id, dd.Id);
            Assert.AreEqual(_designDocumentDefinition.Revision, dd.Revision);
            Assert.AreEqual(1, dd.Views.Count);
            Assert.AreEqual(1, dd.Shows.Count);
            Assert.AreEqual(1, dd.Lists.Count);
            Assert.AreEqual(1, dd.RewriteRules.Count);
            Assert.AreEqual(1, dd.DocumentUpdaters.Count);
            Assert.AreEqual("example", dd.Name);
        }
Example #25
0
        public void Get_BasicDocument_SerializesBackToObject()
        {
            _connectionMock = new Mock<ICouchConnection>(MockBehavior.Strict);
            _connectionMock.Setup(s => s.Get("unittest/abc123")).Returns(_basicResponse.Object);

            var svc = new CouchService(_connectionMock.Object);
            var db = svc.GetDatabase("unittest");
            var result = db.Get<ExampleEntity>("abc123");

            Assert.IsNotNull(result);
            Assert.AreEqual(_exampleObject.Name, result.Name);
            Assert.AreEqual(_exampleObject.Age, result.Age);
            Assert.AreEqual(_exampleObject.IsAlive, result.IsAlive);
        }
Example #26
0
 public void Get_NullRef_ShouldThrow()
 {
     _connectionMock = new Mock<ICouchConnection>(MockBehavior.Strict);
     var svc = new CouchService(_connectionMock.Object);
     var db = svc.GetDatabase("unittest");
     string test = null;
     Assert.Throws<ArgumentNullException>(() => db.Get<ExampleEntity>(test));
 }
Example #27
0
        public void Get_CouchDoc_IdAndRevision()
        {
            _connectionMock = new Mock<ICouchConnection>(MockBehavior.Strict);
            _connectionMock.Setup(s => s.Get("unittest/abc123?rev=946B7D1C")).Returns(_revisionInfoResponse.Object);

            var svc = new CouchService(_connectionMock.Object);
            var db = svc.GetDatabase("unittest");
            var result = db.Get("abc123","946B7D1C");

            Assert.IsNotNull(result);
            Assert.AreEqual(result.Revision, "946B7D1C");
        }
Example #28
0
        public void Get_NotFound_ShouldThrow()
        {
            _connectionMock = new Mock<ICouchConnection>(MockBehavior.Strict);
            _connectionMock.Setup(s => s.Get("unittest/abc123")).Returns(_notFoundResponse.Object);

            var svc = new CouchService(_connectionMock.Object);
            var db = svc.GetDatabase("unittest");
            Assert.Throws<CouchDocumentNotFoundException>(() => db.Get<ExampleEntity>("abc123"));
        }
Example #29
0
        public void Get_NullValues_Throws()
        {
            _connectionMock = new Mock<ICouchConnection>(MockBehavior.Strict);

            var svc = new CouchService(_connectionMock.Object);
            var db = svc.GetDatabase("unittest");
            Assert.Throws<ArgumentNullException>(() => db.Get<ExampleEntity>(null, string.Empty));
        }
Example #30
0
        public void Show_CanExecuteCorrectly()
        {
            var conn = new CouchConnection("http://localhost:5984/");
            var svc = new CouchService(conn);
            var db = svc.GetDatabase("unittest");

            var result = db.GetDesignDocument("example").ExecuteShow("test");
            Debug.WriteLine(result.Output);

            result = db.GetDesignDocument("example").ExecuteShow("test", "e99b84cd49824eaf90b5f5c164b39e12");
            Debug.WriteLine(result.Output);

            result = db.GetDesignDocument("example").ExecuteShow("test", "e99b84cd49824eaf90b5f5c164b39e12", new NameValueCollection { { "format", "xml" } });
            Debug.WriteLine(result.Output);
        }