public void CreateODataCollectionValue_CanSerialize_IEdmObjects() { // Arrange Mock <IEdmComplexObject> edmComplexObject = new Mock <IEdmComplexObject>(); IEdmComplexObject[] collection = new IEdmComplexObject[] { edmComplexObject.Object }; ODataSerializerContext serializerContext = new ODataSerializerContext(); IEdmComplexTypeReference elementType = new EdmComplexTypeReference(new EdmComplexType("NS", "ComplexType"), isNullable: true); edmComplexObject.Setup(s => s.GetEdmType()).Returns(elementType); IEdmCollectionTypeReference collectionType = new EdmCollectionTypeReference(new EdmCollectionType(elementType)); Mock <ODataSerializerProvider> serializerProvider = new Mock <ODataSerializerProvider>(); Mock <ODataComplexTypeSerializer> elementSerializer = new Mock <ODataComplexTypeSerializer>(MockBehavior.Strict, serializerProvider.Object); serializerProvider.Setup(s => s.GetEdmTypeSerializer(elementType)).Returns(elementSerializer.Object); elementSerializer.Setup(s => s.CreateODataComplexValue(collection[0], elementType, serializerContext)).Returns(new ODataComplexValue()).Verifiable(); ODataCollectionSerializer serializer = new ODataCollectionSerializer(serializerProvider.Object); // Act var result = serializer.CreateODataCollectionValue(collection, elementType, serializerContext); // Assert elementSerializer.Verify(); }
public void CreateODataCollectionValue_ThrowsSerializationException_TypeCannotBeSerialized() { IEnumerable enumerable = new[] { 0 }; Mock <ODataSerializerProvider> serializerProvider = new Mock <ODataSerializerProvider>(); var serializer = new ODataCollectionSerializer(serializerProvider.Object); serializerProvider.Setup(s => s.GetEdmTypeSerializer(It.IsAny <IEdmTypeReference>())).Returns <IEdmTypeReference>(null); Assert.Throws <SerializationException>( () => serializer.CreateODataCollectionValue(enumerable, _edmIntType, new ODataSerializerContext()), "'Edm.Int32' cannot be serialized using the ODataMediaTypeFormatter."); }
public void CreateODataCollectionValue_ThrowsArgumentNull_WriteContext() { Assert.ThrowsArgumentNull( () => _serializer.CreateODataCollectionValue(enumerable: null, elementType: _edmIntType, writeContext: null), "writeContext"); }
public void CreateODataCollectionValue_CanSerialize_IEdmObjects() { // Arrange Mock<IEdmComplexObject> edmComplexObject = new Mock<IEdmComplexObject>(); IEdmComplexObject[] collection = new IEdmComplexObject[] { edmComplexObject.Object }; ODataSerializerContext serializerContext = new ODataSerializerContext(); IEdmComplexTypeReference elementType = new EdmComplexTypeReference(new EdmComplexType("NS", "ComplexType"), isNullable: true); edmComplexObject.Setup(s => s.GetEdmType()).Returns(elementType); IEdmCollectionTypeReference collectionType = new EdmCollectionTypeReference(new EdmCollectionType(elementType)); Mock<ODataSerializerProvider> serializerProvider = new Mock<ODataSerializerProvider>(); Mock<ODataComplexTypeSerializer> elementSerializer = new Mock<ODataComplexTypeSerializer>(MockBehavior.Strict, serializerProvider.Object); serializerProvider.Setup(s => s.GetEdmTypeSerializer(elementType)).Returns(elementSerializer.Object); elementSerializer.Setup(s => s.CreateODataComplexValue(collection[0], elementType, serializerContext)).Returns(new ODataComplexValue()).Verifiable(); ODataCollectionSerializer serializer = new ODataCollectionSerializer(serializerProvider.Object); // Act var result = serializer.CreateODataCollectionValue(collection, elementType, serializerContext); // Assert elementSerializer.Verify(); }
public void CreateODataCollectionValue_ThrowsSerializationException_TypeCannotBeSerialized() { IEnumerable enumerable = new[] { 0 }; Mock<ODataSerializerProvider> serializerProvider = new Mock<ODataSerializerProvider>(); var serializer = new ODataCollectionSerializer(serializerProvider.Object); serializerProvider.Setup(s => s.GetEdmTypeSerializer(It.IsAny<IEdmTypeReference>())).Returns<IEdmTypeReference>(null); Assert.Throws<SerializationException>( () => serializer.CreateODataCollectionValue(enumerable, _edmIntType, new ODataSerializerContext { Model = _model }), "'Edm.Int32' cannot be serialized using the ODataMediaTypeFormatter."); }