Ejemplo n.º 1
0
        public async Task Read_Roundtrip_EnumCollection()
        {
            // Arrange
            Color[] colors = { Color.Blue, Color.Green };

            ODataCollectionSerializer   serializer   = new ODataCollectionSerializer(SerializerProvider);
            ODataCollectionDeserializer deserializer = new ODataCollectionDeserializer(DeserializerProvider);

            MemoryStream               stream   = new MemoryStream();
            ODataMessageWrapper        message  = new ODataMessageWrapper(stream);
            ODataMessageWriterSettings settings = new ODataMessageWriterSettings
            {
                ODataUri = new ODataUri {
                    ServiceRoot = new Uri("http://any/")
                }
            };
            ODataMessageWriter     messageWriter = new ODataMessageWriter(message as IODataResponseMessage, settings, Model);
            ODataMessageReader     messageReader = new ODataMessageReader(message as IODataResponseMessage, new ODataMessageReaderSettings(), Model);
            ODataSerializerContext writeContext  = new ODataSerializerContext {
                RootElementName = "Property", Model = Model
            };
            ODataDeserializerContext readContext = new ODataDeserializerContext()
            {
                Model = Model
            };

            // Act
            await serializer.WriteObjectAsync(colors, colors.GetType(), messageWriter, writeContext);

            stream.Seek(0, SeekOrigin.Begin);
            IEnumerable readAddresses = await deserializer.ReadAsync(messageReader, typeof(Color[]), readContext) as IEnumerable;

            // Assert
            Assert.Equal(colors, readAddresses.Cast <Color>());
        }
Ejemplo n.º 2
0
        public async Task WriteObjectAsync_Throws_ArgumentNull_MessageWriter()
        {
            // Arrange
            ODataSerializerProvider   provider   = new Mock <ODataSerializerProvider>().Object;
            ODataCollectionSerializer serializer = new ODataCollectionSerializer(provider);

            // Act & Assert
            await ExceptionAssert.ThrowsArgumentNullAsync(
                () => serializer.WriteObjectAsync(graph: null, type: typeof(int[]), messageWriter: null, writeContext: null),
                "messageWriter");
        }