Пример #1
0
        public void TestThatAllPoorlyOrderedActionHaveMatches()
        {
            ActionPostUser         = new Action(0, "POST", "/users", "register(body:Vlingo.Http.Tests.Sample.User.UserData userData)", null);
            ActionPatchUserContact = new Action(1, "PATCH", "/users/{userId}/contact", "changeContact(string userId, body:Vlingo.Http.Tests.Sample.User.ContactData contactData)", null);
            ActionPatchUserName    = new Action(2, "PATCH", "/users/{userId}/name", "changeName(string userId, body:Vlingo.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 <UserResource> .NewResourceFor("user", ResourceHandlerType, 5, actions);

            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);
        }
Пример #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));
        }
Пример #3
0
        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.Http.Tests.Sample.User.UserData userData)", "Vlingo.Http.Tests.Sample.User.UserDataMapper");
            ActionPatchUserContact = new Action(1, "PATCH", "/users/{userId}/contact", "changeContact(string userId, body:Vlingo.Http.Tests.Sample.User.ContactData contactData)", "Vlingo.Http.Tests.Sample.User.UserDataMapper");
            ActionPatchUserName    = new Action(2, "PATCH", "/users/{userId}/name", "changeName(string userId, body:Vlingo.Http.Tests.Sample.User.NameData nameData)", "Vlingo.Http.Tests.Sample.User.UserDataMapper");
            ActionGetUser          = new Action(3, "GET", "/users/{userId}", "queryUser(string userId)", "Vlingo.Http.Tests.Sample.User.UserDataMapper");
            ActionGetUsers         = new Action(4, "GET", "/users", "queryUsers()", "Vlingo.Http.Tests.Sample.User.UserDataMapper");
            ActionGetUserError     = new Action(5, "GET", "/users/{userId}/error", "queryUserError(string userId)", "Vlingo.Http.Tests.Sample.User.UserDataMapper");
            ActionPutUser          = new Action(6, "PUT", "/users/{userId}", "changeUser(string userId, body:Vlingo.Http.Tests.Sample.User.UserData userData)", "Vlingo.Http.Tests.Sample.User.UserDataMapper");


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

            ResourceHandlerType = ConfigurationResource.NewResourceHandlerTypeFor("Vlingo.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);
        }
Пример #4
0
        public ResourceDispatcherGeneratorTest(ITestOutputHelper output)
        {
            var converter = new Converter(output);

            Console.SetOut(converter);

            var actionPostUser         = new Action(0, "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 actionPatchUserName    = new Action(2, "PATCH", "/users/{userId}/name", "changeName(string userId, body:Vlingo.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);

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

            Type resourceHandlerClass;

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

            _resource = ConfigurationResource <UserResource> .NewResourceFor("user", resourceHandlerClass, 5, _actions);
        }