private void SubtestCreateRequest_SupportedMethod(string method)
 {
     using (var service = new MockClientService("https://build_request_params"))
     {
         var request     = new TestClientServiceRequest(service, method, null);
         var httpRequest = request.CreateRequest();
     }
 }
 public void CreateRequest_UnsupportedMethods()
 {
     using (var service = new MockClientService("https://build_request_params"))
     {
         var request = new TestClientServiceRequest(service, "Unsupported", null);
         Assert.Throws <ArgumentOutOfRangeException>(() => request.CreateRequest());
     }
 }
        public void CreateRequest_ETag()
        {
            var body = new MockRequest {
                Name = "long long name"
            };

            using (var service = new MockClientService())
            {
                // no ETag (ETag = null)
                var request     = new TestClientServiceRequest(service, HttpConsts.Get, body);
                var httpRequest = request.CreateRequest();
                Assert.That(httpRequest.Headers.IfMatch.Count, Is.EqualTo(0));
                Assert.That(httpRequest.Headers.IfNoneMatch.Count, Is.EqualTo(0));

                // ETag has a value, but ETag action is ignored
                body.ETag          = "\"ETAG_HERE\"";
                request            = new TestClientServiceRequest(service, HttpConsts.Get, body);
                request.ETagAction = ETagAction.Ignore;
                httpRequest        = request.CreateRequest();
                Assert.That(httpRequest.Headers.IfMatch.Count, Is.EqualTo(0));
                Assert.That(httpRequest.Headers.IfNoneMatch.Count, Is.EqualTo(0));

                // ETag has a value, so use default action (Get -> If-None-Match)
                request     = new TestClientServiceRequest(service, HttpConsts.Get, body);
                httpRequest = request.CreateRequest();
                Assert.That(httpRequest.Headers.IfMatch.Count, Is.EqualTo(0));
                Assert.That(httpRequest.Headers.IfNoneMatch.Count, Is.EqualTo(1));
                Assert.That(httpRequest.Headers.IfNoneMatch.First(), Is.EqualTo(new EntityTagHeaderValue(body.ETag)));

                // ETag has a value, so use default action (Post -> If-Match)
                request     = new TestClientServiceRequest(service, HttpConsts.Post, body);
                httpRequest = request.CreateRequest();
                Assert.That(httpRequest.Headers.IfNoneMatch.Count, Is.EqualTo(0));
                Assert.That(httpRequest.Headers.IfMatch.Count, Is.EqualTo(1));
                Assert.That(httpRequest.Headers.IfMatch.First(), Is.EqualTo(new EntityTagHeaderValue(body.ETag)));

                // ETag has a value, default is override, use the specified ETag action
                request            = new TestClientServiceRequest(service, HttpConsts.Post, body);
                request.ETagAction = ETagAction.IfNoneMatch;
                httpRequest        = request.CreateRequest();
                Assert.That(httpRequest.Headers.IfMatch.Count, Is.EqualTo(0));
                Assert.That(httpRequest.Headers.IfNoneMatch.Count, Is.EqualTo(1));
                Assert.That(httpRequest.Headers.IfNoneMatch.First(), Is.EqualTo(new EntityTagHeaderValue(body.ETag)));

                // ETag has a value, default is override, use the specified ETag action
                request            = new TestClientServiceRequest(service, HttpConsts.Get, body);
                request.ETagAction = ETagAction.IfMatch;
                httpRequest        = request.CreateRequest();
                Assert.That(httpRequest.Headers.IfNoneMatch.Count, Is.EqualTo(0));
                Assert.That(httpRequest.Headers.IfMatch.Count, Is.EqualTo(1));
                Assert.That(httpRequest.Headers.IfMatch.First(), Is.EqualTo(new EntityTagHeaderValue(body.ETag)));
            }
        }
        public void CreateRequest_DeveloperKey_RequiresEscape()
        {
            var initializer = new BaseClientService.Initializer
            {
                ApiKey = ComplexDeveloperKey
            };

            using (var service = new MockClientService(initializer, "https://build_request_params"))
            {
                var request     = new TestClientServiceRequest(service, "GET", null);
                var httpRequest = request.CreateRequest();
                Assert.That(httpRequest.RequestUri, Is.EqualTo(new Uri(
                                                                   "https://build_request_params/restPath0?key=%3F%26%5E%25%20%20ABC123")));
            }
        }
        public void CreateRequest_DeveloperKey()
        {
            var initializer = new BaseClientService.Initializer
            {
                ApiKey = SimpleDeveloperKey
            };

            using (var service = new MockClientService(initializer, "https://build_request_params"))
            {
                var request     = new TestClientServiceRequest(service, "GET", null);
                var httpRequest = request.CreateRequest();
                Assert.That(httpRequest.RequestUri, Is.EqualTo(new Uri(
                                                                   "https://build_request_params/restPath0?key=" + SimpleDeveloperKey)));
            }
        }