public void TestConflictHandlerWhenDocumentIsPurged() { using (var doc = new MutableDocument("doc1")) { doc.SetString("firstName", "Tiger"); Db.Save(doc); } using (var doc = Db.GetDocument("doc1")) { doc.Generation.Should().Be(1); } using (var doc1 = Db.GetDocument("doc1")) using (var doc1b = doc1.ToMutable()) { Db.Purge("doc1"); doc1b.SetString("nickName", "Scott"); Db.Invoking(d => Db.Save(doc1b, (updated, current) => { return(true); })).Should().Throw <CouchbaseLiteException>() .Where( e => e.Error == CouchbaseLiteError.NotFound && e.Domain == CouchbaseLiteErrorType.CouchbaseLite, "because the document is purged"); } }
public void TestPurgeDocOnDeletedDB() { var doc = GenerateDocument("doc1"); DeleteDB(Db); Db.Invoking(d => d.Purge(doc)) .ShouldThrow <InvalidOperationException>() .WithMessage("Attempt to perform an operation on a closed database", "because this operation is invalid"); }
public void TestDeleteDBOpenByOtherInstance() { using (var otherDB = OpenDB(Db.Name)) { Db.Invoking(d => d.Delete()) .ShouldThrow <CouchbaseLiteException>() .Where(e => e.Error == CouchbaseLiteError.Busy && e.Domain == CouchbaseLiteErrorType.CouchbaseLite, "because an in-use database cannot be deleted"); } }
public void TestDeleteDBOpenByOtherInstance() { using (var otherDB = OpenDB(Db.Name)) { Db.Invoking(d => d.Delete()) .ShouldThrow <LiteCoreException>() .Which.Error.Should() .Match <C4Error>(e => e.code == (int)C4ErrorCode.Busy && e.domain == C4ErrorDomain.LiteCoreDomain, "because an in-use database cannot be deleted"); } }
public void TestGetDocFromClosedDB() { using (var doc = GenerateDocument("doc1")) { Db.Close(); Db.Invoking(d => d.GetDocument("doc1")) .ShouldThrow <InvalidOperationException>() .WithMessage("Attempt to perform an operation on a closed database", "because this operation is invalid"); } }
public void TestDeleteThenCallInBatch() { Db.Invoking(d => d.InBatch(() => { Db.Delete(); })) .ShouldThrow <CouchbaseLiteException>() .Where( e => e.Error == CouchbaseLiteError.TransactionNotClosed && e.Domain == CouchbaseLiteErrorType.CouchbaseLite, "because a database can't be closed in the middle of a batch"); }
public void TestPurgePreSaveDoc() { var doc = new MutableDocument("doc1"); doc.SetInt("key", 1); Db.Invoking(db => db.Purge(doc)).ShouldThrow <CouchbaseLiteException>() .Where(e => e.Error == CouchbaseLiteError.NotFound); Db.Count.Should().Be(0UL, "because the database should still be empty"); }
public void TestConflictResolverGivesUp() { ConflictResolver = new GiveUp(); ReopenDB(); var doc = SetupConflict(); Db.Invoking(d => d.Save(doc)) .ShouldThrow <LiteCoreException>() .Which.Error.code.Should() .Be((int)C4ErrorCode.Conflict, "because the conflict resolver gave up"); }
public void TestDeleteThenCallInBatch() { Db.Invoking(d => d.InBatch(() => { Db.Delete(); })) .ShouldThrow <LiteCoreException>() .Which.Error.Should() .Match <C4Error>( e => e.code == (int)C4ErrorCode.TransactionNotClosed && e.domain == C4ErrorDomain.LiteCoreDomain, "because a database can't be closed in the middle of a batch"); }
public void TestDeletePreSaveDoc() { var doc = new MutableDocument("doc1"); doc.SetInt("key", 1); Db.Invoking(d => d.Delete(doc)) .ShouldThrow <CouchbaseLiteException>() .Which.Status.Should() .Be(StatusCode.NotAllowed, "because deleting an unsaved document is not allowed"); Db.Count.Should().Be(0UL, "because the database should still be empty"); }
public void TestSaveDocToDeletedDB() { DeleteDB(Db); var doc = new MutableDocument("doc1"); doc.SetInt("key", 1); Db.Invoking(d => d.Save(doc)) .ShouldThrow <InvalidOperationException>() .WithMessage("Attempt to perform an operation on a closed database", "because this operation is invalid"); }
public void TestDeletePreSaveDoc() { var doc = new MutableDocument("doc1"); doc.SetInt("key", 1); Db.Invoking(d => d.Delete(doc)) .ShouldThrow <CouchbaseLiteException>() .Where( e => e.Error == CouchbaseLiteError.NotFound && e.Domain == CouchbaseLiteErrorType.CouchbaseLite, "because deleting an unsaved document is not allowed"); Db.Count.Should().Be(0UL, "because the database should still be empty"); }
public void TestPurgeSameDocTwice() { var docID = "doc1"; var doc = GenerateDocument(docID); var doc1 = Db.GetDocument(docID); doc1.Should().NotBeNull("because the document was just created and it should exist"); PurgeDocAndVerify(doc); Db.Count.Should().Be(0UL, "because the only document was purged"); // Second purge and throw error Db.Invoking(db => db.Purge(doc)).Should().Throw <CouchbaseLiteException>().Where(e => e.Error == CouchbaseLiteError.NotFound && e.Domain == CouchbaseLiteErrorType.CouchbaseLite); }
public void TestConflictWithoutCommonAncestor() { ConflictResolver = new NoCommonAncestorValidator(); ReopenDB(); var props = new Dictionary <string, object> { ["hello"] = "world" }; var doc = new MutableDocument("doc1", props); Db.Save(doc); doc = Db.GetDocument(doc.Id).ToMutable(); doc.SetInt("university", 1); Db.Save(doc); // Create a conflict doc = new MutableDocument(doc.Id, props); doc.SetInt("university", 2); Db.Invoking(d => d.Save(doc)).ShouldThrow <LiteCoreException>().Which.Error.Should() .Be(new C4Error(C4ErrorCode.Conflict)); }
public void TestDeleteTwice() { Db.Delete(); Db.Invoking(d => d.Delete()).ShouldThrow <InvalidOperationException>(); }
public void TestCloseThenDeleteDatabase() { Db.Dispose(); Db.Invoking(DeleteDB).ShouldThrow <InvalidOperationException>(); }