Пример #1
0
        public VersionedMetadataDocument <TDocument> Read(string id)
        {
            VersionedMetadataText textItem = _innerStore.Read(id);

            if (textItem == null)
            {
                return(null);
            }

            TDocument document = JsonConvert.DeserializeObject <TDocument>(textItem.Text, SerializerSettings);

            return(new VersionedMetadataDocument <TDocument>(textItem.ETag, textItem.Metadata, textItem.Version,
                                                             document));
        }
        private static void AssertEqual(VersionedMetadataText expected, VersionedMetadataText actual)
        {
            if (expected == null)
            {
                Assert.Null(actual);
                return;
            }

            Assert.NotNull(actual);
            Assert.Equal(expected.ETag, actual.ETag);
            Assert.Equal(expected.Metadata, actual.Metadata);
            Assert.Equal(expected.Version, actual.Version);
            Assert.Equal(expected.Text, actual.Text);
        }
        public void Read_ReturnsItem_IfInnerStoreReturnsItem()
        {
            // Arrange
            string expectedId = "Id";
            string expectedETag = "ETag";
            IDictionary<string, string> expectedMetadata = new Dictionary<string, string>();
            DateTimeOffset expectedVersion = DateTimeOffset.Now;
            string expectedText = "Text";

            Mock<IConcurrentMetadataTextStore> innerStoreMock =
                new Mock<IConcurrentMetadataTextStore>(MockBehavior.Strict);
            innerStoreMock.Setup(s => s.Read(expectedId)).Returns(new ConcurrentMetadataText(expectedETag,
                expectedMetadata, expectedText));
            IConcurrentMetadataTextStore innerStore = innerStoreMock.Object;
            IVersionMetadataMapper versionMapper = CreateMapper(expectedMetadata, expectedVersion);

            IVersionedMetadataTextStore product = CreateProductUnderTest(innerStore, versionMapper);

            // Act
            VersionedMetadataText item = product.Read(expectedId);

            // Assert
            VersionedMetadataText expectedItem = new VersionedMetadataText(expectedETag, expectedMetadata,
                expectedVersion, expectedText);
            AssertEqual(expectedItem, item);
        }