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); }
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); }
public void HomePageUrlWithEmptyOutputFolder() { CodeModelTS codeModel = new CodeModelTS(); codeModel.OutputFolder = ""; Assert.Equal("https://github.com/azure/azure-sdk-for-js", codeModel.HomePageUrl); }
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()); }
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); }
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); }
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); }
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()); }
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); }
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); }
public void GenerateServiceClientImportsWithEmptyCodeModel() { CodeModelTS codeModel = CreateCodeModel(); AssertEx.EqualLines( new[] { "import * as msRest from \"ms-rest-js\";", "import { Context } from \"./context\";" }, codeModel.GenerateServiceClientImports()); }
public void GenerateServiceClientImportsWithEmptyCodeModel() { CodeModelTS codeModel = CreateCodeModel(); AssertEx.EqualLines( new[] { "import * as coreHttp from \"@azure/core-http\";", "import { Context } from \"./context\";" }, codeModel.GenerateServiceClientImports()); }
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); }
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); }
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()); }
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); }
public void HomePageUrlWithEmptyOutputFolder() { CodeModelTS codeModel = CreateCodeModel(""); Assert.AreEqual("https://github.com/azure/azure-sdk-for-js", codeModel.HomePageUrl); }
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); }
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); }