Exemplo n.º 1
0
 public void GetHttpMethodShouldReturnHttpMethodDeleteForMethodAttributedWithHttpDelete()
 {
     // arrange & act & assert
     HttpControllerHelper
     .GetHttpMethod(typeof(PersonController).GetMethod(nameof(PersonController.AttributedDelete)))
     .ShouldBeEquivalentTo(HttpMethod.Delete);
 }
Exemplo n.º 2
0
 public void GetHttpMethodShouldReturnHttpMethodPostForMethodAttributedWithHttpPost()
 {
     // arrange & act & assert
     HttpControllerHelper
     .GetHttpMethod(typeof(PersonController).GetMethod(nameof(PersonController.AddChild)))
     .ShouldBeEquivalentTo(HttpMethod.Post);
 }
Exemplo n.º 3
0
        public void GetRouteTemplateShouldWorkForAttributedClassAndAttributedMethod()
        {
            // arrange
            var method = typeof(TestControllerWithAttribute).GetMethod(nameof(TestControllerWithAttribute.DoSomethingWithAttribute));

            // act & assert
            HttpControllerHelper
            .GetRouteTemplate(method)
            .ShouldBeEquivalentTo("test/dont-do-anything");
        }
Exemplo n.º 4
0
        public void GetRouteTemplateShouldWorkForUnattributedClassAndUnattributedMethodWithId()
        {
            // arrange
            var method = typeof(TestController).GetMethod(nameof(TestController.DoSomethingWithId));

            // act & assert
            HttpControllerHelper
            .GetRouteTemplate(method)
            .ShouldBeEquivalentTo("test/{id}");
        }
Exemplo n.º 5
0
        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);
        }
Exemplo n.º 6
0
        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");
        }
Exemplo n.º 7
0
        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");
        }
Exemplo n.º 8
0
        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})");
        }
Exemplo n.º 9
0
        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");
        }
Exemplo n.º 10
0
        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)");
        }
Exemplo n.º 11
0
        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);
            }
        }