public void GetDocumentId_When_DocId_Exists_Use_It()
 {
     var beer = new Beer {Name = "beer1"};
     var bucket = new Mock<IBucket>();
     var ctx = new BucketContext(bucket.Object);
     var id = ctx.GetDocumentId(beer);
     Assert.AreEqual("beer1", id);
 }
 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_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 SubmitChanges_WhenCalled_DoesNotClearTrackedList()
        {
            //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 = new Beer
            {
                Name = "doc1" //key field
            };

            ctx.Save(beer);

            //act
            ctx.SubmitChanges();

            //assert
            Assert.AreEqual(1, ctx.TrackedCount);
        }
        public void SubmitChanges_Removes_Document_From_Modified_List()
        {
            //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 = new Beer
            {
                Name = "doc1" //key field
            };

            ctx.Save(beer);

            //act
            ctx.SubmitChanges();

            //assert
            Assert.AreEqual(0, ctx.ModifiedCount);
        }
        public void Save_When_Write_Is_Succesful_Return_Success()
        {
            //arrange
            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.Upsert(It.IsAny<string>(), It.IsAny<Beer>())).Returns(result.Object);
            var ctx = new BucketContext(bucket.Object);

            //act
            ctx.Save(beer);

            //assert - does not throw exception
        }
        public void Save_WhenChangeTrackingEnabled_AddsToTrackedList()
        {
            //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 = new Beer
            {
                Name = "doc1" //key field
            };

            ctx.Save(beer);

            Assert.AreEqual(1, ctx.TrackedCount);
        }