Beispiel #1
0
        public void AddingHandlerParam()
        {
            var request = Request.Has(Method.Get)
                          .And("/posts/my-post/comment/my-comment/votes/10/user/admin".ToMatchableUri())
                          .And(Version.Http1_1);
            var mappedParameters =
                new Action.MappedParameters(1, Method.Get, "ignored", new List <Action.MappedParameter>
            {
                new Action.MappedParameter("String", "my-post"),
                new Action.MappedParameter("String", "my-comment"),
                new Action.MappedParameter("String", 10),
                new Action.MappedParameter("String", "admin"),
                new Action.MappedParameter("String", "justanother")
            });

            var
                handler = CreateRequestHandler(
                Method.Get,
                "/posts/{postId}/comment/{commentId}/votes/{votesNumber}/user/{userId}/{another}",
                ParameterResolver.Path <string>(0),
                ParameterResolver.Path <string>(1),
                ParameterResolver.Path <int>(2),
                ParameterResolver.Path <string>(3)
                )
                          .Param <string>();

            AssertResolvesAreEquals(ParameterResolver.Path <string>(4), handler.ResolverParam5);
            Assert.Equal("justanother", handler.ResolverParam5.Apply(request, mappedParameters));
        }
Beispiel #2
0
        public void ExecuteWithRequestAndMappedParameters()
        {
            var request = Request.Has(Method.Get)
                          .And("/posts/my-post/comments/my-comment".ToMatchableUri())
                          .And(Version.Http1_1);
            var mappedParameters =
                new Action.MappedParameters(1, Method.Get, "ignored", new List <Action.MappedParameter>
            {
                new Action.MappedParameter("string", "my-post"),
                new Action.MappedParameter("string", "my-comment"),
            });
            var handler = CreateRequestHandler(
                Method.Get,
                "/posts/{postId}",
                ParameterResolver.Path <string>(0))
                          .Handle(postId
                                  => Completes.WithSuccess(Response.Of(Response.ResponseStatus.Ok, JsonSerialization.Serialized(
                                                                           $"{postId}"))));

            var response = handler.Execute(request, mappedParameters, Logger).Outcome;

            AssertResponsesAreEquals(
                Response.Of(Response.ResponseStatus.Ok, JsonSerialization.Serialized("my-post")),
                response);
        }
Beispiel #3
0
        public void AddingHandlerBodyWithMapper()
        {
            var request = Request.Has(Method.Post)
                          .And("/posts/my-post/comment/my-comment".ToMatchableUri())
                          .And(Body.From("{\"given\":\"John\",\"family\":\"Doe\"}"))
                          .And(Version.Http1_1);
            var mappedParameters =
                new Action.MappedParameters(1, Method.Post, "ignored", new List <Action.MappedParameter>
            {
                new Action.MappedParameter("String", "my-post"),
                new Action.MappedParameter("String", "my-comment")
            });

#pragma warning disable 618
            var handler = CreateRequestHandler(
                Method.Post,
                "/posts/{postId}/comment/{commentId}/votes/{votesNumber}",
                ParameterResolver.Path <string>(0),
                ParameterResolver.Path <string>(1),
                ParameterResolver.Path <int>(2),
                ParameterResolver.Query("page", 10)
                )
                          .Body <NameData>(typeof(TestMapper));
#pragma warning restore 618

            AssertResolvesAreEquals(ParameterResolver.Body <NameData>(), handler.ResolverParam5);
            Assert.Equal(new NameData("John", "Doe"), handler.ResolverParam5.Apply(request, mappedParameters));
        }
