public void ListRemoteStuffAsyncAwait_403NoneShallPass_ThrowsExampleOfAnotherUsefulException()
        {
            var operation = "ListOfStuff";
            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.ListRemoteStuffAsyncAwait(operation);

            // expect exception
        }
        public void ListRemoteStuffAsyncAwait_404DohickeyNotFound_ThrowsDohickeyNotFoundException()
        {
            var operation = "ListOfStuff";
            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.ListRemoteStuffAsyncAwait(operation);

            // expect exception
        }
        public void ListRemoteStuffAsyncAwait_404SomeOtherObjectNotFound_ThrowsGenericNotFoundException()
        {
            var operation = "ListOfStuff";
            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.ListRemoteStuffAsyncAwait(operation);

            // expect exception
        }
        public void ListRemoteStuffAsyncAwait_ValidRequest_SetsVersionHeader()
        {
            var operation = "ListOfStuff";
            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.ListRemoteStuffAsyncAwait(operation);

            Assert.AreEqual("123-awesome", expectedRequest.Headers["version"]);
        }
        public void ListRemoteStuffAsyncAwait_ValidRequest_ReturnsSuccessfulResponse()
        {
            var operation = "ListOfStuff";
            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.ListRemoteStuffAsyncAwait(operation);

            Assert.IsTrue(response.IsSuccess);
        }
        public void ListRemoteStuffAsyncAwait_TimeoutOccurs_TruesASecondTime()
        {
            var operation = "ListOfStuff";
            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.ListRemoteStuffAsyncAwait(operation);

            Assert.AreEqual("Nothing to see, please move along", response.Message);
        }
        public void ListRemoteStuffAsyncAwait_SixTimeoutsOccur_FinallyThrowsTheException()
        {
            var operation = "ListOfStuff";
            var expectedRequest = new TestableWebRequest(new Uri(BaseUri, operation));
            expectedRequest.EnqueueResponse(new TimeoutException("took too long, so sorry"))
                           .EnqueueResponse(new TimeoutException("took too long, so sorry"))
                           .EnqueueResponse(new TimeoutException("took too long, so sorry"))
                           .EnqueueResponse(new TimeoutException("took too long, so sorry"))
                           .EnqueueResponse(new TimeoutException("took too long, so sorry"))
                           .EnqueueResponse(new TimeoutException("took too long, so sorry"));
            TestableWebRequestCreateFactory.GetFactory().AddRequest(expectedRequest);
            var service = new SampleService(BaseUri);

            var response = service.ListRemoteStuffAsyncAwait(operation);

            // expect exception
        }
        public void ListRemoteStuffAsyncAwait_ServiceOutage_ThrowsSampleServiceOutage()
        {
            var operation = "ListOfStuff";
            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.ListRemoteStuffAsyncAwait(operation);

            // expect exception
        }