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));
    }
    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));
    }
    public void ExecuteWithRequestAndMappedParameters()
    {
        var request = Request.Has(Method.Get)
                      .And("/posts/my-post/comments/my-comment/users/my-user/contacts/my-contact".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", "my-user"),
            new Action.MappedParameter("string", "my-contact")
        });
        var handler = CreateRequestHandler(
            Method.Get,
            "/posts/{postId}/comment/{commentId}/user/{userId}/contact/{contactId}",
            ParameterResolver.Path <string>(0),
            ParameterResolver.Path <string>(1),
            ParameterResolver.Path <string>(2),
            ParameterResolver.Path <string>(3),
            ParameterResolver.Query("page", 10),
            ParameterResolver.Query("pageSize", 10))
                      .Handle((postId, commentId, userId, contactId, page, pageSize)
                              => Completes.WithSuccess(Response.Of(ResponseStatus.Ok, JsonSerialization.Serialized(
                                                                       $"{postId} {commentId} {userId} {contactId}"))));

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

        AssertResponsesAreEquals(Response.Of(ResponseStatus.Ok, JsonSerialization.Serialized("my-post my-comment my-user my-contact")), response);
    }
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")
            });
        }
Beispiel #5
0
    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));
    }
Beispiel #6
0
    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));
    }
Beispiel #7
0
    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(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(ResponseStatus.Created), response);
    }
Beispiel #8
0
    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));
    }
Beispiel #9
0
    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));
    }
    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(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 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}",
            ParameterResolver.Path <string>(0),
            ParameterResolver.Path <string>(1))
                      .Query("filter");

        AssertResolvesAreEquals(ParameterResolver.Query <string>("filter"), handler.ResolverParam3);
        Assert.Equal("abc", handler.ResolverParam3.Apply(request, mappedParameters));
    }
    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}",
            ParameterResolver.Path <string>(0),
            ParameterResolver.Path <string>(1))
                      .Header("Host");

        AssertResolvesAreEquals(ParameterResolver.Header("Host"), handler.ResolverParam3);
        Assert.Equal(hostHeader, handler.ResolverParam3.Apply(request, mappedParameters));
    }
Beispiel #13
0
    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));
    }
    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));
    }
    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));
    }
    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));
    }
 internal override ICompletes <Response> Execute(Request request, Action.MappedParameters mappedParameters, ILogger logger)
 {
     throw new NotImplementedException();
 }
 internal override ICompletes <Response> Execute(Request request, Action.MappedParameters mappedParameters, ILogger logger)
 => _executor.Invoke(request, DefaultMediaTypeMapper.Instance, _errorHandler, logger);