public void GetDocumentId_When_Id_Field_DoesNotExist_Throw_KeyAttributeMissingException()
 {
     var route = new Route();
     var bucket = new Mock<IBucket>();
     var ctx = new BucketContext(bucket.Object);
     Assert.Throws<KeyAttributeMissingException>(()=>ctx.GetDocumentId(route));
 }
        public void GetDocumentId_When_Id_Field_DoesNotExist_Throw_KeyAttributeMissingException()
        {
            var route  = new Route();
            var bucket = new Mock <IBucket>();
            var ctx    = new BucketContext(bucket.Object);

            Assert.Throws <KeyAttributeMissingException>(() => ctx.GetDocumentId(route));
        }
 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 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);
        }
예제 #5
0
        public void GetDocumentId_NullKey_ThrowsKeyNullException()
        {
            //arrange
            var document = new Beer {
                Name = null
            };
            var bucket = new Mock <IBucket>();
            var ctx    = new BucketContext(bucket.Object);

            //act
            var ex = Assert.Throws <KeyNullException>(() => ctx.GetDocumentId(document));

            //assert
            Assert.AreEqual(ExceptionMsgs.KeyNull, ex.Message);
        }
예제 #6
0
        public void GetDocumentId_NonString_ConvertsToString()
        {
            //arrange
            var document = new IntegerIdDocument {
                Id = 2
            };
            var bucket = new Mock <IBucket>();
            var ctx    = new BucketContext(bucket.Object);

            //act
            var id = ctx.GetDocumentId(document);

            //assert
            Assert.AreEqual("2", id);
        }
예제 #7
0
        public void GetDocumentId_WhenChangeTrackingEnabled_ProxyUses__idFieldForKey()
        {
            var document = (Beer)DocumentProxyManager.Default.CreateProxy(typeof(Beer));

            ((ITrackedDocumentNode)document).Metadata.Id = "thekey";

            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 key = ctx.GetDocumentId(document);

            Assert.AreEqual("thekey", key);
        }
예제 #8
0
        public void GetDocumentId_DocumentProxyVirtualA_UsesMetadataNotProperty()
        {
            //arrange
            var document = (VirtualKeyA)DocumentProxyManager.Default.CreateProxy(typeof(VirtualKeyA));

            document.A = "Key1";

            // ReSharper disable once SuspiciousTypeConversion.Global
            var trackedDoc = (ITrackedDocumentNode)document;

            trackedDoc.Metadata = new DocumentMetadata()
            {
                Id = "Key2"
            };

            var bucket = new Mock <IBucket>();
            var ctx    = new BucketContext(bucket.Object);

            //act
            var result = ctx.GetDocumentId(document);

            //assert
            Assert.AreEqual("Key2", result);
        }
        public void GetDocumentId_WhenChangeTrackingEnabled_ProxyUses__idFieldForKey()
        {
            var document = (Beer)DocumentProxyManager.Default.CreateProxy(typeof(Beer));

            ((ITrackedDocumentNode) document).Metadata.Id = "thekey";

            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 key = ctx.GetDocumentId(document);

            Assert.AreEqual("thekey", key);
        }