コード例 #1
0
        public void HomePageUrlWithBackslashOutputFolderThatContainsAzureSdkForJs()
        {
            CodeModelTS codeModel = new CodeModelTS();

            codeModel.OutputFolder = "C:\\Users\\daschult\\Sources\\azure-sdk-for-js\\lib\\services\\batchManagement";
            Assert.Equal("https://github.com/azure/azure-sdk-for-js/lib/services/batchManagement", codeModel.HomePageUrl);
        }
コード例 #2
0
        public void GenerateOperationSpecWithDifferentRequestContentTypeThanCodeModel()
        {
            CodeModelTS codeModel = Models.CodeModel();

            Models.Method(codeModel: codeModel, requestContentType: "application/json");
            MethodTS method = Models.Method(codeModel: codeModel, requestContentType: "blah");

            Assert.AreNotEqual(method.RequestContentType, codeModel.RequestContentType);

            TSBuilder builder = GenerateOperationSpec(method);

            AssertEx.EqualLines(
                new[]
            {
                "{",
                "  httpMethod: \"GET\",",
                "  contentType: \"blah\",",
                "  responses: {",
                "    default: {}",
                "  },",
                "  serializer",
                "}"
            },
                builder);
        }
コード例 #3
0
        public void HomePageUrlWithEmptyOutputFolder()
        {
            CodeModelTS codeModel = new CodeModelTS();

            codeModel.OutputFolder = "";
            Assert.Equal("https://github.com/azure/azure-sdk-for-js", codeModel.HomePageUrl);
        }
コード例 #4
0
        public string GenerateMethodGroupImports()
        {
            TSBuilder builder = new TSBuilder();

            builder.ImportAllAs("coreHttp", "@azure/core-http");
            if (MethodTemplateModels.Any((MethodTS method) => method.IsLongRunningOperation))
            {
                builder.ImportAllAs("coreArm", "@azure/core-arm");
            }

            CodeModelTS codeModel = CodeModelTS;

            if (CodeGeneratorTS.ShouldWriteModelsFiles(codeModel))
            {
                if (ContainsCompositeOrEnumTypeInParametersOrReturnType() || MethodTemplateModels.Any(m => m.HasCustomHttpResponseType))
                {
                    builder.ImportAllAs("Models", "../models");
                }
                if (codeModel.HasMappers())
                {
                    builder.ImportAllAs("Mappers", $"../models/{MappersModuleName}");
                }
            }

            if (HasMappableParameters)
            {
                builder.ImportAllAs("Parameters", "../models/parameters");
            }

            builder.Import(new string[] { codeModel.ContextName }, $"../{codeModel.ContextName.ToCamelCase()}");

            return(builder.ToString());
        }
コード例 #5
0
        public void HomePageUrlWithOutputFolderThatDoesntContainAzureSdkForJs()
        {
            CodeModelTS codeModel = new CodeModelTS();

            codeModel.OutputFolder = "test/azure/generated/StorageManagementClient";
            Assert.Equal("https://github.com/azure/azure-sdk-for-js", codeModel.HomePageUrl);
        }
コード例 #6
0
        public void GenerateOperationSpecWithHeaderParameter()
        {
            CodeModelTS codeModel = Models.CodeModel();
            MethodTS    method    = Models.Method(
                codeModel: codeModel,
                requestContentType: "fake-content-type",
                parameters: new[] { Models.Parameter(name: "fakeParameterName", location: ParameterLocation.Header) });

            TSBuilder builder = GenerateOperationSpec(method);

            AssertEx.EqualLines(
                new[]
            {
                "{",
                "  httpMethod: \"GET\",",
                "  headerParameters: [",
                "    Parameters.fakeParameterName",
                "  ],",
                "  responses: {",
                "    default: {}",
                "  },",
                "  serializer",
                "}"
            },
                builder);
        }
コード例 #7
0
        public void GenerateOperationSpecWithFormDataParameterAndDifferentRequestContentTypeThanCodeModel()
        {
            CodeModelTS codeModel = Models.CodeModel();

            Models.Method(codeModel: codeModel, requestContentType: "application/json");
            MethodTS method = Models.Method(
                codeModel: codeModel,
                requestContentType: "fake-content-type",
                parameters: new[] { Models.Parameter(name: "fakeParameterName", location: ParameterLocation.FormData) });

            TSBuilder builder = GenerateOperationSpec(method);

            AssertEx.EqualLines(
                new[]
            {
                "{",
                "  httpMethod: \"GET\",",
                "  formDataParameters: [",
                "    Parameters.fakeParameterName",
                "  ],",
                "  contentType: \"fake-content-type\",",
                "  responses: {",
                "    default: {}",
                "  },",
                "  serializer",
                "}"
            },
                builder);
        }
コード例 #8
0
        public string GenerateOperationSpecDefinitions(string emptyLine)
        {
            TSBuilder builder = new TSBuilder();

            builder.LineComment("Operation Specifications");
            bool addedFirstValue = false;

            foreach (MethodTS method in MethodTemplateModels)
            {
                if (!method.IsLongRunningOperation)
                {
                    if (addedFirstValue)
                    {
                        builder.Line(emptyLine);
                    }
                    else
                    {
                        builder.ConstObjectVariable("serializer", CodeModelTS.CreateSerializerExpression());
                        addedFirstValue = true;
                    }
                    method.GenerateOperationSpecDefinition(builder);
                }
            }

            return(builder.ToString());
        }
