示例#1
0
        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, false)).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 ReadResourceSet_ThrowsArgumentNull_ResourceSet()
        {
            // Arrange & Act & Assert
            var deserializer = new ODataResourceSetDeserializer(_deserializerProvider);

            ExceptionAssert.ThrowsArgumentNull(() => deserializer.ReadResourceSet(null, null, null).GetEnumerator().MoveNext(), "resourceSet");
        }
示例#3
0
        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, false)).Returns <ODataEdmTypeDeserializer>(null);

            ExceptionAssert.Throws <SerializationException>(
                () => deserializer.ReadResourceSet(feedWrapper, _customerType, readContext).GetEnumerator().MoveNext(),
                "'Microsoft.AspNetCore.OData.Tests.Models.Customer' cannot be deserialized using the OData input formatter.");
        }