public void Generates_one_Attribute()
        {
            var attributes = new[]
            {
                new AuthorizeAttribute {
                    AuthenticationSchemes = "sch.1", Policy = "p.1", Roles = "r.1"
                }
            };

            var result = AttributeCodeGenerator.GenerateAttributes(attributes);

            result.Should().Contain("[global::Microsoft.AspNetCore.Authorization.Authorize(Roles = \"r.1\", Policy = \"p.1\", AuthenticationSchemes = \"sch.1\")]");
        }
Exemplo n.º 2
0
        public GeneratedMethod GenerateMethod(string codeTemplate, string methodName, Type request, Type response, HandlerInfo handlerInfo)
        {
            var attributes = AttributeCodeGenerator.GenerateAttributes(handlerInfo.AuthorizeAttributes);

            string code = codeTemplate
                          .Replace(Tag.Attributes, attributes, StringComparison.Ordinal)
                          .Replace(Tag.Method, methodName, StringComparison.Ordinal)
                          .Replace(Tag.Request, request.GetFullClassName(), StringComparison.Ordinal)
                          .Replace(Tag.Response, response.GetFullClassName(), StringComparison.Ordinal)
                          .Replace(Tag.Handler, handlerInfo.Handler.GetFullClassName(), StringComparison.Ordinal);

            return(new GeneratedMethod(handlerInfo.Handler, request, response, code));
        }
Exemplo n.º 3
0
        private string GenerateClassSource(IEnumerable <GeneratedMethod> methods, string className, string baseClassName)
        {
            var attributes = AttributeCodeGenerator.GenerateAttributes(_configuration.GlobalAuthorizeAttributes);

            var members = Code.ConstructorCode
                          .Replace(Tag.Constructor, className, StringComparison.Ordinal)
                          +
                          string.Concat(methods.Select(m => m.Code));

            var classSource = Code.ClassCode
                              .Replace(Tag.Attributes, attributes, StringComparison.Ordinal)
                              .Replace(Tag.Class, className, StringComparison.Ordinal)
                              .Replace(Tag.BaseClass, baseClassName, StringComparison.Ordinal)
                              .Replace(Tag.Members, members, StringComparison.Ordinal);

            return(classSource);
        }