Ejemplo n.º 1
0
        public void Constructor_WithQueryParameters_AddsQueryParametersToFullUri()
        {
            const string UriString = "https://www.google.ch";
            var          baseUri   = new Uri(UriString);

            const RestCallMethodType MethodType = RestCallMethodType.Get;
            var security = RestSecurity.CreateAnonymous();
            var headers  = new RestHeaders(new List <RestHeader>());
            var body     = Maybe.CreateSome(RestCallBody.CreateApplicationJson(new object()));

            var queryParameterList = new List <QueryParameter> {
                new QueryParameter("Key1", "Value1", "Value2"), new QueryParameter("Key2", "Value3")
            };

            const string ExpectedUriString = UriString + "?Key1=Value1&Key1=Value2&Key2=Value3";
            var          expectedFullUri   = new Uri(ExpectedUriString);

            var queryParameters = new QueryParameters(queryParameterList);

            ConstructorTestBuilderFactory.Constructing <RestCall>()
            .UsingDefaultConstructor()
            .WithArgumentValues(baseUri, Maybe.CreateNone <string>(), MethodType, security, headers, body, queryParameters)
            .Maps()
            .ToProperty(f => f.AbsoluteUri).WithValue(expectedFullUri)
            .BuildMaps()
            .Assert();
        }
Ejemplo n.º 2
0
        public void Constructor_Works()
        {
            var          baseUri = new Uri("https://www.google.ch");
            const string ActualResourcePathString = "Test";

            Maybe <string>           resourcePath = ActualResourcePathString;
            const RestCallMethodType MethodType   = RestCallMethodType.Get;
            var security        = RestSecurity.CreateAnonymous();
            var headers         = new RestHeaders(new List <RestHeader>());
            var body            = Maybe.CreateSome(RestCallBody.CreateApplicationJson(new object()));
            var expectedFullUri = new Uri(baseUri, "/" + ActualResourcePathString);
            var queryParameters = new QueryParameters(new List <QueryParameter>());

            ConstructorTestBuilderFactory.Constructing <RestCall>()
            .UsingDefaultConstructor()
            .WithArgumentValues(baseUri, resourcePath, MethodType, security, headers, body, queryParameters)
            .Maps()
            .ToProperty(f => f.BaseUri).WithValue(baseUri)
            .ToProperty(f => f.Body).WithValue(body)
            .ToProperty(f => f.Headers).WithValue(headers)
            .ToProperty(f => f.MethodType).WithValue(MethodType)
            .ToProperty(f => f.ResourcePath).WithValue(resourcePath)
            .ToProperty(f => f.Security).WithValue(security)
            .ToProperty(f => f.AbsoluteUri).WithValue(expectedFullUri)
            .BuildMaps()
            .Assert();
        }
Ejemplo n.º 3
0
        internal RestCall(Uri baseUri, Maybe <string> resourcePath, RestCallMethodType methodType, RestSecurity security, RestHeaders headers, Maybe <RestCallBody> body, QueryParameters queryParameters)
        {
            Guard.ObjectNotNull(() => baseUri);
            Guard.ObjectNotNull(() => security);
            Guard.ObjectNotNull(() => headers);
            Guard.ObjectNotNull(() => body);
            Guard.ObjectNotNull(() => queryParameters);

            _queryParameters = queryParameters;
            ResourcePath     = resourcePath;
            MethodType       = methodType;
            Security         = security;
            Headers          = headers;
            Body             = body;
            BaseUri          = baseUri;
        }
Ejemplo n.º 4
0
        private static HttpMethod MapHttpMethod(RestCallMethodType methodType)
        {
            switch (methodType)
            {
            case RestCallMethodType.Get:
                return(HttpMethod.Get);

            case RestCallMethodType.Post:
                return(HttpMethod.Post);

            case RestCallMethodType.Patch:
                return(new HttpMethod("PATCH"));

            case RestCallMethodType.Delete:
                return(HttpMethod.Delete);

            case RestCallMethodType.Put:
                return(HttpMethod.Put);

            default:
                throw new ArgumentException($"Invalid RestCallMethodType{methodType}.");
            }
        }
 protected IRestCallBuilder CreateBaseBuilder(string resourcePath, RestCallMethodType method)
 {
     return(_restCallBuilderFactory.StartBuilding(RestSettings.BasePath, method)
            .WithResourcePath(resourcePath)
            .WithSecurity(RestSettings.RestSecurity));
 }
 public RestCallBuilder(Uri basePath, RestCallMethodType methodType)
 {
     _basePath   = basePath;
     _methodType = methodType;
 }
 public IRestCallBuilder StartBuilding(Uri basePath, RestCallMethodType methodType = RestCallMethodType.Get)
 {
     return(new RestCallBuilder(basePath, methodType));
 }