Example #1
0
        public void CustomVerb_Works()
        {
            var        hh  = new MockHttpHelper("dummyuri");
            HttpHelper sut = hh;

            _ = sut.Execute("p", exVerb: new HttpMethod("customMethodThatDoesNotExist"));
            Assert.Equal("customMethodThatDoesNotExist", hh.LastUsedVerb);
        }
Example #2
0
        public void Verb_DefaultIs_Get()
        {
            var        hh  = new MockHttpHelper("dummyuri");
            HttpHelper sut = hh;

            _ = sut.Execute("p");

            Assert.Equal("GET", hh.LastUsedVerb);
        }
Example #3
0
        public void Verb_ExecuteSet_Arrives()
        {
            var        hh  = new MockHttpHelper("dummyuri");
            HttpHelper sut = hh;

            _ = sut.Execute("p", exVerb: HttpMethod.Delete);

            Assert.Equal("DELETE", hh.LastUsedVerb);
        }
Example #4
0
        public void GetUri_ReturnsUri(string baseval, string stem, string qparam, string expected)
        {
            var        hh  = new MockHttpHelper("dummyuri");
            HttpHelper sut = hh;

            var result = sut.GetUri(baseval, stem, qparam);

            Assert.Equal(expected, result);
        }
Example #5
0
        public async Task Body_IsPresent()
        {
            var        hh  = new MockHttpHelper("dummyuri");
            HttpHelper sut = hh;
            await sut.Execute("qparam", "body");

            var s = hh.GetBodyValue();

            Assert.Equal("body", s);
        }
Example #6
0
        public async void HttpSucces_ReturnsSuccess()
        {
            var hh = new MockHttpHelper("dummy");

            hh.SetResponse(HttpStatusCode.OK);

            var f = await hh.Execute("");

            Assert.True(f.Success);
            Assert.True(f.Status == HttpStatusCode.OK);
        }
Example #7
0
        public async Task Retry_404_DoesNotRetry()
        {
            var        hh  = new MockHttpHelper("dummyuri");
            HttpHelper sut = hh;

            hh.SetResponse(HttpStatusCode.NotFound);
            sut.RetryCount = 5;
            await sut.Execute(null);

            Assert.Equal(1, hh.CallsMade);
        }
Example #8
0
        public void Header_IsPresent()
        {
            var        hh  = new MockHttpHelper("dummyuri");
            HttpHelper sut = hh;

            sut.AddHeader("name", "value");

            var s = hh.GetHeaderValue("name");

            Assert.Equal("value", s);
        }
Example #9
0
        public void Verb_PropSet_Persists()
        {
            var        hh  = new MockHttpHelper("dummyuri");
            HttpHelper sut = hh;

            sut.Verb = HttpMethod.Post;

            _ = sut.Execute("p");

            Assert.Equal("POST", hh.LastUsedVerb);
        }
Example #10
0
        public async Task Retry_500_DoesRetry()
        {
            var        hh  = new MockHttpHelper("dummyuri");
            HttpHelper sut = hh;

            hh.SetResponse(HttpStatusCode.InternalServerError);

            sut.RetryCount = 5;
            await sut.Execute(null);

            Assert.Equal(5, hh.CallsMade);
        }
Example #11
0
        public void Auth_Bearer_AddsCreds()
        {
            var        hh  = new MockHttpHelper("dummyuri");
            HttpHelper sut = hh;

            sut.AddBearerAuthHeader("secret");

            var s = hh.GetHeaderValue("Authorization");

            Assert.Contains("Bearer", s);
            Assert.Contains("secret", s);  // cant contain it in plain text.
        }
Example #12
0
        public void Auth_Basic_AddsB64Creds()
        {
            var        hh  = new MockHttpHelper("dummyuri");
            HttpHelper sut = hh;

            sut.AddBasicAuthHeader("secret");

            var s = hh.GetHeaderValue("Authorization");

            Assert.Contains("Basic", s);
            Assert.True(!s.Contains("secret"));  // cant contain it in plain text.
        }
Example #13
0
        public void GetUri_BaseCanNotBeNull()
        {
            var        hh  = new MockHttpHelper("dummyuri");
            HttpHelper sut = hh;

            Assert.Throws <ArgumentNullException>(() => {
                var result = sut.GetUri(null, "dummy", "dummy");
            });

            Assert.Throws <ArgumentOutOfRangeException>(() => {
                var result = sut.GetUri("", "dummy", "dummy");
            });
        }
Example #14
0
        public async void MockHelper_SetResponse_ReturnsResponse()
        {
            var hh = new MockHttpHelper("dummy");

            hh.SetResponse(HttpStatusCode.InternalServerError);

            var wcr = new WebCallRequest {
                // Normally done in the Helper but this test exercises the mock directly.
                Verb = HttpMethod.Get
            };

            var r = await hh.ActualCall_Test(wcr);

            Assert.Equal(HttpStatusCode.InternalServerError, r.Status);
        }
Example #15
0
        public void Verb_ArivesUpperCase()
        {
            var        hh  = new MockHttpHelper("dummyuri");
            HttpHelper sut = hh;

            _ = sut.Execute("p", exVerb: HttpMethod.Post);
            Assert.Equal("POST", hh.LastUsedVerb);

            _ = sut.Execute("p", exVerb: HttpMethod.Get);
            Assert.Equal("GET", hh.LastUsedVerb);

            sut.Verb = HttpMethod.Delete;
            _        = sut.Execute("p");
            Assert.Equal("DELETE", hh.LastUsedVerb);
        }
Example #16
0
        public void MockHelper_StartsZeroCallsMade()
        {
            var hh = new MockHttpHelper("dummy");

            Assert.Equal(0, hh.CallsMade);
        }