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); }
public void TestMatchesMultipleParametersWithSimilarUri() { var shortAction = new Action( 0, "GET", "/o/{oId}/u/{uId}/foo", "foo(string oId, string uId, string uId)", null); var longAction = new Action( 0, "GET", "/o/{oId}/u/{uId}/c/{cId}/foo", "foo(string oId, string uId, string uId, string cId)", null); var matchResultsShortUriToShortAction = shortAction.MatchWith(Method.Get, "/o/1/u/2/foo".ToMatchableUri()); var matchResultsLongUriToShortAction = shortAction.MatchWith(Method.Get, "/o/1/u/2/c/3/foo".ToMatchableUri()); var matchResultsShortUriToLongAction = longAction.MatchWith(Method.Get, "/o/1/u/2/foo".ToMatchableUri()); var matchResultsLongUriToLongAction = longAction.MatchWith(Method.Get, "/o/1/u/2/c/3/foo".ToMatchableUri()); Assert.True(matchResultsShortUriToShortAction.IsMatched); Assert.False(matchResultsLongUriToShortAction.IsMatched); Assert.False(matchResultsShortUriToLongAction.IsMatched); Assert.True(matchResultsLongUriToLongAction.IsMatched); }
public void TestWithQueryParameters() { var action = new Action( 0, "GET", "/users/{userId}", "queryUser(String userId)", null); var uri = "/users/1234567?one=1.1&two=2.0&three=three*&three=3.3".ToMatchableUri(); var matchResults = action.MatchWith(Method.Get, uri); Assert.True(matchResults.IsMatched); Assert.Same(action, matchResults.Action); Assert.Equal(1, matchResults.ParameterCount); Assert.Equal("1234567", matchResults.Parameters[0].Value); var queryParameters = new QueryParameters(uri.Query); Assert.Equal(3, queryParameters.Names.Count); Assert.Equal(1, queryParameters.ValuesOf("one").Count); Assert.Equal("1.1", queryParameters.ValuesOf("one")[0]); Assert.Equal(1, queryParameters.ValuesOf("two").Count); Assert.Equal("2.0", queryParameters.ValuesOf("two")[0]); Assert.Equal(2, queryParameters.ValuesOf("three").Count); Assert.Equal("three*", queryParameters.ValuesOf("three")[0]); Assert.Equal("3.3", queryParameters.ValuesOf("three")[1]); }
public void TestMatchesNoParameters() { var action = new Action(0, "GET", "/users", "QueryUsers()", null); var matchResults = action.MatchWith(Method.Get, "/users".ToMatchableUri()); Assert.True(matchResults.IsMatched); Assert.Equal(0, matchResults.ParameterCount); Assert.Same(action, matchResults.Action); }
public void TestMatchEmptyParamGivenAllowsTrailingSlash() { var action = new Action(0, "GET", "/users/{id}", "queryUsers(String userId)", null); var matchResults = action.MatchWith(Method.Get, "/users//".ToMatchableUri()); Assert.True(matchResults.IsMatched); Assert.Same(action, matchResults.Action); Assert.Equal(1, matchResults.ParameterCount); }
public void TestNoMatchEmptyParam() { var action = new Action(0, "GET", "/users/{id}/data", "queryUserData(String userId)", null); var matchResults = action.MatchWith(Method.Get, "/users//data".ToMatchableUri()); Assert.False(matchResults.IsMatched); Assert.Same(action, matchResults.Action); Assert.Equal(0, matchResults.ParameterCount); }
public void TestNoMatchGivenAdditionalElements() { var action = new Action(0, "GET", "/users/{id}", "queryUsers(String userId)", null); var matchResults = action.MatchWith(Method.Get, "/users/1234/extra".ToMatchableUri()); Assert.False(matchResults.IsMatched); Assert.Null(matchResults.Action); Assert.Equal(0, matchResults.ParameterCount); }
public void TestNoMatchNoParameters() { var action = new Action(0, "GET", "/users/all", "queryUsers()", null); var matchResults = action.MatchWith(Method.Get, "/users/one".ToMatchableUri()); Assert.False(matchResults.IsMatched); Assert.Null(matchResults.Action); Assert.Equal(0, matchResults.ParameterCount); }
public void TestMatchesOneParameterWithEndSlash() { var action = new Action(0, "GET", "/users/{userId}/", "QueryUser(string userId)", null); var matchResults = action.MatchWith(Method.Get, "/users/1234567/".ToMatchableUri()); Assert.True(matchResults.IsMatched); Assert.Same(action, matchResults.Action); Assert.Equal(1, matchResults.ParameterCount); Assert.Equal("userId", matchResults.Parameters[0].Name); Assert.Equal("1234567", matchResults.Parameters[0].Value); }
public void TestMatchesOneParameterInBetween() { var action = new Action(0, "PATCH", "/users/{userId}/name", "ChangeName(string userId)", null); var matchResults = action.MatchWith(Method.Patch, "/users/1234567/name".ToMatchableUri()); Assert.True(matchResults.IsMatched); Assert.Same(action, matchResults.Action); Assert.Equal(1, matchResults.ParameterCount); Assert.Equal("userId", matchResults.Parameters[0].Name); Assert.Equal("1234567", matchResults.Parameters[0].Value); }
public void TestThatWrongIdOrderBreaks() { var actionPostUser = new Action(3, "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 actions = new List <Action> { actionPostUser, actionPatchUserContact }; var resourceHandlerClass = ConfigurationResource.NewResourceHandlerTypeFor("Vlingo.Xoom.Http.Tests.Sample.User.UserResource"); Assert.Throws <ArgumentException>(() => ConfigurationResource.NewResourceFor("user", resourceHandlerClass, 5, actions, ConsoleLogger.TestInstance())); }
public void TestNoMatchMultipleParametersMissingSlash() { var action = new Action( 0, "GET", "/users/{userId}/emailAddresses/{emailAddressId}/", "queryUserEmailAddress(String userId, String emailAddressId)", null); var matchResults = action.MatchWith(Method.Get, "/users/1234567/emailAddresses/890".ToMatchableUri()); Assert.False(matchResults.IsMatched); Assert.Null(matchResults.Action); Assert.Equal(0, matchResults.ParameterCount); }
public void TestWeirdMatchMultipleParametersNoSlash() { var action = new Action( 0, "GET", "/users/{userId}/emailAddresses/{emailAddressId}", "queryUserEmailAddress(String userId, String emailAddressId)", null); var matchResults = action.MatchWith(Method.Get, "/users/1234567/emailAddresses/890/".ToMatchableUri()); Assert.True(matchResults.IsMatched); Assert.Same(action, matchResults.Action); Assert.Equal(2, matchResults.ParameterCount); Assert.NotEqual("890", matchResults.Parameters[1].Value); Assert.Equal("890/", matchResults.Parameters[1].Value); // TODO: may watch for last "/" or add optional configuration }
public void TestMatchesMultipleParametersWithEndSlash() { var action = new Action( 0, "GET", "/users/{userId}/emailAddresses/{emailAddressId}/", "queryUserEmailAddress(String userId, String emailAddressId)", null); var matchResults = action.MatchWith(Method.Get, "/users/1234567/emailAddresses/890/".ToMatchableUri()); Assert.True(matchResults.IsMatched); Assert.Same(action, matchResults.Action); Assert.Equal(2, matchResults.ParameterCount); Assert.Equal("userId", matchResults.Parameters[0].Name); Assert.Equal("1234567", matchResults.Parameters[0].Value); Assert.Equal("emailAddressId", matchResults.Parameters[1].Name); Assert.Equal("890", matchResults.Parameters[1].Value); }
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 void TestMatchesMultipleParameters() { var action = new Action( 0, "GET", "/catalogs/{catalogId}/products/{productId}/details/{detailId}", "queryCatalogProductDetails(String catalogId, String productId, String detailId)", null); var matchResults = action.MatchWith(Method.Get, "/catalogs/123/products/4567/details/890".ToMatchableUri()); Assert.True(matchResults.IsMatched); Assert.Same(action, matchResults.Action); Assert.Equal(3, matchResults.ParameterCount); Assert.Equal("catalogId", matchResults.Parameters[0].Name); Assert.Equal("123", matchResults.Parameters[0].Value); Assert.Equal("productId", matchResults.Parameters[1].Name); Assert.Equal("4567", matchResults.Parameters[1].Value); Assert.Equal("detailId", matchResults.Parameters[2].Name); Assert.Equal("890", matchResults.Parameters[2].Value); }
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()); }