Beispiel #4
0
        public ParameterResolverTest()
        {
            _request = Request.Has(Method.Post)
                       .And(Version.Http1_1)
                       .And("/user/my-post?page=10".ToMatchableUri())
                       .And(RequestHeader.FromString("Host:www.vlingo.io"))
                       .And(Http.Body.From("{\"given\":\"John\",\"family\":\"Doe\"}"));

            _mappedParameters = new Action.MappedParameters(1, Method.Get, "ignored", new List <Action.MappedParameter>
            {
                new Action.MappedParameter("String", "my-post")
            });
        }
        public void AddingHandlerQuery()
        {
            var request = Request.Has(Method.Get)
                          .And("/user?filter=abc".ToMatchableUri())
                          .And(Version.Http1_1);
            var mappedParameters =
                new Action.MappedParameters(1, Method.Get, "ignored", new List <Action.MappedParameter>());

            var handler = new RequestHandler0(Method.Get, "/user").Query("filter");

            AssertResolvesAreEquals(ParameterResolver.Query <string>("filter"), handler.Resolver);
            Assert.Equal("abc", handler.Resolver.Apply(request, mappedParameters));
        }
        public void AddingHandlerHeader()
        {
            var hostHeader = RequestHeader.Of("Host", "www.vlingo.io");
            var request    = Request.Has(Method.Get)
                             .And("/user?filter=abc".ToMatchableUri())
                             .And(Headers.Of(hostHeader))
                             .And(Version.Http1_1);
            var mappedParameters =
                new Action.MappedParameters(1, Method.Get, "ignored", new List <Action.MappedParameter>());

            var handler = new RequestHandler0(Method.Get, "/user").Header("Host");

            AssertResolvesAreEquals(ParameterResolver.Header("Host"), handler.Resolver);
            Assert.Equal(hostHeader, handler.Resolver.Apply(request, mappedParameters));
        }
        public void AddingHandlerParam()
        {
            var request = Request.Has(Method.Get)
                          .And("/user/admin".ToMatchableUri())
                          .And(Version.Http1_1);
            var mappedParameters =
                new Action.MappedParameters(1, Method.Get, "ignored", new List <Action.MappedParameter>
            {
                new Action.MappedParameter("String", "admin")
            });

            var handler = new RequestHandler0(Method.Get, "/user/{userId}").Param <string>();

            AssertResolvesAreEquals(ParameterResolver.Path <string>(0), handler.Resolver);
            Assert.Equal("admin", handler.Resolver.Apply(request, mappedParameters));
        }
        public void ExecuteWithRequestAndMappedParametersHasToReturnTheSameAsExecute()
        {
            var request = Request.Has(Method.Get)
                          .And("/hellworld".ToMatchableUri())
                          .And(Version.Http1_1);
            var mappedParameters =
                new Action.MappedParameters(1, Method.Get, "ignored", new List <Action.MappedParameter>());
            var handler = new RequestHandler0(Method.Get, "/helloworld")
                          .Handle(() => Completes.WithSuccess(Response.Of(Response.ResponseStatus.Created)));
            var response = handler.Execute(request, mappedParameters, Logger).Outcome;

            Assert.NotNull(handler);
            Assert.Equal(Method.Get, handler.Method);
            Assert.Equal("/helloworld", handler.Path);
            AssertResponsesAreEquals(Response.Of(Response.ResponseStatus.Created), response);
        }
Beispiel #9
0
        public void ExecuteWithRequestAndMappedParametersWithWrongSignatureType()
        {
            var request = Request.Has(Method.Get)
                          .And("/posts/my-post".ToMatchableUri())
                          .And(Version.Http1_1);
            var mappedParameters =
                new Action.MappedParameters(1, Method.Get, "ignored", new List <Action.MappedParameter>
            {
                new Action.MappedParameter("String", "my-post")
            });
            var handler = CreateRequestHandler(Method.Get, "/posts/{postId}", ParameterResolver.Path <int>(0))
                          .Handle(postId => Completes.WithSuccess(Response.Of(Response.ResponseStatus.Ok, JsonSerialization.Serialized("it is my-post"))));

            var exception = Assert.Throws <ArgumentException>(() => handler.Execute(request, mappedParameters, Logger));

            Assert.Equal("Value my-post is of mimeType String instead of Int32", exception.Message);
        }
        public void AddingHandlerBody()
        {
            var request = Request.Has(Method.Post)
                          .And("/user/admin/name".ToMatchableUri())
                          .And(Body.From("{\"given\":\"John\",\"family\":\"Doe\"}"))
                          .And(Version.Http1_1);
            var mappedParameters =
                new Action.MappedParameters(1, Method.Post, "ignored", new List <Action.MappedParameter>
            {
                new Action.MappedParameter("String", "admin")
            });

            var handler = new RequestHandler0(Method.Get, "/user/admin/name").Body <NameData>();

            AssertResolvesAreEquals(ParameterResolver.Body <NameData>(), handler.Resolver);
            Assert.Equal(new NameData("John", "Doe"), handler.Resolver.Apply(request, mappedParameters));
        }
