示例#1
0
        public void VersionHeaderTest()
        {
            const string versionHeaderValue = "3.2";

            var testHandler = new TestHandler(
                                  (request, cancelation) =>
                                      {
                                          var requestVersionHeader = request.Headers.FirstOrDefault(h => h.Key == VersioningHandler.API_VERSION_HEADER);

                                          Assert.IsNotNull(requestVersionHeader);
                                          Assert.That(requestVersionHeader.Value.FirstOrDefault(), Is.Not.Null.Or.Empty);
                                          Assert.That(requestVersionHeader.Value.FirstOrDefault(), Is.EqualTo(versionHeaderValue));

                                          return Task.FromResult(new HttpResponseMessage(HttpStatusCode.OK));
                                      });

            var handler = new VersioningHandler(versionHeaderValue) { InnerHandler = testHandler };

            var client = new HttpClient(handler);

            // ReSharper disable once MethodSupportsCancellation
            var response = client.GetAsync("http://lodididki");

            Assert.AreEqual(HttpStatusCode.OK, response.Result.StatusCode);
        }
示例#2
0
        public void SetupOnce()
        {
            var logger = Substitute.For<ILog>();
            var credentials = new Credentials("ABC");

            _versionHandler = new VersioningHandler(API_VERSION);
            _authorizationHandlerhandler = new AuthorizationHandler(credentials, logger);
        }