public void ReadFeed_Calls_ReadInlineForEachEntry() { // Arrange Mock <ODataDeserializerProvider> deserializerProvider = new Mock <ODataDeserializerProvider>(); Mock <ODataEdmTypeDeserializer> entityDeserializer = new Mock <ODataEdmTypeDeserializer>(_customerType, ODataPayloadKind.Entry); ODataFeedDeserializer deserializer = new ODataFeedDeserializer(_customersType, deserializerProvider.Object); ODataFeedWithEntries feedWrapper = new ODataFeedWithEntries(new ODataFeed()); feedWrapper.Entries.Add(new ODataEntryWithNavigationLinks(new ODataEntry { Id = "1" })); feedWrapper.Entries.Add(new ODataEntryWithNavigationLinks(new ODataEntry { Id = "2" })); ODataDeserializerContext readContext = new ODataDeserializerContext(); deserializerProvider.Setup(p => p.GetEdmTypeDeserializer(_customerType)).Returns(entityDeserializer.Object); entityDeserializer.Setup(d => d.ReadInline(feedWrapper.Entries[0], readContext)).Returns("entry1").Verifiable(); entityDeserializer.Setup(d => d.ReadInline(feedWrapper.Entries[1], readContext)).Returns("entry2").Verifiable(); // Act var result = deserializer.ReadFeed(feedWrapper, readContext); // Assert Assert.Equal(new[] { "entry1", "entry2" }, result.OfType <String>()); entityDeserializer.Verify(); }
/// <summary> /// Initializes a new instance of the <see cref="DefaultODataDeserializerProvider"/> class. /// </summary> public DefaultODataDeserializerProvider() { _actionPayloadDeserializer = new ODataActionPayloadDeserializer(this); _entityDeserializer = new ODataEntityDeserializer(this); _feedDeserializer = new ODataFeedDeserializer(this); _collectionDeserializer = new ODataCollectionDeserializer(this); _complexDeserializer = new ODataComplexTypeDeserializer(this); }
public void ReadInline_Throws_ArgumentMustBeOfType() { var deserializer = new ODataFeedDeserializer(_customersType, new DefaultODataDeserializerProvider()); Assert.ThrowsArgument( () => deserializer.ReadInline(item: 42, readContext: new ODataDeserializerContext()), "item", "The argument must be of type 'ODataFeedWithEntries'."); }
public void ReadFeed_Throws_TypeCannotBeDeserialized() { Mock <ODataDeserializerProvider> deserializerProvider = new Mock <ODataDeserializerProvider>(); ODataFeedDeserializer deserializer = new ODataFeedDeserializer(_customersType, deserializerProvider.Object); ODataFeedWithEntries feedWrapper = new ODataFeedWithEntries(new ODataFeed()); ODataDeserializerContext readContext = new ODataDeserializerContext(); deserializerProvider.Setup(p => p.GetEdmTypeDeserializer(_customerType)).Returns <ODataEdmTypeDeserializer>(null); Assert.Throws <SerializationException>( () => deserializer.ReadFeed(feedWrapper, readContext).GetEnumerator().MoveNext(), "'System.Web.Http.OData.TestCommon.Models.Customer' cannot be deserialized using the ODataMediaTypeFormatter."); }
public void ReadFeed_Throws_TypeCannotBeDeserialized() { Mock<ODataDeserializerProvider> deserializerProvider = new Mock<ODataDeserializerProvider>(); ODataFeedDeserializer deserializer = new ODataFeedDeserializer(deserializerProvider.Object); ODataFeedWithEntries feedWrapper = new ODataFeedWithEntries(new ODataFeed()); ODataDeserializerContext readContext = new ODataDeserializerContext(); deserializerProvider.Setup(p => p.GetEdmTypeDeserializer(_customerType)).Returns<ODataEdmTypeDeserializer>(null); Assert.Throws<SerializationException>( () => deserializer.ReadFeed(feedWrapper, _customerType, readContext).GetEnumerator().MoveNext(), "'System.Web.Http.OData.TestCommon.Models.Customer' cannot be deserialized using the ODataMediaTypeFormatter."); }
public void ReadInline_ReturnsNull_IfItemIsNull() { var deserializer = new ODataFeedDeserializer(_customersType, new DefaultODataDeserializerProvider()); Assert.Null(deserializer.ReadInline(item: null, readContext: new ODataDeserializerContext())); }
public void Ctor_SetsProperty_EntityType() { var deserializer = new ODataFeedDeserializer(_customersType, new DefaultODataDeserializerProvider()); Assert.Equal(_customerType, deserializer.EntityType); }
public void ReadFeed_Calls_ReadInlineForEachEntry() { // Arrange Mock<ODataDeserializerProvider> deserializerProvider = new Mock<ODataDeserializerProvider>(); Mock<ODataEdmTypeDeserializer> entityDeserializer = new Mock<ODataEdmTypeDeserializer>(_customerType, ODataPayloadKind.Entry); ODataFeedDeserializer deserializer = new ODataFeedDeserializer(_customersType, deserializerProvider.Object); ODataFeedWithEntries feedWrapper = new ODataFeedWithEntries(new ODataFeed()); feedWrapper.Entries.Add(new ODataEntryWithNavigationLinks(new ODataEntry { Id = "1" })); feedWrapper.Entries.Add(new ODataEntryWithNavigationLinks(new ODataEntry { Id = "2" })); ODataDeserializerContext readContext = new ODataDeserializerContext(); deserializerProvider.Setup(p => p.GetEdmTypeDeserializer(_customerType)).Returns(entityDeserializer.Object); entityDeserializer.Setup(d => d.ReadInline(feedWrapper.Entries[0], readContext)).Returns("entry1").Verifiable(); entityDeserializer.Setup(d => d.ReadInline(feedWrapper.Entries[1], readContext)).Returns("entry2").Verifiable(); // Act var result = deserializer.ReadFeed(feedWrapper, readContext); // Assert Assert.Equal(new[] { "entry1", "entry2" }, result.OfType<String>()); entityDeserializer.Verify(); }