public void TestThatAllPoorlyOrderedActionHaveMatches()
    {
        ActionPostUser         = new Action(0, "POST", "/users", "register(body:Vlingo.Xoom.Http.Tests.Sample.User.UserData userData)", null);
        ActionPatchUserContact = new Action(1, "PATCH", "/users/{userId}/contact", "changeContact(string userId, body:Vlingo.Xoom.Http.Tests.Sample.User.ContactData contactData)", null);
        ActionPatchUserName    = new Action(2, "PATCH", "/users/{userId}/name", "changeName(string userId, body:Vlingo.Xoom.Http.Tests.Sample.User.NameData nameData)", null);
        ActionGetUsers         = new Action(3, "GET", "/users", "queryUsers()", null);
        ActionGetUser          = new Action(4, "GET", "/users/{userId}", "queryUser(string userId)", null);
        var actionGetUserEmailAddress = new Action(5, "GET", "/users/{userId}/emailAddresses/{emailAddressId}", "queryUserEmailAddress(string userId, string emailAddressId)", null);

        //=============================================================
        // this test assures that the optional feature used in the
        // Action.MatchResults constructor is enabled and short circuits
        // a match if any parameters contain a "/", which would normally
        // mean that the Action that appeared to match didn't have
        // enough Matchable PathSegments. Look for the following in
        // Action.MatchResult(): disallowPathParametersWithSlash
        // see the above testThatAllWellOrderedActionHaveMatches() for
        // a better ordering of actions and one that does not use the
        // disallowPathParametersWithSlash option.
        // See also: vlingo-http.properties
        //   userResource.NAME.disallowPathParametersWithSlash = true/false
        //=============================================================

        var actions = new List <Action>
        {
            ActionPostUser,
            ActionPatchUserContact,
            ActionPatchUserName,
            ActionGetUsers, // order is problematic unless parameter matching short circuit used
            ActionGetUser,
            actionGetUserEmailAddress
        };

        var resource = ConfigurationResource.NewResourceFor("user", ResourceHandlerType, 5, actions, ConsoleLogger.TestInstance());

        var actionGetUsersMatch = resource.MatchWith(Method.Get, "/users".ToMatchableUri());

        Assert.True(actionGetUsersMatch.IsMatched);
        Assert.Equal(ActionGetUsers, actionGetUsersMatch.Action);

        var actionGetUserMatch = resource.MatchWith(Method.Get, "/users/1234567".ToMatchableUri());

        Assert.True(actionGetUserMatch.IsMatched);
        Assert.Equal(ActionGetUser, actionGetUserMatch.Action);

        var actionGetUserEmailAddressMatch = resource.MatchWith(Method.Get, "/users/1234567/emailAddresses/890".ToMatchableUri());

        Assert.True(actionGetUserEmailAddressMatch.IsMatched);
        Assert.Equal(actionGetUserEmailAddress, actionGetUserEmailAddressMatch.Action);

        var actionPatchUserNameMatch = resource.MatchWith(Method.Patch, "/users/1234567/name".ToMatchableUri());

        Assert.True(actionPatchUserNameMatch.IsMatched);
        Assert.Equal(ActionPatchUserName, actionPatchUserNameMatch.Action);

        var actionPostUserMatch = resource.MatchWith(Method.Post, "/users".ToMatchableUri());

        Assert.True(actionPostUserMatch.IsMatched);
        Assert.Equal(ActionPostUser, actionPostUserMatch.Action);
    }
Esempio n. 2
0
        public void TestThatWrongIdOrderBreaks()
        {
            var actionPostUser         = new Action(3, "POST", "/users", "register(body:Vlingo.Http.Tests.Sample.User.UserData userData)", null);
            var actionPatchUserContact = new Action(1, "PATCH", "/users/{userId}/contact", "changeContact(string userId, body:Vlingo.Http.Tests.Sample.User.ContactData contactData)", null);

            var actions = new List <Action> {
                actionPostUser, actionPatchUserContact
            };

            var resourceHandlerClass = ConfigurationResource <UserResource> .NewResourceHandlerTypeFor("Vlingo.Http.Tests.Sample.User.UserResource");

            Assert.Throws <ArgumentException>(() => ConfigurationResource <UserResource> .NewResourceFor("user", resourceHandlerClass, 5, actions));
        }
