Beispiel #1
0
        public void SendTimeSyncRequestReturnsErrorCode()
        {
            // 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.SendTimeSyncRequest();

            // 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);
        }
Beispiel #2
0
        public void SendTimeSyncRequestReturnsAnUnknownErrorResponseForWrongHttpResponse()
        {
            // 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.SendTimeSyncRequest();

            // 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);
        }
Beispiel #3
0
        public void SendTimeSyncRequestIsRetriedThreeTimesBeforeGivingUp()
        {
            // 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.SendTimeSyncRequest();

            // 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);
        }
Beispiel #4
0
        public void SendTimeSyncRequestSendRequestToTimeSyncURL()
        {
            // given
            HTTPClient target = spyClient;

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


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

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

            spyClient.Received(1).DoGetRequest(TimeSyncURL, null);
        }
Beispiel #5
0
        public void SendTimeSyncRequestReturnsAnUnknownErrorResponseForUnparseableStatusResponse()
        {
            // 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 = TimeSyncResponse.Response + "&t1=a"
            });

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

            // 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);
        }