コード例 #9
0
        public void HomePageUrlWithForwardSlashOutputFolderThatContainsAzureSdkForJs()
        {
            CodeModelTS codeModel = new CodeModelTS();

            codeModel.OutputFolder = "C:/Users/daschult/Sources/azure-sdk-for-js/lib/services/batchManagement";
            Assert.Equal("https://github.com/azure/azure-sdk-for-js/lib/services/batchManagement", codeModel.HomePageUrl);
        }
コード例 #10
0
        public void GenerateClassFieldsGeneratesProperlyOptionalPropertyDeclaration()
        {
            PropertyTS  property  = Models.Property("property", new PrimaryTypeTS(KnownPrimaryType.String));
            CodeModelTS codeModel = new CodeModelTS();

            codeModel.Add(property);

            string fieldsDeclaration = codeModel.GenerateClassProperties("");

            Assert.AreEqual("Property?: string;", fieldsDeclaration);
        }
コード例 #11
0
        public void GenerateServiceClientImportsWithEmptyCodeModel()
        {
            CodeModelTS codeModel = CreateCodeModel();

            AssertEx.EqualLines(
                new[]
            {
                "import * as msRest from \"ms-rest-js\";",
                "import { Context } from \"./context\";"
            },
                codeModel.GenerateServiceClientImports());
        }
コード例 #12
0
        public void GenerateServiceClientImportsWithEmptyCodeModel()
        {
            CodeModelTS codeModel = CreateCodeModel();

            AssertEx.EqualLines(
                new[]
            {
                "import * as coreHttp from \"@azure/core-http\";",
                "import { Context } from \"./context\";"
            },
                codeModel.GenerateServiceClientImports());
        }
コード例 #13
0
        public void GenerateClassFieldsSkipBaseClassProperties()
        {
            PropertyTS  stringProperty    = Models.Property("property-name", new PrimaryTypeTS(KnownPrimaryType.String));
            PropertyTS  baseClassProperty = Models.Property("user-agent-info", new PrimaryTypeTS(KnownPrimaryType.String));
            CodeModelTS codeModel         = new CodeModelTS();

            codeModel.Add(stringProperty);
            codeModel.Add(baseClassProperty);

            string fieldsDeclaration = codeModel.GenerateClassProperties("");

            Assert.AreEqual("PropertyName?: string;", fieldsDeclaration);
        }
コード例 #14
0
        public void GenerateClassFieldsGeneratesProperlyRequiredPropertyDeclaration()
        {
            PropertyTS property = Models.Property("property-name", new PrimaryTypeTS(KnownPrimaryType.String));

            property.IsRequired = true;
            CodeModelTS codeModel = new CodeModelTS();

            codeModel.Add(property);

            string fieldsDeclaration = codeModel.GenerateClassProperties("");

            Assert.AreEqual("PropertyName: string;", fieldsDeclaration);
        }
コード例 #15
0
        public void GenerateServiceClientImportsWithOneModelType()
        {
            CodeModelTS codeModel = CreateCodeModel(modelTypes: new[] { Models.CompositeType(name: "MyFakeType") });

            AssertEx.EqualLines(
                new[]
            {
                "import * as msRest from \"ms-rest-js\";",
                "import * as Models from \"./models\";",
                "import * as Mappers from \"./models/mappers\";",
                "import { Context } from \"./context\";"
            },
                codeModel.GenerateServiceClientImports());
        }
コード例 #16
0
        public void GenerateClassFieldsGeneratesMultiplePropertiesDeclaration()
        {
            PropertyTS stringProperty = Models.Property("property-name", new PrimaryTypeTS(KnownPrimaryType.String));
            PropertyTS boolProperty   = Models.Property("is-property", new PrimaryTypeTS(KnownPrimaryType.Boolean));
            PropertyTS intProperty    = Models.Property("numProperty", new PrimaryTypeTS(KnownPrimaryType.Int));

            boolProperty.IsRequired = true;
            CodeModelTS codeModel = new CodeModelTS();

            codeModel.Add(stringProperty);
            codeModel.Add(boolProperty);
            codeModel.Add(intProperty);

            string fieldsDeclaration = codeModel.GenerateClassProperties("");

            Assert.AreEqual("PropertyName?: string;\nIsProperty: boolean;\nNumProperty?: number;", fieldsDeclaration);
        }
コード例 #17
0
        public void HomePageUrlWithEmptyOutputFolder()
        {
            CodeModelTS codeModel = CreateCodeModel("");

            Assert.AreEqual("https://github.com/azure/azure-sdk-for-js", codeModel.HomePageUrl);
        }
コード例 #18
0
        public void HomePageUrlWithForwardSlashOutputFolderThatContainsAzureSdkForJsButEmptyPackageNameProperty()
        {
            CodeModelTS codeModel = CreateCodeModel("C:/Users/daschult/Sources/azure-sdk-for-js/packages/arm-batch", "");

            Assert.AreEqual("https://github.com/azure/azure-sdk-for-js/tree/master/packages/arm-batch", codeModel.HomePageUrl);
        }
コード例 #19
0
        public void HomePageUrlWithBackslashOutputFolderThatContainsAzureSdkForJs()
        {
            CodeModelTS codeModel = CreateCodeModel("C:\\Users\\daschult\\Sources\\azure-sdk-for-js\\packages\\arm-batch");

            Assert.AreEqual("https://github.com/azure/azure-sdk-for-js/tree/master/packages/arm-batch", codeModel.HomePageUrl);
        }