コード例 #1
0
        public void FormatRequest()
        {
            Model model = CreateModel();

            WriteBodyAsXml(model);

            var formatter = new XmlFormatter();
            var resource = formatter.FormatRequest(m_context, typeof(Model)) as Model;

            Assert.That(resource, Is.Not.Null);
            Assert.That(resource.Id, Is.EqualTo(model.Id));
            Assert.That(resource.Name, Is.EqualTo(model.Name));
            Assert.That(resource.Items, Is.Not.Null);
            CollectionAssert.AreEqual(model.Items, resource.Items);
        }
コード例 #2
0
        public void FormatResponseWithPreferredMediaType()
        {
            Model model = CreateModel();

            var formatter = new XmlFormatter();
            var result = formatter.FormatResponse(m_context, typeof(Model), model, "application/xml") as XmlResult;

            Assert.That(result, Is.Not.Null);
            Assert.That(result.Content, Is.SameAs(model));

            result.Execute(m_context);

            string response = ReadResponseAsXml();
            Assert.That(response, Is.Not.Null);

            string serializedModel = SerializeModel(model);
            Assert.That(response, Is.EqualTo(serializedModel));
        }