public void JsonServiceGroup1EchoComplexContractTest() { EnsureServiceGroup1IsPresent(); var request = HttpWebRequest.Create(ServiceGroup1EchoComplexContractOperationPath); request.Headers[OAuthHelper.OAuthHeader] = OAuthHelper.GetAuthenticationHeader(); request.Method = "POST"; var inputString = "SomeString"; var inputContractList = new Contract1[] { new Contract1 { parmStringMember = inputString } , new Contract1 { parmStringMember = inputString + "*" } }; var requestContract = new ComplexContractRequest { input = new ComplexContract { parmContractList = inputContractList } }; //var requestContractString = JsonConvert.SerializeObject(requestContract); var requestContractString = JsonConvert.SerializeObject(requestContract, new JsonSerializerSettings() { ReferenceLoopHandling = ReferenceLoopHandling.Serialize, PreserveReferencesHandling = PreserveReferencesHandling.Objects }); using (var stream = request.GetRequestStream()) { using (var writer = new StreamWriter(stream)) { writer.Write(requestContractString); } } using (var response = (HttpWebResponse)request.GetResponse()) { using (Stream responseStream = response.GetResponseStream()) { using (StreamReader streamReader = new StreamReader(responseStream)) { string responseString = streamReader.ReadToEnd(); ComplexContract returnedComplex = JsonConvert.DeserializeObject<ComplexContract>(responseString); Assert.AreEqual(HttpStatusCode.OK, response.StatusCode); Assert.IsFalse(string.IsNullOrEmpty(responseString)); Console.WriteLine(responseString); Assert.IsNotNull(returnedComplex); var returnedContractList = returnedComplex.parmContractList; Assert.IsNotNull(returnedContractList); Assert.AreEqual(returnedContractList.Length, inputContractList.Length); Assert.AreEqual(returnedContractList[0].parmStringMember, inputContractList[0].parmStringMember); Assert.AreEqual(returnedContractList[1].parmStringMember, inputContractList[1].parmStringMember); } } } }
public void JsonServiceGroup1EchoContractListTest() { EnsureServiceGroup1IsPresent(); var request = HttpWebRequest.Create(ServiceGroup1EchoContractListOperationPath); request.Headers[OAuthHelper.OAuthHeader] = OAuthHelper.GetAuthenticationHeader(); request.Method = "POST"; var inputString = "SomeString"; var inputContractList = new Contract1[] { new Contract1 { parmStringMember = inputString } , new Contract1 { parmStringMember = inputString + "*" } }; var requestContract = new ContractListRequest { input = inputContractList }; var requestContractString = JsonConvert.SerializeObject(requestContract); using (var stream = request.GetRequestStream()) { using (var writer = new StreamWriter(stream)) { writer.Write(requestContractString); } } using (var response = (HttpWebResponse)request.GetResponse()) { using (Stream responseStream = response.GetResponseStream()) { using (StreamReader streamReader = new StreamReader(responseStream)) { string responseString = streamReader.ReadToEnd(); Contract1[] returnedContractList = JsonConvert.DeserializeObject <Contract1[]>(responseString); Assert.AreEqual(HttpStatusCode.OK, response.StatusCode); Assert.IsFalse(string.IsNullOrEmpty(responseString)); Console.WriteLine(responseString); Assert.IsNotNull(returnedContractList); Assert.AreEqual(returnedContractList.Length, inputContractList.Length); Assert.AreEqual(returnedContractList[0].parmStringMember, inputContractList[0].parmStringMember); Assert.AreEqual(returnedContractList[1].parmStringMember, inputContractList[1].parmStringMember); } } } }