Beispiel #11
0
        public void AddingHandlerQuery()
        {
            var request = Request.Has(Method.Post)
                          .And("/user/admin?filter=abc".ToMatchableUri())
                          .And(Version.Http1_1);
            var mappedParameters =
                new Action.MappedParameters(1, Method.Get, "ignored",
                                            Enumerable.Empty <Action.MappedParameter>().ToList());

            var handler = CreateRequestHandler(
                Method.Get,
                "/user/{userId}",
                ParameterResolver.Path <string>(0))
                          .Query("filter");

            AssertResolvesAreEquals(ParameterResolver.Query <string>("filter"), handler.ResolverParam2);
            Assert.Equal("abc", handler.ResolverParam2.Apply(request, mappedParameters));
        }
Beispiel #12
0
        public void AddingHandlerHeader()
        {
            var hostHeader = RequestHeader.Of("Host", "www.vlingo.io");
            var request    = Request.Has(Method.Get)
                             .And("/user/admin".ToMatchableUri())
                             .And(Headers.Of(hostHeader))
                             .And(Version.Http1_1);
            var mappedParameters =
                new Action.MappedParameters(1, Method.Get, "ignored",
                                            Enumerable.Empty <Action.MappedParameter>().ToList());

            var handler = CreateRequestHandler(
                Method.Get,
                "/user/{userId}",
                ParameterResolver.Path <string>(0))
                          .Header("Host");

            AssertResolvesAreEquals(ParameterResolver.Header("Host"), handler.ResolverParam2);
            Assert.Equal(hostHeader, handler.ResolverParam2.Apply(request, mappedParameters));
        }
        public void AddingHandlerBodyWithMediaTypeMapper()
        {
            var request = Request.Has(Method.Post)
                          .And("/user/admin/name".ToMatchableUri())
                          .And(Body.From("{\"given\":\"John\",\"family\":\"Doe\"}"))
                          .And(RequestHeader.Of(RequestHeader.ContentType, "application/json"))
                          .And(Version.Http1_1);
            var mappedParameters =
                new Action.MappedParameters(1, Method.Post, "ignored", new List <Action.MappedParameter>
            {
                new Action.MappedParameter("String", "admin")
            });

#pragma warning disable 618
            var handler = new RequestHandler0(Method.Get, "/user/admin/name").Body <NameData>(typeof(TestMapper));
#pragma warning restore 618

            AssertResolvesAreEquals(ParameterResolver.Body <NameData>(new TestMapper()), handler.Resolver);
            Assert.Equal(new NameData("John", "Doe"), handler.Resolver.Apply(request, mappedParameters));
        }
Beispiel #14
0
        public void AddingHandlerParam()
        {
            var request = Request.Has(Method.Get)
                          .And("/user/admin/picture/2".ToMatchableUri())
                          .And(Version.Http1_1);
            var mappedParameters =
                new Action.MappedParameters(1, Method.Get, "ignored", new List <Action.MappedParameter>
            {
                new Action.MappedParameter("String", "admin"),
                new Action.MappedParameter("int", 1)
            });

            var handler = CreateRequestHandler(
                Method.Get,
                "/user/{userId}/picture/{pictureId}",
                ParameterResolver.Path <string>(0))
                          .Param <int>();

            AssertResolvesAreEquals(ParameterResolver.Path <int>(1), handler.ResolverParam2);
            Assert.Equal(1, handler.ResolverParam2.Apply(request, mappedParameters));
        }
