public void Remove_ThenQuery_ReturnsChanges() { var bucket = ClusterHelper.GetBucket("beer-sample"); var clusterVersion = VersionProvider.Current.GetVersion(bucket); if (clusterVersion < FeatureVersions.ReadYourOwnWrite) { Assert.Ignore("Cluster does not support RYOW, test skipped."); } var db = new BucketContext(bucket); var testValue = new Random().Next(0, 100000); var testKey = "Remove_ThenQuery_ReturnsChanges_" + testValue; var testDocument = new Sample { Id = testKey, Value = testValue }; db.Save(testDocument); db.Remove(testDocument); Assert.NotNull(db.MutationState); var result = db.Query <Sample>() .ConsistentWith(db.MutationState) .Select(p => p.Id) .FirstOrDefault(p => p == testKey); Assert.Null(result); }
public ActionResult Delete(int id, FormCollection formCollection) { // Begin change tracking _db.BeginChangeTracking(); var query = from p in _db.Query <Airline>() where p.Id == id select p; var airline = query.FirstOrDefault(); if (airline == null) { return(HttpNotFound()); } // Remove the document and save the changes _db.Remove(airline); _db.SubmitChanges(); // Collect mutation state for queries on the next page view TempData["AirlineMutationState"] = _db.MutationState; return(RedirectToAction("Index")); }
public void Save_RemoveThenSave_ClearsIsDeletedFlagAndSetsIsDirtyAndAddsToModified() { //arrange var bucket = new Mock <IBucket>(); bucket.Setup(x => x.Configuration).Returns(new ClientConfiguration().BucketConfigs.First().Value); var ctx = new BucketContext(bucket.Object); ctx.BeginChangeTracking(); var beer = (Beer)DocumentProxyManager.Default.CreateProxy(typeof(Beer)); beer.Name = "doc1"; // ReSharper disable once SuspiciousTypeConversion.Global var trackedDoc = (ITrackedDocumentNode)beer; trackedDoc.Metadata = new DocumentMetadata() { Id = "doc1" }; trackedDoc.ClearStatus(); (ctx as IChangeTrackableContext).Track(beer); //act ctx.Remove(beer); ctx.Save(beer); //assert Assert.True(trackedDoc.IsDirty); Assert.False(trackedDoc.IsDeleted); Assert.AreEqual(1, ctx.ModifiedCount); }
public void Remove_When_DocId_Is_Not_Defined_Throw_DocumentIdMissingException() { //arrange var brewery = new Brewery(); var bucket = new Mock <IBucket>(); var ctx = new BucketContext(bucket.Object); //act-assert Assert.Throws <KeyAttributeMissingException>(() => ctx.Remove(brewery)); }
public void Remove_When_Write_Is_Not_Succesful_Throw_CouchbaseWriteException() { var beer = new Beer(); var bucket = new Mock<IBucket>(); var result = new Mock<IOperationResult<Beer>>(); result.Setup(x => x.Success).Returns(false); bucket.Setup(x => x.Remove(It.IsAny<string>())).Returns(result.Object); var ctx = new BucketContext(bucket.Object); Assert.Throws<CouchbaseWriteException>(() => ctx.Remove(beer)); }
public void Remove_When_DocId_Is_Not_Defined_Throw_DocumentIdMissingException() { var brewery = new Brewery(); var bucket = new Mock<IBucket>(); var result = new Mock<IOperationResult<Brewery>>(); result.Setup(x => x.Status).Returns(ResponseStatus.Success); bucket.Setup(x => x.Upsert(It.IsAny<string>(), It.IsAny<Brewery>())).Returns(result.Object); var ctx = new BucketContext(bucket.Object); Assert.Throws<KeyAttributeMissingException>(() => ctx.Remove(brewery)); }
public void Remove_When_Write_Is_Succesful_Return_Success() { var beer = new Beer(); var bucket = new Mock<IBucket>(); var result = new Mock<IOperationResult<Beer>>(); result.Setup(x => x.Status).Returns(ResponseStatus.Success); result.Setup(x => x.Success).Returns(true); bucket.Setup(x => x.Remove(It.IsAny<string>())).Returns(result.Object); var ctx = new BucketContext(bucket.Object); ctx.Remove(beer); }
public void Remove_When_Write_Is_Not_Succesful_Throw_CouchbaseWriteException() { var beer = new Beer(); var bucket = new Mock <IBucket>(); var result = new Mock <IOperationResult <Beer> >(); result.Setup(x => x.Success).Returns(false); bucket.Setup(x => x.Remove(It.IsAny <string>())).Returns(result.Object); var ctx = new BucketContext(bucket.Object); Assert.Throws <CouchbaseWriteException>(() => ctx.Remove(beer)); }
public void Remove_When_DocId_Is_Not_Defined_Throw_DocumentIdMissingException() { var brewery = new Brewery(); var bucket = new Mock <IBucket>(); var result = new Mock <IOperationResult <Brewery> >(); result.Setup(x => x.Status).Returns(ResponseStatus.Success); bucket.Setup(x => x.Upsert(It.IsAny <string>(), It.IsAny <Brewery>())).Returns(result.Object); var ctx = new BucketContext(bucket.Object); Assert.Throws <KeyAttributeMissingException>(() => ctx.Remove(brewery)); }
public void Remove_When_Write_Is_Succesful_Return_Success() { var beer = new Beer(); var bucket = new Mock <IBucket>(); var result = new Mock <IOperationResult <Beer> >(); result.Setup(x => x.Status).Returns(ResponseStatus.Success); result.Setup(x => x.Success).Returns(true); bucket.Setup(x => x.Remove(It.IsAny <string>())).Returns(result.Object); var ctx = new BucketContext(bucket.Object); ctx.Remove(beer); }
public ActionResult Delete(string id) { try { // TODO: Add delete logic here var contact = _bucketContext.Query <Contact>().FirstOrDefault(x => N1QlFunctions.Meta(x).Id == id); if (contact == null) { return(NotFound()); } contact.id = id; _bucketContext.Remove(contact); _bucketContext.SubmitChanges(); return(RedirectToAction(nameof(Index))); } catch (Exception e) { ModelState.AddModelError("error", e.Message); return(View()); } }
public void Remove_When_DocId_Is_Not_Defined_Throw_DocumentIdMissingException() { //arrange var brewery = new Brewery(); var bucket = new Mock<IBucket>(); var ctx = new BucketContext(bucket.Object); //act-assert Assert.Throws<KeyAttributeMissingException>(() => ctx.Remove(brewery)); }
public void SubmitChanges_ThenQuery_ReturnsChanges() { var bucket = ClusterHelper.GetBucket("beer-sample"); var clusterVersion = VersionProvider.Current.GetVersion(bucket); if (clusterVersion < FeatureVersions.ReadYourOwnWrite) { Assert.Ignore("Cluster does not support RYOW, test skipped."); } var db = new BucketContext(bucket); var testValue = new Random().Next(0, 100000); var testKey = "SubmitChanges_ThenQuery_ReturnsChanges_" + testValue; var testDocument = new Sample { Id = testKey, Value = testValue }; db.BeginChangeTracking(); db.Save(testDocument); db.SubmitChanges(); try { Assert.NotNull(db.MutationState); var result = db.Query<Sample>() .ConsistentWith(db.MutationState) .FirstOrDefault(p => p.Id == testKey); Assert.NotNull(result); Assert.AreEqual(testValue, result.Value); } finally { db.Remove(testDocument); } }