public void ReadFeed_Calls_ReadInlineForEachEntry() { // Arrange Mock <ODataDeserializerProvider> deserializerProvider = new Mock <ODataDeserializerProvider>(); Mock <ODataEdmTypeDeserializer> entityDeserializer = new Mock <ODataEdmTypeDeserializer>(ODataPayloadKind.Resource); ODataResourceSetDeserializer deserializer = new ODataResourceSetDeserializer(deserializerProvider.Object); ODataResourceSetWrapper resourceSetWrapper = new ODataResourceSetWrapper(new ODataResourceSet()); resourceSetWrapper.Resources.Add(new ODataResourceWrapper(new ODataResource { Id = new Uri("http://a1/") })); resourceSetWrapper.Resources.Add(new ODataResourceWrapper(new ODataResource { Id = new Uri("http://a2/") })); ODataDeserializerContext readContext = new ODataDeserializerContext(); deserializerProvider.Setup(p => p.GetEdmTypeDeserializer(_customerType)).Returns(entityDeserializer.Object); entityDeserializer.Setup(d => d.ReadInline(resourceSetWrapper.Resources[0], _customerType, readContext)).Returns("entry1").Verifiable(); entityDeserializer.Setup(d => d.ReadInline(resourceSetWrapper.Resources[1], _customerType, readContext)).Returns("entry2").Verifiable(); // Act var result = deserializer.ReadResourceSet(resourceSetWrapper, _customerType, readContext); // Assert Assert.Equal(new[] { "entry1", "entry2" }, result.OfType <String>()); entityDeserializer.Verify(); }
public void ReadFeed_Throws_TypeCannotBeDeserialized() { Mock <ODataDeserializerProvider> deserializerProvider = new Mock <ODataDeserializerProvider>(); ODataResourceSetDeserializer deserializer = new ODataResourceSetDeserializer(deserializerProvider.Object); ODataResourceSetWrapper feedWrapper = new ODataResourceSetWrapper(new ODataResourceSet()); ODataDeserializerContext readContext = new ODataDeserializerContext(); deserializerProvider.Setup(p => p.GetEdmTypeDeserializer(_customerType)).Returns <ODataEdmTypeDeserializer>(null); Assert.Throws <SerializationException>( () => deserializer.ReadResourceSet(feedWrapper, _customerType, readContext).GetEnumerator().MoveNext(), "'System.Web.OData.TestCommon.Models.Customer' cannot be deserialized using the ODataMediaTypeFormatter."); }