public void TestRefactGamerInterface() { var classDefinition = new TypeScriptClassDefinition { Name = "Person", Fields = { new FieldDefinition(AccessModifier.Public, "number", "id"), new FieldDefinition(AccessModifier.Public, "string", "firstName"), new FieldDefinition(AccessModifier.Public, "string", "middleName"), new FieldDefinition(AccessModifier.Public, "string", "lastName"), new FieldDefinition(AccessModifier.Public, "string", "gender"), new FieldDefinition(AccessModifier.Public, "Date", "birthDate") } }; var interfaceDefinition = classDefinition.RefactInterface(); TypeScriptClassBuilder.CreateFiles("C:\\Temp\\CatFactory.TypeScript", string.Empty, true, classDefinition); TypeScriptInterfaceBuilder.CreateFiles("C:\\Temp\\CatFactory.TypeScript", string.Empty, true, interfaceDefinition); Assert.True(classDefinition.Properties.Count == interfaceDefinition.Properties.Count); Assert.True(interfaceDefinition.Methods.Count == 0); }
public void ScaffoldServiceClass() { var definition = new TypeScriptClassDefinition { Export = true, Name = "Service", Fields = { new FieldDefinition(AccessModifier.Protected, "string", "url") { Documentation = new Documentation("Gets or sets the url") } }, Constructors = { new TypeScriptClassConstructorDefinition { Documentation = new Documentation("Initializes a new instance of Service class"), Lines = { new CodeLine("this.url = 'http://localhost:1234/api/v1';") } } } }; foreach (var filePath in TypeScriptClassBuilder.CreateFiles("C:\\Temp\\CatFactory.TypeScript", string.Empty, true, definition)) { Process.Start(ScaffoldingPaths.TscPath, string.Format("{0} --outDir {1}", Path.Combine(ScaffoldingPaths.TsFilesPath, filePath), ScaffoldingPaths.OutPath)); } }
public void TestRefactInterface() { var classDefinition = new TypeScriptClassDefinition { Name = "Gamer", Implements = { "IGamer" } }; classDefinition.AddImport("IGamer", "./IGamer"); classDefinition.Fields.Add(new FieldDefinition("string", "m_firstName")); classDefinition.Fields.Add(new FieldDefinition("string", "m_middleName")); classDefinition.Fields.Add(new FieldDefinition("string", "m_lastName")); classDefinition.Properties.Add(new PropertyDefinition("string", "firstName")); classDefinition.Properties.Add(new PropertyDefinition("string", "middleName")); classDefinition.Properties.Add(new PropertyDefinition("string", "lastName")); TypeScriptClassBuilder.CreateFiles("C:\\Temp\\CatFactory.TypeScript", string.Empty, true, classDefinition); var interfaceDefinition = classDefinition.RefactInterface(); TypeScriptInterfaceBuilder.CreateFiles("C:\\Temp\\CatFactory.TypeScript", string.Empty, true, interfaceDefinition); }
public void TestTypeScriptBaseClassGeneration() { var definition = new TypeScriptClassDefinition { Name = "Entity" }; TypeScriptClassBuilder.CreateFiles("C:\\Temp\\CatFactory.TypeScript", string.Empty, true, definition); }
public void TestRefactClass() { var definition = (new Customer()).RefactClass(); definition.Documentation.Summary = "Refacted from Customer class definition"; foreach (var filePath in TypeScriptClassBuilder.CreateFiles("C:\\Temp\\CatFactory.TypeScript", string.Empty, true, definition)) { Process.Start(ScaffoldingPaths.TscPath, string.Format("{0} --outDir {1}", Path.Combine(ScaffoldingPaths.TsFilesPath, filePath), ScaffoldingPaths.OutPath)); } }
public void ScaffoldWarehouseServiceClass() { var definition = new TypeScriptClassDefinition { Documentation = new Documentation("Provides methods to invoke Warehouse controller in OnLineStore Web API"), Name = "WarehouseService", BaseClass = "Service", Constructors = { new TypeScriptClassConstructorDefinition { Documentation = new Documentation("Initializes a new instance of WarehouseService class"), Lines = { new CodeLine("super();") } } }, Methods = { new MethodDefinition("Response", "getProducts", new ParameterDefinition("string", "productName") { Documentation = new Documentation("Name for product") }) { Documentation = new Documentation("Retrieves products from warehouse"), Lines = { new TodoLine("Apply productName parameter to filter products by product name"), new CodeLine(), new CodeLine("return new Response();") } }, new MethodDefinition("Response", "getProduct", new ParameterDefinition("Product", "entity")) { Lines = { new TodoLine("Search product by id"), new CodeLine(), new CodeLine("return new Response();") } } } }; definition.AddImport("Response", "./Response"); definition.AddImport("Service", "./Service"); definition.AddImport("Product", "./Product"); foreach (var filePath in TypeScriptClassBuilder.CreateFiles("C:\\Temp\\CatFactory.TypeScript", string.Empty, true, definition)) { Process.Start(ScaffoldingPaths.TscPath, string.Format("{0} --outDir {1}", Path.Combine(ScaffoldingPaths.TsFilesPath, filePath), ScaffoldingPaths.OutPath)); } }
public void ScaffoldResponseClass() { var definition = new TypeScriptClassDefinition { Name = "Response" }; foreach (var filePath in TypeScriptClassBuilder.CreateFiles("C:\\Temp\\CatFactory.TypeScript", string.Empty, true, definition)) { Process.Start(ScaffoldingPaths.TscPath, string.Format("{0} --outDir {1}", Path.Combine(ScaffoldingPaths.TsFilesPath, filePath), ScaffoldingPaths.OutPath)); } }
public void TestTypeScriptClassWithReadOnlyFieldsGeneration() { var definition = new TypeScriptClassDefinition { Name = "Tokens" }; definition.AddConstant("number", "foo", "123"); definition.AddConstant("string", "bar", "\"hello\""); definition.AddConstant("string", "zaz", "\"ABCDEF\""); TypeScriptClassBuilder.CreateFiles("C:\\Temp\\CatFactory.TypeScript", string.Empty, true, definition); }
public void TestTypeScriptClassWithPropertiesAndMethodsGeneration() { var definition = new TypeScriptClassDefinition { Namespace = "School", Name = "Student" }; definition.Fields.Add(new FieldDefinition("string", "m_firstName")); definition.Fields.Add(new FieldDefinition("string", "m_middleName")); definition.Fields.Add(new FieldDefinition("string", "m_lastName")); definition.Fields.Add(new FieldDefinition("string", "m_gender")); definition.Fields.Add(new FieldDefinition("Date", "m_birthDate")); definition.Fields.Add(new FieldDefinition("string", "m_fullName")); definition.Fields.Add(new FieldDefinition("number", "m_age")); definition.Properties.Add(new PropertyDefinition("string", "firstName")); definition.Properties.Add(new PropertyDefinition("string", "middleName")); definition.Properties.Add(new PropertyDefinition("string", "lastName")); definition.Properties.Add(new PropertyDefinition("string", "gender")); definition.Properties.Add(new PropertyDefinition("Date", "birthDate")); definition.Properties.Add(new PropertyDefinition("string", "fullName")); definition.Properties.Add(new PropertyDefinition("number", "age")); definition.Methods.Add(new MethodDefinition("boolean", "equals", new ParameterDefinition("any", "obj")) { Lines = { new CodeLine("return false;") } }); definition.Methods.Add(new MethodDefinition("number", "getHashCode") { Lines = { new CodeLine("return 0;") } }); definition.Methods.Add(new MethodDefinition("string", "tostring") { Lines = { new CodeLine("return '';") } }); TypeScriptClassBuilder.CreateFiles("C:\\Temp\\CatFactory.TypeScript", string.Empty, true, definition); }
public void TestTypeScriptClassWithPropertiesGeneration() { var definition = new TypeScriptClassDefinition { Namespace = "HumanResources", Name = "Employee" }; definition.Properties.Add(new PropertyDefinition("string", "firstName")); definition.Properties.Add(new PropertyDefinition("string", "middleName")); definition.Properties.Add(new PropertyDefinition("string", "lastName")); definition.Properties.Add(new PropertyDefinition("string", "gender")); definition.Properties.Add(new PropertyDefinition("Date", "birthDate")); TypeScriptClassBuilder.CreateFiles("C:\\Temp\\CatFactory.TypeScript", string.Empty, true, definition); }
public void TestTypeScriptClassServiceGeneration() { var definition = new TypeScriptClassDefinition { Name = "NorthwindService" }; definition.Attributes.Add(new MetadataAttribute("Injectable")); definition.AddImport("Injectable", "@angular/core"); definition.AddImport(new string[] { "Http", "Response" }, "@angular/http"); definition.AddImport("Observable", "rxjs/Observable"); definition.Constructors.Add(new ClassConstructorDefinition(new ParameterDefinition("Http", "http")) { Lines = new List <ILine>() { new CodeLine("this.api = \"{0}\";", "api/Northwind") } }); definition.Fields.Add(new FieldDefinition("string", "api")); definition.Methods.Add(new MethodDefinition("Observable<Response>", "getOrders", new ParameterDefinition("number", "pageNumber"), new ParameterDefinition("number", "pageSize")) { Lines = new List <ILine>() { new CodeLine("var url = [this.api, \"Sales\", \"Order\"].join(\"/\");"), new CodeLine(), new CodeLine("return this.http.get(url);") } }); definition.Methods.Add(new MethodDefinition("Observable<Response>", "getOrder", new ParameterDefinition("number", "id")) { Lines = new List <ILine>() { new CodeLine("var url = [this.api, \"Sales\", \"Order\", id].join(\"/\");"), new CodeLine(), new CodeLine("return this.http.get(url);") } }); TypeScriptClassBuilder.CreateFiles("C:\\Temp\\CatFactory.TypeScript", string.Empty, true, definition); }
public void TestRefactAnonymous() { var definition = new { ID = 0, Name = "", UnitPrice = 0m, ReleaseDate = DateTime.Now, Description = "" } .RefactClass(name: "Anonymous", convertPropertiesToFields: false); definition.Documentation.Summary = "Refacted from anonymous definition"; foreach (var filePath in TypeScriptClassBuilder.CreateFiles("C:\\Temp\\CatFactory.TypeScript", string.Empty, true, definition)) { Process.Start(ScaffoldingPaths.TscPath, string.Format("{0} --outDir {1}", Path.Combine(ScaffoldingPaths.TsFilesPath, filePath), ScaffoldingPaths.OutPath)); } }
public void TestTypeScriptClassWithFieldsGeneration() { var definition = new TypeScriptClassDefinition { Documentation = new Documentation("Represents a product in wharehouse"), Name = "Product", Fields = { new FieldDefinition(AccessModifier.Public, "number", "id"), new FieldDefinition(AccessModifier.Public, "string", "productName"), new FieldDefinition(AccessModifier.Public, "number", "categoryId"), new FieldDefinition(AccessModifier.Public, "string", "unitPrice"), new FieldDefinition(AccessModifier.Public, "string", "description"), new FieldDefinition(AccessModifier.Public, "string", "tags"), new FieldDefinition(AccessModifier.Public, "Date", "releaseDate") } }; foreach (var filePath in TypeScriptClassBuilder.CreateFiles("C:\\Temp\\CatFactory.TypeScript", string.Empty, true, definition)) { Process.Start(ScaffoldingPaths.TscPath, string.Format("{0} --outDir {1}", Path.Combine(ScaffoldingPaths.TsFilesPath, filePath), ScaffoldingPaths.OutPath)); } }
public void TestTypeScriptClassWithFieldsGeneration() { var definition = new TypeScriptClassDefinition { Namespace = "ContactManager", Name = "Contact", BaseClass = "Entity", Implements = new List <string>() { "IContact" } }; definition.AddImport("IContact", "./IContact"); definition.Fields.Add(new FieldDefinition("string", "firstName")); definition.Fields.Add(new FieldDefinition("string", "middleName")); definition.Fields.Add(new FieldDefinition("string", "lastName")); definition.Fields.Add(new FieldDefinition("string", "gender")); definition.Fields.Add(new FieldDefinition("Date", "birthDate")); TypeScriptClassBuilder.CreateFiles("C:\\Temp\\CatFactory.TypeScript", string.Empty, true, definition); }
public void TestRefactClass() { var definition = (new Customer()).RefactClass(); TypeScriptClassBuilder.CreateFiles("C:\\Temp\\CatFactory.TypeScript", string.Empty, true, definition); }
public void TestTypeScriptClassComponentGeneration() { var definition = new TypeScriptClassDefinition { Name = "OrderListComponent", Implements = new List <string>() { "OnInit" } }; definition.AddImport(new string[] { "Component", "Injectable", "OnInit" }, "@angular/core"); definition.AddImport("Router", "@angular/router"); definition.AddImport("SalesService", "../../services/sales.service"); definition.AddImport("OrderSummary", "../../models/order.summary"); definition.AddImport("IListResponse", "../../responses/list.response"); definition.Attributes.Add(new MetadataAttribute("Component") { Sets = new List <MetadataAttributeSet>() { new MetadataAttributeSet("selector", "\"order-list\""), new MetadataAttributeSet("template", "require(\"./order-list.component.html\")") } }); definition.Constructors.Add(new ClassConstructorDefinition( new ParameterDefinition("Router", "router"), new ParameterDefinition("SalesService", "service")) ); definition.Fields.Add(new FieldDefinition("number", "pageSize")); definition.Fields.Add(new FieldDefinition("number", "pageNumber")); definition.Fields.Add(new FieldDefinition("string", "salesOrderNumber")); definition.Fields.Add(new FieldDefinition("string", "customerName")); definition.Fields.Add(new FieldDefinition("IListResponse<OrderSummary>", "result")); definition.Methods.Add(new MethodDefinition("void", "ngOnInit") { Lines = new List <ILine>() { new TodoLine("Add logic for this operation") } }); definition.Methods.Add(new MethodDefinition("void", "search") { Lines = new List <ILine>() { new TodoLine("Add logic for this operation") } }); definition.Methods.Add(new MethodDefinition("void", "details", new ParameterDefinition("OrderSummary", "order")) { Lines = new List <ILine>() { new TodoLine("Add logic for this operation") } }); TypeScriptClassBuilder.CreateFiles("C:\\Temp\\CatFactory.TypeScript", string.Empty, true, definition); }
public void TestRefactAnonymous() { var definition = (new { ID = 0, Name = "", Description = "" }).RefactClass(name: "Anonymous"); TypeScriptClassBuilder.CreateFiles("C:\\Temp\\CatFactory.TypeScript", string.Empty, true, definition); }