Esempio n. 3
0
 private static IConfigurationResource ResourceFor(
     string resourceName,
     Type resourceHandlerClass,
     int handlerPoolSize,
     IList <Action> resourceActions,
     ILogger logger)
 {
     try
     {
         var resource = ConfigurationResource.NewResourceFor(resourceName, resourceHandlerClass, handlerPoolSize, resourceActions, logger);
         return(resource);
     }
     catch (Exception e)
     {
         throw new InvalidOperationException($"ConfigurationResource cannot be created for: {resourceHandlerClass.Name}", e);
     }
 }
    public ResourceTestFixtures(ITestOutputHelper output)
    {
        var converter = new Converter(output);

        Console.SetOut(converter);

        World = World.Start(WorldName);

        ActionPostUser         = new Action(0, "POST", "/users", "Register(body:Vlingo.Xoom.Http.Tests.Sample.User.UserData userData)", "Vlingo.Xoom.Http.Tests.Sample.User.UserDataMapper");
        ActionPatchUserContact = new Action(1, "PATCH", "/users/{userId}/contact", "changeContact(string userId, body:Vlingo.Xoom.Http.Tests.Sample.User.ContactData contactData)", "Vlingo.Xoom.Http.Tests.Sample.User.UserDataMapper");
        ActionPatchUserName    = new Action(2, "PATCH", "/users/{userId}/name", "changeName(string userId, body:Vlingo.Xoom.Http.Tests.Sample.User.NameData nameData)", "Vlingo.Xoom.Http.Tests.Sample.User.UserDataMapper");
        ActionGetUser          = new Action(3, "GET", "/users/{userId}", "queryUser(string userId)", "Vlingo.Xoom.Http.Tests.Sample.User.UserDataMapper");
        ActionGetUsers         = new Action(4, "GET", "/users", "queryUsers()", "Vlingo.Xoom.Http.Tests.Sample.User.UserDataMapper");
        ActionGetUserError     = new Action(5, "GET", "/users/{userId}/error", "queryUserError(string userId)", "Vlingo.Xoom.Http.Tests.Sample.User.UserDataMapper");
        ActionPutUser          = new Action(6, "PUT", "/users/{userId}", "changeUser(string userId, body:Vlingo.Xoom.Http.Tests.Sample.User.UserData userData)", "Vlingo.Xoom.Http.Tests.Sample.User.UserDataMapper");


        var actions = new List <Action> {
            ActionPostUser,
            ActionPatchUserContact,
            ActionPatchUserName,
            ActionGetUser,
            ActionGetUsers,
            ActionGetUserError,
            ActionPutUser
        };

        ResourceHandlerType = ConfigurationResource.NewResourceHandlerTypeFor("Vlingo.Xoom.Http.Tests.Sample.User.UserResource");

        Resource = ConfigurationResource.NewResourceFor("user", ResourceHandlerType, 7, actions, World.DefaultLogger);

        Resource.AllocateHandlerPool(World.Stage);

        var oneResource = new Dictionary <string, IResource>(1);

        oneResource.Add(Resource.Name, Resource);

        Resources  = new Resources(oneResource);
        Dispatcher = new TestDispatcher(Resources, World.DefaultLogger);
    }
    public ResourceDispatcherGeneratorTest(ITestOutputHelper output)
    {
        var converter = new Converter(output);

        Console.SetOut(converter);

        var actionPostUser         = new Action(0, "POST", "/users", "register(body:Vlingo.Xoom.Http.Tests.Sample.User.UserData userData)", null);
        var actionPatchUserContact = new Action(1, "PATCH", "/users/{userId}/contact", "changeContact(string userId, body:Vlingo.Xoom.Http.Tests.Sample.User.ContactData contactData)", null);
        var actionPatchUserName    = new Action(2, "PATCH", "/users/{userId}/name", "changeName(string userId, body:Vlingo.Xoom.Http.Tests.Sample.User.NameData nameData)", null);
        var actionGetUser          = new Action(3, "GET", "/users/{userId}", "queryUser(string userId)", null);
        var actionGetUsers         = new Action(4, "GET", "/users", "queryUsers()", null);
        var actionQueryUserError   = new Action(5, "GET", "/users/{userId}/error", "queryUserError(string userId)", null);
        var actionPutUser          = new Action(6, "PUT", "/users/{userId}", "changeUser(string userId, body:Vlingo.Xoom.Http.Tests.Sample.User.UserData userData)", null);

        _actions = new List <Action>
        {
            actionPostUser,
            actionPatchUserContact,
            actionPatchUserName,
            actionGetUser,
            actionGetUsers,
            actionQueryUserError,
            actionPutUser
        };

        Type resourceHandlerClass;

        try
        {
            resourceHandlerClass = Type.GetType("Vlingo.Xoom.Http.Tests.Sample.User.UserResource");
        }
        catch (Exception)
        {
            resourceHandlerClass = ConfigurationResource.NewResourceHandlerTypeFor("Vlingo.Xoom.Http.Tests.Sample.User.UserResource");
        }

        _resource = ConfigurationResource.NewResourceFor("user", resourceHandlerClass, 5, _actions, ConsoleLogger.TestInstance());
    }