public void GetHttpMethodShouldReturnHttpMethodDeleteForMethodAttributedWithHttpDelete() { // arrange & act & assert HttpControllerHelper .GetHttpMethod(typeof(PersonController).GetMethod(nameof(PersonController.AttributedDelete))) .ShouldBeEquivalentTo(HttpMethod.Delete); }
public void GetHttpMethodShouldReturnHttpMethodPostForMethodAttributedWithHttpPost() { // arrange & act & assert HttpControllerHelper .GetHttpMethod(typeof(PersonController).GetMethod(nameof(PersonController.AddChild))) .ShouldBeEquivalentTo(HttpMethod.Post); }
public void GetRouteTemplateShouldWorkForAttributedClassAndAttributedMethod() { // arrange var method = typeof(TestControllerWithAttribute).GetMethod(nameof(TestControllerWithAttribute.DoSomethingWithAttribute)); // act & assert HttpControllerHelper .GetRouteTemplate(method) .ShouldBeEquivalentTo("test/dont-do-anything"); }
public void GetRouteTemplateShouldWorkForUnattributedClassAndUnattributedMethodWithId() { // arrange var method = typeof(TestController).GetMethod(nameof(TestController.DoSomethingWithId)); // act & assert HttpControllerHelper .GetRouteTemplate(method) .ShouldBeEquivalentTo("test/{id}"); }
public void GetHttpMethodShouldReturnHttpMethodGetAsDefaultReturnType() { // arrange var methodMock = new Mock <MethodInfo>(); methodMock.SetupGet(m => m.Name).Returns("SomeObscureName"); // act & assert HttpControllerHelper .GetHttpMethod(methodMock.Object) .ShouldBeEquivalentTo(HttpMethod.Get); }
public void GetRouteTemplateShouldThrowExceptionWhenGivenMethodWithoutDeclaringType() { // arrange var methodMock = new Mock <MethodInfo>(); methodMock.SetupGet(m => m.Name).Returns("SomeObscureName"); Action action = () => HttpControllerHelper.GetRouteTemplate(methodMock.Object); // act & assert action .ShouldThrow <NullReferenceException>() .And.Message.Should().Be("DeclaringType can't be null"); }
public void GetActionShouldReturnDirectlyIfOnlyOneMethodFound() { // arrange var method = HttpMethod.Post; var source = typeof(TestController); var relation = "self"; var argumentsMock = new Mock <IDictionary <string, Argument> >(); // act & assert HttpControllerHelper .GetAction(source, relation, method, argumentsMock.Object) .Should().NotBeNull() .And.Match(m => m.Name == "Post"); }
public void GetActionShouldThrowExceptionWhenNoMethodFound() { // arrange var method = HttpMethod.Options; var source = typeof(TestController); var relation = "self"; var argumentsMock = new Mock <IDictionary <string, Argument> >(); Action action = () => HttpControllerHelper.GetAction(source, relation, method, argumentsMock.Object); // act & assert action .ShouldThrow <Exception>() .And.Message.Should().Be($"No suitable action found for {method} on {source.Name} (relation: {relation})"); }
public void GetActionShouldReturnParameterMatchingMethodIfMoreThanOneMethodFound() { // arrange var method = HttpMethod.Delete; var source = typeof(TestController); var relation = "self"; //var argumentsMock = new Mock<IDictionary<string, Argument>>(); //argumentsMock.SetupGet(a=>a.) var arguments = new Dictionary <string, Argument> { { "id", new Argument {/*Name = "id", */ IsTemplateArgument = false, Type = typeof(int), Value = 1 } } }; // act & assert HttpControllerHelper .GetAction(source, relation, method, arguments) .Should().NotBeNull() .And.Match(m => m.Name == "Delete"); }
public void GetActionShouldThrowExceptionIfMoreThanOneMethodWithMatchingParametersAndMethodFound() { // arrange var method = HttpMethod.Delete; var source = typeof(TestController); var relation = "self"; var arguments = new Dictionary <string, Argument> { { "id", new Argument { Name = "id", Origin = "id", IsTemplateArgument = false, Type = typeof(int), Value = 1 } } }; Action action = () => HttpControllerHelper .GetAction(source, relation, method, arguments); // act & assert action .ShouldThrow <Exception>() .And.Message.Should().Be($"Unable to create relation 'self' There are multiple actions supporting DELETE on TestController, try specifying explicit by using Delete<TestController>(p => p.Delete) or Delete<TestController>(p => p.DeleteWithCorrespondingParamter)"); }
public void GetHttpMethodShouldReturnCorrectHttpMethodNamedMethod() { // arrange var methodNames = new[] { new { name = "Get", method = HttpMethod.Get }, new { name = "Post", method = HttpMethod.Post }, new { name = "Put", method = HttpMethod.Put }, new { name = "Delete", method = HttpMethod.Delete }, }; foreach (var pair in methodNames) { // arrange var methodMock = new Mock <MethodInfo>(); methodMock.SetupGet(m => m.Name).Returns(pair.name); // act & assert HttpControllerHelper .GetHttpMethod(methodMock.Object) .ShouldBeEquivalentTo(pair.method); } }