Beispiel #15
0
        public void AddingHandlerQuery()
        {
            var request = Request.Has(Method.Post)
                          .And("/posts/my-post/comment/my-comment?filter=abc".ToMatchableUri())
                          .And(Version.Http1_1);
            var mappedParameters =
                new Action.MappedParameters(1, Method.Get, "ignored", Enumerable.Empty <Action.MappedParameter>().ToList());

            var handler = CreateRequestHandler(
                Method.Get,
                "/posts/{postId}/comment/{commentId}/votes/{votesId}",
                ParameterResolver.Path <string>(0),
                ParameterResolver.Path <string>(1),
                ParameterResolver.Path <string>(2),
                ParameterResolver.Query("page", 10)
                )
                          .Query("filter");

            AssertResolvesAreEquals(ParameterResolver.Query <string>("filter"), handler.ResolverParam5);
            Assert.Equal("abc", handler.ResolverParam5.Apply(request, mappedParameters));
        }
        public void AddingHandlerBody()
        {
            var request = Request.Has(Method.Post)
                          .And("/posts/my-post/comment/my-comment".ToMatchableUri())
                          .And(Body.From("{\"given\":\"John\",\"family\":\"Doe\"}"))
                          .And(Version.Http1_1);
            var mappedParameters =
                new Action.MappedParameters(1, Method.Post, "ignored", new List <Action.MappedParameter>
            {
                new Action.MappedParameter("String", "my-post"),
                new Action.MappedParameter("String", "my-comment")
            });

            var handler = CreateRequestHandler(
                Method.Post,
                "/posts/{postId}/comment/{commentId}",
                ParameterResolver.Path <string>(0),
                ParameterResolver.Path <string>(1))
                          .Body <NameData>();

            AssertResolvesAreEquals(ParameterResolver.Body <NameData>(), handler.ResolverParam3);
            Assert.Equal(new NameData("John", "Doe"), handler.ResolverParam3.Apply(request, mappedParameters));
        }
Beispiel #17
0
        public void AddingHandlerBodyWithMapper()
        {
            var request = Request.Has(Method.Post)
                          .And("/user/admin/name".ToMatchableUri())
                          .And(Body.From("{\"given\":\"John\",\"family\":\"Doe\"}"))
                          .And(Version.Http1_1);
            var mappedParameters =
                new Action.MappedParameters(1, Method.Post, "ignored", new List <Action.MappedParameter>
            {
                new Action.MappedParameter("String", "admin")
            });

#pragma warning disable 618
            var handler = CreateRequestHandler(
                Method.Post,
                "/user/{userId}/picture/{pictureId}",
                ParameterResolver.Path <string>(0))
                          .Body <NameData>(typeof(TestMapper));
#pragma warning restore 618

            AssertResolvesAreEquals(ParameterResolver.Body <NameData>(), handler.ResolverParam2);
            Assert.Equal(new NameData("John", "Doe"), handler.ResolverParam2.Apply(request, mappedParameters));
        }
Beispiel #18
0
        public void AddingHandlerHeader()
        {
            var hostHeader = RequestHeader.Of("Host", "www.vlingo.io");
            var request    = Request.Has(Method.Get)
                             .And("/posts/my-post/comment/my-comment".ToMatchableUri())
                             .And(Headers.Of(hostHeader))
                             .And(Version.Http1_1);
            var mappedParameters =
                new Action.MappedParameters(1, Method.Get, "ignored", Enumerable.Empty <Action.MappedParameter>().ToList());

            var handler = CreateRequestHandler(
                Method.Get,
                "/posts/{postId}/comment/{commentId}/votes/{votesNumber}",
                ParameterResolver.Path <string>(0),
                ParameterResolver.Path <string>(1),
                ParameterResolver.Path <string>(2),
                ParameterResolver.Query("page", 10)
                )
                          .Header("Host");

            AssertResolvesAreEquals(ParameterResolver.Header("Host"), handler.ResolverParam5);
            Assert.Equal(hostHeader, handler.ResolverParam5.Apply(request, mappedParameters));
        }
 internal override ICompletes <Response> Execute(Request request, Action.MappedParameters mappedParameters, ILogger logger)
 => _executor.Invoke(request, DefaultMediaTypeMapper.Instance, _errorHandler, logger);
 internal override ICompletes <Response> Execute(Request request, Action.MappedParameters mappedParameters, ILogger logger)
 {
     throw new System.NotImplementedException();
 }