Exemplo n.º 1
0
        public void IsMatch_WithEmpty_MatchesMethodWithNoParameters()
        {
            // Arrange
            var method           = typeof(TestController).GetMethod(nameof(TestController.SearchEmpty));
            var conventionMethod = typeof(TestConvention).GetMethod(nameof(TestConvention.SearchWithParams));

            // Act
            var result = ApiConventionMatcher.IsMatch(method, conventionMethod);

            // Assert
            Assert.True(result);
        }
Exemplo n.º 2
0
        public void IsMatch_ReturnsTrue_IfParamsArrayMatchesRemainingArguments()
        {
            // Arrange
            var method           = typeof(TestController).GetMethod(nameof(TestController.Search));
            var conventionMethod = typeof(TestConvention).GetMethod(nameof(TestConvention.Search));

            // Act
            var result = ApiConventionMatcher.IsMatch(method, conventionMethod);

            // Assert
            Assert.True(result);
        }
Exemplo n.º 3
0
        public void IsMatch_ReturnsTrue_IfMethodNameAndParametersMatchs()
        {
            // Arrange
            var method           = typeof(TestController).GetMethod(nameof(TestController.Get));
            var conventionMethod = typeof(TestConvention).GetMethod(nameof(TestConvention.Get));

            // Act
            var result = ApiConventionMatcher.IsMatch(method, conventionMethod);

            // Assert
            Assert.True(result);
        }
Exemplo n.º 4
0
        public void IsMatch_ReturnsFalse_IfParametersDoNotMatch()
        {
            // Arrange
            var method           = typeof(TestController).GetMethod(nameof(TestController.Get));
            var conventionMethod = typeof(TestConvention).GetMethod(nameof(TestConvention.GetParameterNotMatching));

            // Act
            var result = ApiConventionMatcher.IsMatch(method, conventionMethod);

            // Assert
            Assert.False(result);
        }
Exemplo n.º 5
0
        public void IsMatch_ReturnsFalse_IfMethodHasFewerParametersThanConvention()
        {
            // Arrange
            var method           = typeof(TestController).GetMethod(nameof(TestController.Get));
            var conventionMethod = typeof(TestConvention).GetMethod(nameof(TestConvention.GetTwoArgs));

            // Act
            var result = ApiConventionMatcher.IsMatch(method, conventionMethod);

            // Assert
            Assert.False(result);
        }
Exemplo n.º 6
0
        private static MethodInfo GetConventionMethod(MethodInfo method, Type conventionType)
        {
            foreach (var conventionMethod in conventionType.GetMethods(BindingFlags.Public | BindingFlags.Static))
            {
                if (ApiConventionMatcher.IsMatch(method, conventionMethod))
                {
                    return(conventionMethod);
                }
            }

            return(null);
        }
Exemplo n.º 7
0
        private static MethodInfo GetConventionMethod(MethodInfo method, ApiConventionTypeAttribute[] apiConventionAttributes)
        {
            foreach (var attribute in apiConventionAttributes)
            {
                var conventionMethods = attribute.ConventionType.GetMethods(BindingFlags.Public | BindingFlags.Static);
                foreach (var conventionMethod in conventionMethods)
                {
                    if (ApiConventionMatcher.IsMatch(method, conventionMethod))
                    {
                        return(conventionMethod);
                    }
                }
            }

            return(null);
        }