public void When_Insert_Called_And_AuthenticationError_Is_Returned_Throw_AuthenticationException()
        {
            var beer = new Beer
            {
                Id = "beer1"
            };

            var bucket = new Mock<IBucket>();
            bucket.Setup(x => x.Insert(It.IsAny<Document<Beer>>()))
                .Returns(() => new FakeDocumentResult<Beer>
                {
                    Status = ResponseStatus.AuthenticationError,
                    Success = false
                });

            var dao = new DataAccessObject<Beer>(bucket.Object);
            Assert.Throws<CouchbaseAuthenticationException>(() => dao.Insert(beer));
            bucket.VerifyAll();
        }
        public void When_Insert_Called_And_Document_Exists_Throw_DocumentExistsException()
        {
            var beer = new Beer
            {
                Id = "beer1"
            };

            var bucket = new Mock<IBucket>();
            bucket.Setup(x => x.Insert(It.IsAny<Document<Beer>>()))
                .Returns(() => new FakeDocumentResult<Beer>
                {
                    Status = ResponseStatus.KeyExists,
                    Message = "The Key Exists",
                    Success = false
                });

            var dao = new DataAccessObject<Beer>(bucket.Object);
            Assert.Throws<DocumentExistsException>(() => dao.Insert(beer));
            bucket.VerifyAll();
        }
        public void When_Insert_Called_And_Document_Does_Not_Exists_Operation_Completes()
        {
            var beer = new Beer
            {
                Id = "beer1"
            };

            var bucket = new Mock<IBucket>();
            bucket.Setup(x => x.Insert(It.IsAny<Document<Beer>>()))
                .Returns(() => new FakeDocumentResult<Beer>
                {
                    Status = ResponseStatus.Success,
                    Success = true
                });

            var dao = new DataAccessObject<Beer>(bucket.Object);
            dao.Insert(beer);
            bucket.VerifyAll();
        }
        public void When_Select_Is_Called_And_Document_Does_Not_Exist_DocumentNotFoundException_Is_Thrown()
        {
            var beer = new Beer
            {
                Id = "beer1",
                Name = "Bud"
            };
            var bucket = new Mock<IBucket>();
            bucket.Setup(x => x.GetDocument<Beer>(It.IsAny<string>()))
                .Returns(() => new FakeDocumentResult<Beer>
                {
                    Status = ResponseStatus.KeyNotFound,
                    Success = false,
                    Content = beer
                });

            var dao = new DataAccessObject<Beer>(bucket.Object);
            Assert.Throws<DocumentNotFoundException>(() => dao.Select("the_key"));
            bucket.VerifyAll();
        }
        public void When_Select_Is_Called_And_Document_Exists_It_is_Returned()
        {
            var beer = new Beer
            {
                Id = "beer1",
                Name = "Bud"
            };
            var bucket = new Mock<IBucket>();
            bucket.Setup(x => x.GetDocument<Beer>(It.IsAny<string>()))
                .Returns(() => new FakeDocumentResult<Beer>
                {
                    Status = ResponseStatus.Success,
                    Success = true,
                    Content = beer
                });

            var dao = new DataAccessObject<Beer>(bucket.Object);
            var result = dao.Select("the_key");
            Assert.AreEqual(beer.Name, result.Name);
            bucket.VerifyAll();
        }
        public void When_Update_Called_And_Document_Is_Too_Big_CouchbaseDataException_Is_Thrown()
        {
            var beer = new Beer
            {
                Id = "beer1"
            };

            var bucket = new Mock<IBucket>();
            bucket.Setup(x => x.Replace(It.IsAny<Document<Beer>>()))
                .Returns(() => new FakeDocumentResult<Beer>
                {
                    Status = ResponseStatus.ValueTooLarge,
                    Success = false
                });

            var dao = new DataAccessObject<Beer>(bucket.Object);
            Assert.Throws<CouchbaseDataException>(() => dao.Update(beer));
            bucket.VerifyAll();
        }
        public void When_Update_Called_And_Document_Does_Not_Exist_DocumentNotFoundException_Is_Thrown()
        {
            var beer = new Beer
            {
                Id = "beer1"
            };

            var bucket = new Mock<IBucket>();
            bucket.Setup(x => x.Replace(It.IsAny<Document<Beer>>()))
                .Returns(() => new FakeDocumentResult<Beer>
                {
                    Status = ResponseStatus.KeyNotFound,
                    Success = false
                });

            var dao = new DataAccessObject<Beer>(bucket.Object);
            Assert.Throws<DocumentNotFoundException>(() => dao.Update(beer));
            bucket.VerifyAll();
        }