public void InheritanceExample() { var scripter = new TypeScripter.Scripter(); var output = scripter .AddType(typeof(Mammal)) .ToString(); ValidateTypeScript(output); }
public void CanOutputEnums() { var scripter = new TypeScripter.Scripter(); var output = scripter .AddType(typeof(Person)) .ToString(); ValidateTypeScript(output); }
public void GenericsExample() { var scripter = new TypeScripter.Scripter(); var output = scripter .AddType(typeof(MammalZoo)) .ToString(); ValidateTypeScript(output); }
public void BasicUsageExample() { var scripter = new TypeScripter.Scripter(); var output = scripter .AddType(typeof(Animal)) .ToString(); ValidateTypeScript(output); }
public void TestThatEnumIsRendered() { var scripter = new TypeScripter.Scripter(); var output = scripter .AddType(typeof(Person)) .ToString(); Assert.True(output.Contains("Female")); Assert.True(output.Contains("Male")); Assert.True(output.Contains("Unknown")); Assert.True(output.Contains("sex: TypeScripter.Tests.Sex")); }
public void TestThatNullableTypeIsRendered() { var scripter = new TypeScripter.Scripter(); var output = scripter .AddType(typeof(TypeWithNullables)) .ToString(); Assert.True(output.Contains("const enum Enum1"), "Underlaying enum should be resolved"); Assert.True(output.Contains("IntProperty?: number")); Assert.True(output.Contains("LongField?: number")); Assert.True(output.Contains("Property1?: TypeScripter.Tests.Enum1")); }
public void TestThatEnumIsRenderedAsString() { var scripter = new TypeScripter.Scripter(); var output = scripter .UsingFormatter(new TsFormatter { EnumsAsString = true }) .AddType(typeof(Person)) .ToString(); Assert.True(output.Contains("type Sex = 'Female' | 'Male' | 'Unknown'")); Assert.True(output.Contains("sex: TypeScripter.Tests.Sex;")); }
public void TestThatDictionaryIsRendered() { var scripter = new TypeScripter.Scripter(); var output = scripter .AddType(typeof(Order)) .ToString(); // we want to descent to generic type Assert.True(output.Contains("OrderLineItem")); ValidateTypeScript(output); // inline interfaces for dictionaries are generated Assert.True(output.Contains("LinesByIndex: {[key: number]: TypeScripter.Tests.OrderLineItem;}")); Assert.True(output.Contains("OrderLines: {[key: string]: TypeScripter.Tests.OrderLineItem;}")); Assert.True(output.Contains("SimpleDict1: {[key: string]: string;}")); Assert.True(output.Contains("SimpleDict2: {[key: number]: number;}")); Assert.True(output.Contains("SimpleDict3: TypeScripter.Tests.OrderDictionary;")); }
private List<string> GenerateFiles(Assembly Assembly, string InputNamespace, string OutputPath, string TSModule, bool IgnoreFunctions = false) { if (!Directory.Exists(OutputPath)) { Directory.CreateDirectory(OutputPath); } var scripter = new TypeScripter.Scripter(); scripter.IgnoreFunctions = IgnoreFunctions; scripter.UsingAssembly(Assembly); scripter.UsingTypeFilter(t => t.Namespace == InputNamespace && t.GetCustomAttribute(typeof(Newtonsoft.Json.JsonObjectAttribute)) != null); scripter.AddTypes(Assembly); var _modules = scripter.Modules().SelectMany(x => x.Types.Select(y => y.Name.ToString())); scripter.SaveToDirectory(OutputPath); return _modules.ToList(); }
public void EnumValueIsValidated() { var scripter = new TypeScripter.Scripter(); var output = scripter .UsingFormatter(new TsFormatter { EnumsAsString = true }) .AddType(typeof(Person)) .ToString(); var code = "\n var x: TypeScripter.Tests.Person; \n" + "x.sex = 'test'"; AssertNotValidTypeScript(output + code); code = "\n var x: TypeScripter.Tests.Person; \n" + "x.sex = 'Female'"; ValidateTypeScript(output + code); }