public void UploadSomethingAsyncAwait_ValidRequest_UploadsMyAwesomeDataCorrectly()
        {
            var operation = "UploadSomething";
            var expectedRequest = new TestableWebRequest(new Uri(BaseUri, operation));
            expectedRequest.EnqueueResponse(HttpStatusCode.OK, "Success", "Even More Success", false);
            TestableWebRequestCreateFactory.GetFactory().AddRequest(expectedRequest);
            var service = new SampleService(BaseUri);

            var response = service.UploadSomethingAsyncAwait(operation, System.Text.Encoding.UTF8.GetBytes("My awesome data payload!"));

            var uploadedData = ((TestableWebRequest)expectedRequest).GetContent();
            Assert.AreEqual("My awesome data payload!", System.Text.Encoding.UTF8.GetString(uploadedData));
        }
        public void UploadSomethingAsyncAwait_ValidRequest_ReturnsSuccessfulResponse()
        {
            var operation = "UploadSomething";
            var expectedRequest = new TestableWebRequest(new Uri(BaseUri, operation));
            expectedRequest.EnqueueResponse(HttpStatusCode.OK, "Success", "Even More Success", false);
            TestableWebRequestCreateFactory.GetFactory().AddRequest(expectedRequest);
            var service = new SampleService(BaseUri);

            var response = service.UploadSomethingAsyncAwait(operation, System.Text.Encoding.UTF8.GetBytes("My awesome data payload!"));

            Assert.IsTrue(response.IsSuccess);
        }
        public void UploadSomethingAsyncAwait_ValidRequest_SetsVersionHeader()
        {
            var operation = "UploadSomething";
            var expectedRequest = new TestableWebRequest(new Uri(BaseUri, operation));
            expectedRequest.EnqueueResponse(HttpStatusCode.OK, "Success", "Even More Success", false);
            TestableWebRequestCreateFactory.GetFactory().AddRequest(expectedRequest);
            var service = new SampleService(BaseUri);

            var response = service.UploadSomethingAsyncAwait(operation, System.Text.Encoding.UTF8.GetBytes("My awesome data payload!"));

            Assert.AreEqual("123-awesome", expectedRequest.Headers["version"]);
        }
        public void UploadSomethingAsyncAwait_TimeoutOccurs_ThrowsRawTimeoutException()
        {
            var operation = "UploadSomething";
            var expectedRequest = new TestableWebRequest(new Uri(BaseUri, operation));
            expectedRequest.EnqueueResponse(new TimeoutException("took too long, so sorry"))
                           .EnqueueResponse(HttpStatusCode.OK, "All Good", "Nothing to see, please move along", false);
            TestableWebRequestCreateFactory.GetFactory().AddRequest(expectedRequest);
            var service = new SampleService(BaseUri);

            var response = service.UploadSomethingAsyncAwait(operation, System.Text.Encoding.UTF8.GetBytes("My awesome data payload!"));

            Assert.AreEqual("Nothing to see, please move along", response.Message);
        }
        public void UploadSomethingAsyncAwait_ServiceOutage_ThrowsSampleServiceOutage()
        {
            var operation = "UploadSomething";
            var expectedRequest = new TestableWebRequest(new Uri(BaseUri, operation));
            expectedRequest.EnqueueResponse(new WebException("I'm broke!", WebExceptionStatus.ConnectFailure));
            TestableWebRequestCreateFactory.GetFactory().AddRequest(expectedRequest);
            var service = new SampleService(BaseUri);

            var response = service.UploadSomethingAsyncAwait(operation, System.Text.Encoding.UTF8.GetBytes("My awesome data payload!"));

            // expect exception
        }
        public void UploadSomethingAsyncAwait_404SomeOtherObjectNotFound_ThrowsGenericNotFoundException()
        {
            var operation = "UploadSomething";
            var expectedRequest = new TestableWebRequest(new Uri(BaseUri, operation));
            expectedRequest.EnqueueResponse(HttpStatusCode.NotFound, "OtherObjectType not found", "I couldn't find yuor other object because the name was unimaginative", true);
            TestableWebRequestCreateFactory.GetFactory().AddRequest(expectedRequest);
            var service = new SampleService(BaseUri);

            var response = service.UploadSomethingAsyncAwait(operation, System.Text.Encoding.UTF8.GetBytes("My awesome data payload!"));

            // expect exception
        }
        public void UploadSomethingAsyncAwait_404DohickeyNotFound_ThrowsDohickeyNotFoundException()
        {
            var operation = "UploadSomething";
            var expectedRequest = new TestableWebRequest(new Uri(BaseUri, operation));
            expectedRequest.EnqueueResponse(HttpStatusCode.NotFound, "Dohicky not found", "I couldn't find your dohicky because I don't like you", true);
            TestableWebRequestCreateFactory.GetFactory().AddRequest(expectedRequest);
            var service = new SampleService(BaseUri);

            var response = service.UploadSomethingAsyncAwait(operation, System.Text.Encoding.UTF8.GetBytes("My awesome data payload!"));

            // expect exception
        }
        public void UploadSomethingAsyncAwait_403NoneShallPass_ThrowsExampleOfAnotherUsefulException()
        {
            var operation = "UploadSomething";
            var expectedRequest = new TestableWebRequest(new Uri(BaseUri, operation));
            expectedRequest.EnqueueResponse(HttpStatusCode.Forbidden, "None shall pass", "Somethign else amusing", true);
            TestableWebRequestCreateFactory.GetFactory().AddRequest(expectedRequest);
            var service = new SampleService(BaseUri);

            var response = service.UploadSomethingAsyncAwait(operation, System.Text.Encoding.UTF8.GetBytes("My awesome data payload!"));

            // expect exception
        }