Пример #1
0
        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 <DateTime>(responseString);

                        Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
                        Assert.IsFalse(string.IsNullOrEmpty(responseString));
                        Console.WriteLine(responseString);
                        Assert.IsNotNull(appliedTimeZone);
                        Assert.AreNotEqual(appliedTimeZone.Hour, inputDateTime.Hour);
                    }
                }
            }
        }
Пример #2
0
        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<DateTime>(responseString);

                        Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
                        Assert.IsFalse(string.IsNullOrEmpty(responseString));
                        Console.WriteLine(responseString);
                        Assert.IsNotNull(appliedTimeZone);
                        Assert.AreNotEqual(appliedTimeZone.Hour, inputDateTime.Hour);
                    }
                }
            }
        }