コード例 #1
0
        public void SendNewSessionRequestReturnsAnUnknownErrorResponseForWrongHttpResponse()
        {
            // given
            HTTPClient target = spyClient;

            spyClient.WhenForAnyArgs(x => x.DoGetRequest(string.Empty, string.Empty)).DoNotCallBase();

            // when
            spyClient.DoGetRequest(string.Empty, string.Empty).ReturnsForAnyArgs(InvalidStatusResponseShort);
            var obtained = target.SendNewSessionRequest();

            // then
            Assert.That(obtained, Is.Not.Null);
            Assert.That(obtained.ResponseCode, Is.EqualTo(int.MaxValue));
            Assert.That(obtained.Headers, Is.Empty);

            // and when
            spyClient.DoGetRequest(string.Empty, string.Empty).ReturnsForAnyArgs(InvalidStatusResponseLong);
            obtained = target.SendNewSessionRequest();

            // then
            Assert.That(obtained, Is.Not.Null);
            Assert.That(obtained.ResponseCode, Is.EqualTo(int.MaxValue));
            Assert.That(obtained.Headers, Is.Empty);

            spyClient.ReceivedWithAnyArgs(2).DoGetRequest(string.Empty, string.Empty);
        }
コード例 #2
0
        public void SendNewSessionRequestReturnsErrorCode()
        {
            // given
            var headers = new Dictionary <string, List <string> >
            {
                { "Content-Length", new List <string> {
                      "42"
                  } },
                { "Content-Type", new List <string> {
                      "application/json"
                  } }
            };
            HTTPClient target = spyClient;

            spyClient.WhenForAnyArgs(x => x.DoGetRequest(string.Empty, string.Empty)).DoNotCallBase();
            spyClient.DoGetRequest(string.Empty, string.Empty).ReturnsForAnyArgs(new HTTPClient.HTTPResponse {
                ResponseCode = 400, Headers = headers, Response = null
            });

            // when
            var obtained = target.SendNewSessionRequest();

            // then
            Assert.That(obtained, Is.Not.Null);
            Assert.That(obtained.ResponseCode, Is.EqualTo(400));
            Assert.That(obtained.Headers, Is.EqualTo(headers));

            spyClient.ReceivedWithAnyArgs(1).DoGetRequest(string.Empty, string.Empty);
        }
コード例 #3
0
        public void SendNewSessionRequestIsRetriedThreeTimesBeforeGivingUp()
        {
            // given
            HTTPClient target = spyClient;

            spyClient.WhenForAnyArgs(x => x.DoGetRequest(string.Empty, string.Empty)).DoNotCallBase();
            spyClient.WhenForAnyArgs(x => x.DoGetRequest(string.Empty, string.Empty)).Do(x => throw new Exception("dummy"));

            // when
            var obtained = target.SendNewSessionRequest();

            // then
            Assert.That(obtained, Is.Not.Null);
            Assert.That(obtained.ResponseCode, Is.EqualTo(int.MaxValue));
            Assert.That(obtained.Headers, Is.Empty);

            spyClient.ReceivedWithAnyArgs(3).DoGetRequest(string.Empty, string.Empty);
        }
コード例 #4
0
        public void SendNewSessionRequestSendRequestToMonitorURL()
        {
            // given
            HTTPClient target = spyClient;

            spyClient.WhenForAnyArgs(x => x.DoGetRequest(string.Empty, string.Empty)).DoNotCallBase();
            spyClient.DoGetRequest(string.Empty, string.Empty).ReturnsForAnyArgs(StatusResponse);


            // when
            var obtained = target.SendNewSessionRequest();

            // then
            Assert.That(obtained, Is.Not.Null);
            Assert.That(obtained.ResponseCode, Is.EqualTo(200));

            spyClient.Received(1).DoGetRequest(MonitorURL, null);
        }
コード例 #5
0
        public void SendNewSessionRequestReturnsAnUnknownErrorResponseForUnparseableStatusResponse()
        {
            // given
            HTTPClient target = spyClient;

            spyClient.WhenForAnyArgs(x => x.DoGetRequest(string.Empty, string.Empty)).DoNotCallBase();
            spyClient.DoGetRequest(string.Empty, string.Empty).ReturnsForAnyArgs(
                new HTTPClient.HTTPResponse {
                ResponseCode = 200, Headers = new Dictionary <string, List <string> >(), Response = StatusResponse.Response + "&cp=a"
            });

            // when
            var obtained = target.SendNewSessionRequest();

            // then
            Assert.That(obtained, Is.Not.Null);
            Assert.That(obtained.ResponseCode, Is.EqualTo(int.MaxValue));
            Assert.That(obtained.Headers, Is.Empty);

            spyClient.ReceivedWithAnyArgs(1).DoGetRequest(string.Empty, string.Empty);
        }