示例#1
0
        public void CanDealWithNestedNamespaces()
        {
            var builder = new TsModelBuilder();

            builder.Add <Person>();
            builder.Add <Drink>();

            var generator = new TsGenerator();

            generator.SetModuleNameFormatter(_ => "custom");//everything should go into the 'custom' module
            var model  = builder.Build();
            var result = generator.Generate(model);

            var expectedOutput = @"
declare module custom {
	interface Person {
		WhiteRussian: custom.Drink;
		AllDrinks: custom.Drink[];
	}
}
declare module custom {
	interface Drink {
	}
}
";

            Assert.Equal(expectedOutput, result);
        }
        public void CanDealWithNestedNamespaces()
        {
            var builder = new TsModelBuilder();
            builder.Add<Person>();
            builder.Add<Drink>();

            var generator = new TsGenerator();
            generator.SetModuleNameFormatter(_ => "custom");//everything should go into the 'custom' module
            var model = builder.Build();
            var result = generator.Generate(model);

            var expectedOutput = @"
            declare module custom {
            interface Person {
            WhiteRussian: custom.Drink;
            AllDrinks: custom.Drink[];
            }
            }
            declare module custom {
            interface Drink {
            }
            }
            ";

            Assert.Equal(expectedOutput, result);
        }
示例#3
0
        public void RespectsModuleNameFormatterOverrides()
        {
            var builder = new TsModelBuilder();

            builder.Add <DifferentNamespaces_Class2>();
            builder.Add <DifferentNamespaces_Class3>();

            var generator = new TsGenerator();

            // Reverse the order of the modules
            generator.SetModuleNameFormatter(m => m.Name == "TypeLitePlus.Tests.NetCore.TestModels.Namespace1" ? "modz" : "moda");
            var model = builder.Build();

            var result = generator.Generate(model);

            Assert.True(result.IndexOf("moda") < result.IndexOf("modz"), "Didn't order namespaces when formatters involved");
        }
        public void CanUseCustomFormatter()
        {
            var builder = new TsModelBuilder();
            builder.Add<Drink>();

            var generator = new TsGenerator();
            generator.SetModuleNameFormatter(_ => "custom");//everything should go into the 'custom' module
            var model = builder.Build();
            var result = generator.Generate(model);

            var expectedOutput = @"
            declare module custom {
            interface Drink {
            }
            }
            ";

            Assert.Equal(expectedOutput, result);
        }
示例#5
0
        private static string CompileModels(List <Type> types)
        {
            var builder = new TsModelBuilder();

            types.ForEach(a => builder.Add(a));

            var model = builder.Build();

            var generator = new TsGenerator();

            generator.IndentationString = "    ";
            generator.SetTypeVisibilityFormatter((tsClass, typeName) => true);
            generator.SetModuleNameFormatter((module) => "");
            generator.SetIdentifierFormatter((identifier) => Char.ToLower(identifier.Name[0]) + identifier.Name.Substring(1));

            string typeScript = generator.Generate(model);

            return(typeScript);
        }
示例#6
0
        public void CanUseCustomFormatter()
        {
            var builder = new TsModelBuilder();

            builder.Add <Drink>();

            var generator = new TsGenerator();

            generator.SetModuleNameFormatter(_ => "custom");//everything should go into the 'custom' module
            var model  = builder.Build();
            var result = generator.Generate(model);

            var expectedOutput = @"
declare module custom {
	interface Drink {
	}
}
";

            Assert.Equal(expectedOutput, result);
        }