Beispiel #1
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();
        }
Beispiel #2
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();
        }
        public void CreatingAnonymous_CreatesAnonymous()
        {
            // Act
            var actualSecurity = RestSecurity.CreateAnonymous();

            // Assert
            Assert.IsInstanceOf <Anonymous>(actualSecurity);
        }
 internal static RestCall CreatePostOneTodoRestCall(string todoJson)
 {
     return(new RestCall(
                new Uri("https://jsonplaceholder.typicode.com/comments"),
                Maybe.CreateNone <string>(),
                RestCallMethodType.Post,
                RestSecurity.CreateAnonymous(),
                new RestHeaders(new List <RestHeader>()),
                RestCallBody.CreateApplicationJson(todoJson),
                new QueryParameters(new List <QueryParameter>())));
 }
 internal static RestCall CreateNotExistingPostRestCall()
 {
     return(new RestCall(
                new Uri("https://google.com/"),
                Maybe.CreateNone <string>(),
                RestCallMethodType.Post,
                RestSecurity.CreateAnonymous(),
                new RestHeaders(new List <RestHeader>()),
                Maybe.CreateNone <RestCallBody>(),
                new QueryParameters(new List <QueryParameter>())));
 }
 internal static RestCall CreateGetOneTodoRestCall()
 {
     return(new RestCall(
                new Uri("https://jsonplaceholder.typicode.com/todos/1"),
                Maybe.CreateNone <string>(),
                RestCallMethodType.Get,
                RestSecurity.CreateAnonymous(),
                new RestHeaders(new List <RestHeader>()),
                Maybe.CreateNone <RestCallBody>(),
                new QueryParameters(new List <QueryParameter>())));
 }
 internal static RestCall CreateDefaultRestCall()
 {
     return(new RestCall(
                new Uri("https://www.google.ch"),
                Maybe.CreateNone <string>(),
                RestCallMethodType.Get,
                RestSecurity.CreateAnonymous(),
                new RestHeaders(new List <RestHeader>()),
                Maybe.CreateNone <RestCallBody>(),
                new QueryParameters(new List <QueryParameter>())));
 }
Beispiel #8
0
        public Task Given_the_user_is_about_to_call_a_nonexisting_url()
        {
            _restCall = new RestCall(
                new Uri("https://googlewdwwfwef.com/"),
                Maybe.CreateNone <string>(),
                RestCallMethodType.Post,
                RestSecurity.CreateAnonymous(),
                new RestHeaders(new List <RestHeader>()),
                Maybe.CreateNone <RestCallBody>(),
                new QueryParameters(new List <QueryParameter>()));

            return(Task.CompletedTask);
        }
        internal static RestCall CreateCommentsByPostIdRestCall()
        {
            var queryParameters = new List <QueryParameter> {
                new QueryParameter("postId", 1)
            };

            return(new RestCall(
                       new Uri("https://jsonplaceholder.typicode.com/comments"),
                       Maybe.CreateNone <string>(),
                       RestCallMethodType.Get,
                       RestSecurity.CreateAnonymous(),
                       new RestHeaders(new List <RestHeader>()),
                       Maybe.CreateNone <RestCallBody>(),
                       new QueryParameters(queryParameters)));
        }
Beispiel #10
0
        public Task Given_the_user_is_about_to_fetch_comments_per_post_id()
        {
            var queryParameters = new List <QueryParameter> {
                new QueryParameter("postId", PostId)
            };

            _restCall = new RestCall(
                new Uri("https://jsonplaceholder.typicode.com/comments"),
                Maybe.CreateNone <string>(),
                RestCallMethodType.Get,
                RestSecurity.CreateAnonymous(),
                new RestHeaders(new List <RestHeader>()),
                Maybe.CreateNone <RestCallBody>(),
                new QueryParameters(queryParameters));

            return(Task.CompletedTask);
        }