コード例 #1
0
        public IEncoder GetEncoder()
        {
            var jsonWriter = new JsonWriter(new DataWriterSettings(CombinedResolverStrategy()),
                                            new[] {"application/.*json", "text/.*json"});
            var xmlWriter = new XmlWriter(new DataWriterSettings(CombinedResolverStrategy()),
                                          new[] {"application/xml", "text/.*xhtml", "text/xml", "text/html"});

            var urlEncoderWriter = new UrlEncoderWriter(new DataWriterSettings(CombinedResolverStrategy()),
                                                        new[] {"application/x-www-form-urlencoded"});

            var writers = new List<IDataWriter> { jsonWriter, xmlWriter, urlEncoderWriter };

            var dataWriterProvider = new RegExBasedDataWriterProvider(writers);

            return new DefaultEncoder(dataWriterProvider);
        }
コード例 #2
0
        public void XmlAttributes_Are_Not_Converted_To_Elements()
        {
            var customerRaw = @"<Customer Mode=""Add"">
                                <CustomerNo>02121V</CustomerNo>
                            </Customer>";

            var xmlSerializer = new XmlSerializer(typeof (Customer));
            var reader = new StringReader(customerRaw);
            var customer = (Customer)xmlSerializer.Deserialize(reader);

            var writer = new XmlWriter();
            var serialized = writer.Write(customer);

            Assert.NotNull(serialized);
            Assert.That(serialized, Is.StringContaining("Mode=\"Add\""));
        }