public void executer_get_should_be_throw_exception()
        {
            byte[] buffer = Encoding.UTF8.GetBytes("{ IsSuccess : true }");

            var mockHttpWebRequest = new Mock <HttpWebRequest>();

            mockHttpWebRequest.Setup(x => x.GetResponse())
            .Throws(new Exception("bar"));

            IExecuter executer = new Executer(mockHttpWebRequest.Object, new JsonResponseHandler());

            var result = executer.Get <TestObject>();

            bool actual = result.ErrorMessage == "bar";

            Assert.IsTrue(actual);
        }
        public void executer_get_should_be_response_issuccess_true()
        {
            byte[] buffer = Encoding.UTF8.GetBytes("{ IsSuccess : true }");

            var mockHttpWebRequest  = new Mock <HttpWebRequest>();
            var mockHttpWebResponse = new Mock <HttpWebResponse>();

            mockHttpWebResponse.Setup(x => x.GetResponseStream()).Returns(new MemoryStream(buffer));

            mockHttpWebRequest.Setup(x => x.GetResponse()).Returns(mockHttpWebResponse.Object);

            IExecuter executer = new Executer(mockHttpWebRequest.Object, new JsonResponseHandler());

            var result = executer.Get <TestObject>();

            Assert.IsTrue(result.Data.IsSuccess);
        }
        public void executer_get_should_be_throw_webexception()
        {
            byte[] buffer = Encoding.UTF8.GetBytes("{ IsSuccess : true }");

            byte[] exBuffer            = Encoding.UTF8.GetBytes("{ Message : \"Test Error\" }");
            var    mockHttpWebRequest  = new Mock <HttpWebRequest>();
            var    mockHttpWebResponse = new Mock <HttpWebResponse>();

            mockHttpWebResponse.Setup(x => x.StatusCode).Returns(HttpStatusCode.Unauthorized);
            mockHttpWebResponse.Setup(x => x.GetResponseStream()).Returns(new MemoryStream(exBuffer));

            mockHttpWebRequest.Setup(x => x.GetResponse())
            .Throws(new WebException("foo", null, WebExceptionStatus.ConnectFailure, mockHttpWebResponse.Object));

            IExecuter executer = new Executer(mockHttpWebRequest.Object, new JsonResponseHandler());

            var result = executer.Get <TestObject>();

            bool actual = result.Status == HttpStatusCode.Unauthorized && result.ErrorMessage == "Test Error";

            Assert.IsTrue(actual);
        }