diff --git a/ServiceSamples/ServiceTests/JsonTests.cs b/ServiceSamples/ServiceTests/JsonTests.cs index 5f77b7a..b85c371 100644 --- a/ServiceSamples/ServiceTests/JsonTests.cs +++ b/ServiceSamples/ServiceTests/JsonTests.cs @@ -1,5 +1,8 @@ using AuthenticationUtility; using Microsoft.VisualStudio.TestTools.UnitTesting; +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; +using SoapUtility.UserSessionServiceReference; using System; using System.IO; using System.Net; @@ -10,6 +13,7 @@ namespace ServiceTests public class JsonXppAuthTests { public string GetUserSessionOperationPath = ClientConfiguration.Default.UriString + "api/services/UserSessionService/AifUserSessionService/GetUserSessionInfo"; + public string ApplyTimeZoneOperationPath = ClientConfiguration.Default.UriString + "api/services/UserSessionService/AifUserSessionService/ApplyTimeZone"; [TestMethod] @@ -34,4 +38,88 @@ namespace ServiceTests } } } - }} + + [TestMethod] + public void JsonSoapContractTest() + { + var request = HttpWebRequest.Create(ApplyTimeZoneOperationPath); + request.Headers[OAuthHelper.OAuthHeader] = OAuthHelper.GetAuthenticationHeader(); + request.Method = "POST"; + + DateTime inputDateTime = DateTime.Now; + var requestContract = new ApplyTimeZone(); + requestContract.dateTime = inputDateTime; + requestContract.timeZoneOffset = 3; + 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(); + DateTime appliedTimeZone = JsonConvert.DeserializeObject(responseString); + + Assert.AreEqual(HttpStatusCode.OK, response.StatusCode); + Assert.IsFalse(string.IsNullOrEmpty(responseString)); + Console.WriteLine(responseString); + Assert.IsNotNull(appliedTimeZone); + Assert.AreNotEqual(appliedTimeZone.Hour, inputDateTime.Hour); + } + } + } + } + + [TestMethod] + public void JsonWeaklyTypedContractTest() + { + var request = HttpWebRequest.Create(ApplyTimeZoneOperationPath); + request.Headers[OAuthHelper.OAuthHeader] = OAuthHelper.GetAuthenticationHeader(); + request.Method = "POST"; + + DateTime inputDateTime = DateTime.Now; + var requestContract = new + { + dateTime = inputDateTime, + timeZoneOffset = 3 + }; + 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(); + JToken jsonObject = JToken.Parse(responseString); + DateTime appliedTimeZone = jsonObject.Value(); + + Assert.AreEqual(HttpStatusCode.OK, response.StatusCode); + Assert.IsFalse(string.IsNullOrEmpty(responseString)); + Console.WriteLine(responseString); + Assert.IsNotNull(appliedTimeZone); + Assert.AreNotEqual(appliedTimeZone.Hour, inputDateTime.Hour); + } + } + } + } + } +} diff --git a/ServiceSamples/ServiceTests/ServiceTests.csproj b/ServiceSamples/ServiceTests/ServiceTests.csproj index a84d3db..1421899 100644 --- a/ServiceSamples/ServiceTests/ServiceTests.csproj +++ b/ServiceSamples/ServiceTests/ServiceTests.csproj @@ -36,6 +36,10 @@ 4 + + ..\packages\Newtonsoft.Json.7.0.1\lib\net45\Newtonsoft.Json.dll + True + @@ -70,6 +74,9 @@ False + + +