예제 #1
0
        public void Get_customers_using_xml_post()
        {
            var request = new DtoOperations.GetCustomers {
                CustomerIds = new ArrayOfIntId(new[] { base.CustomerId }),
            };
            var xmlRequest = DataContractSerializer.Instance.Parse(request);

            var requestUri = XmlSyncReplyBaseUri + "/" + typeof(DtoOperations.GetCustomers).Name;
            var client     = WebRequest.Create(requestUri);

            client.Method      = "POST";
            client.ContentType = "application/xml";
            using (var writer = new StreamWriter(client.GetRequestStream()))
            {
                writer.Write(xmlRequest);
            }

            var xml      = new StreamReader(client.GetResponse().GetResponseStream()).ReadToEnd();
            var response = DataContractDeserializer.Instance.Parse(xml,
                                                                   typeof(DtoOperations.GetCustomersResponse)) as DtoOperations.GetCustomersResponse;

            Assert.IsNotNull(response);
            Assert.AreEqual(1, response.Customers.Count);
            Assert.AreEqual(CustomerId, response.Customers[0].Id);
        }
        public void Get_customers_using_json_post()
        {
            var request = new DtoOperations.GetCustomers { CustomerIds = new ArrayOfIntId(new[] { base.CustomerId }), };
            var jsonRequest = JsonDataContractSerializer.Instance.Parse(request);

            var requestUri = JsonSyncReplyBaseUri + "/" + typeof(DtoOperations.GetCustomers).Name;
            var client = WebRequest.Create(requestUri);
            client.Method = "POST";
            client.ContentType = "application/json";
            using (var writer = new StreamWriter(client.GetRequestStream()))
            {
                writer.Write(jsonRequest);
            }

            var json = new StreamReader(client.GetResponse().GetResponseStream()).ReadToEnd();
            var response = JsonDataContractDeserializer.Instance.Parse(json,
                typeof(DtoOperations.GetCustomersResponse)) as DtoOperations.GetCustomersResponse;

            Assert.IsNotNull(response);
            Assert.AreEqual(1, response.Customers.Count);
            Assert.AreEqual(CustomerId, response.Customers[0].Id);
        }