コード例 #1
0
        public void ListRemoteStuff_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.ListRemoteStuff(operation);

            Assert.AreEqual("123-awesome", expectedRequest.Headers["version"]);
        }
コード例 #2
0
        public void ListRemoteStuff_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.ListRemoteStuff(operation);

            Assert.AreEqual("Nothing to see, please move along", response.Message);
        }
コード例 #3
0
        public void ListRemoteStuff_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.ListRemoteStuff(operation);

            Assert.IsTrue(response.IsSuccess);
        }
コード例 #4
0
        public void ListRemoteStuff_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.ListRemoteStuff(operation);

            // expect exception
        }
コード例 #5
0
        public void ListRemoteStuff_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.ListRemoteStuff(operation);

            // expect exception
        }
コード例 #6
0
        public void ListRemoteStuff_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.ListRemoteStuff(operation);

            // expect exception
        }
コード例 #7
0
        public void ListRemoteStuff_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.ListRemoteStuff(operation);

            // expect exception
        }
コード例 #8
0
        public void ListRemoteStuff_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.ListRemoteStuff(operation);

            // expect exception
        }