Exemplo n.º 1
0
        public void TestClassGenericToIntf()
        {
            var rg = new ReflectionGenerator();

            rg.NamingStrategy.InterfacePrefixForClasses = "i";
            rg.GenerateInterface(typeof(PagedAminUser));
            rg.GenerateInterface(typeof(PagedCompany));

            var g = new OutputGenerator();

            g.Generate(rg.GenerationStrategy.TargetModule);
            Assert.AreEqual(
                @"
module GeneratedModule {
    interface iPagedModel<T> {
        TotalCount: number;
        Values: T[];
    }
    interface iPagedAminUser extends iPagedModel<iAdminUser> {
    }
    interface iAdminUser {
        Name: string;
        Login: string;
    }
    interface iPagedCompany extends iPagedModel<iCompanyModel> {
    }
    interface iCompanyModel {
        VAT: string;
        Name: string;
    }
}".Trim(), g.Output.Trim());
        }
Exemplo n.º 2
0
        public void TestGenerics2()
        {
            var rg = new ReflectionGenerator();

            rg.NamingStrategy.InterfacePrefixForClasses = "i";
            //nonsense?!? rg.GenerateInterface(typeof(Test1<int>));
            rg.GenerateInterface(typeof(Test1 <>));

            var g = new OutputGenerator();

            g.Generate(rg.GenerationStrategy.TargetModule);
            Assert.AreEqual(
                @"
module GeneratedModule {
    interface iTest1<T> {
        T1: iGenList<string>;
        T2: iGenList<number>;
        T3: iGenList<iGenList<boolean>>;
        T4: iGenList<T[]>[];
    }
    interface iGenList<TI> {
        Values: iGenTest<TI>[];
    }
    interface iGenTest<T> {
        Value: T;
    }
}".Trim(), g.Output.Trim());
        }
Exemplo n.º 3
0
        public void TestGenericsInstance()
        {
            var rg = new ReflectionGenerator();

            rg.NamingStrategy.InterfacePrefixForClasses = "i";
            rg.GenerateInterface(typeof(GenTest <int>));

            var g = new OutputGenerator();

            g.Generate(rg.GenerationStrategy.TargetModule);
            Assert.AreEqual(null, Helper.StringCompare(
                                @"
module GeneratedModule {
    interface iGenTest_Int32 {
        Value: number;
    }
}", g.Output));
        }
Exemplo n.º 4
0
        public void TestReflectionInheritanceOptimalization2()
        {
            var rg = new ReflectionGenerator();

            rg.GenerateInterface(typeof(Test3A));

            var module = rg.GenerationStrategy.TargetModule;

            module = Optimizer.RemoveEmptyDeclarations(module);
            var g = new OutputGenerator();

            g.Generate(module);

            Assert.AreEqual(null, Helper.StringCompare(
                                @"module GeneratedModule {
    interface ITest3A {
        Prop1: number;
    }
}", g.Output));
        }
Exemplo n.º 5
0
        public void TestReflectionInheritanceOptimalization1()
        {
            var rg = new ReflectionGenerator();

            rg.GenerateInterface(typeof(ITest3B));

            var g = new OutputGenerator();

            g.Generate(rg.GenerationStrategy.TargetModule);

            Assert.AreEqual(null, Helper.StringCompare(
                                @"module GeneratedModule {
    interface ITest3A {
        Prop1: number;
    }
    interface ITest3B extends ITest3A {
        Prop2: string;
        Prop2b: ITest3A;
    }
}", g.Output));
        }
Exemplo n.º 6
0
        public void TestMethods()
        {
            var rg = new ReflectionGenerator();

            rg.NamingStrategy.InterfacePrefixForClasses = "i";
            rg.GenerationStrategy.GenerateMethods       = true;
            rg.GenerateInterface(typeof(TestGenMethods <>));

            var g = new OutputGenerator();

            g.Generate(rg.GenerationStrategy.TargetModule);

            Assert.AreEqual(@"
module GeneratedModule {
    interface iTestGenMethods<T> {
        Test1(input: T): string;
        Test2<T2>(input: T2, withDefault?: string = '42'): boolean;
        Test3(x: number, ...args: string[]): void;
    }
}".Trim(), g.Output.Trim());
        }
Exemplo n.º 7
0
        public void TestIntf()
        {
            var rg = new ReflectionGenerator();

            rg.NamingStrategy.InterfacePrefixForClasses = "i";
            rg.GenerateInterface(typeof(TestingClass));

            var g = new OutputGenerator();

            g.GenerateComments = false;
            g.Generate(rg.GenerationStrategy.TargetModule);

            Assert.AreEqual(null, Helper.StringCompare(@"
module GeneratedModule {
    interface IMyInterface {
        Property2: string;
    }
    interface iTestingClassBase extends IMyInterface {
        Property1: number;
        /* Property Property2 skipped, because it is already implemented by interface IMyInterface*/
    }
    interface iTestingClass extends iTestingClassBase {
        Property3: MyEnum;
        Property4?: number;
        Property5: string[];
        Property6: iTestingClass;
        Property7: iTestingClass[];
        Property8: iTestingClass[];
    }
    enum MyEnum {
        Value1 = 0,
        Value2 = 1,
        Value3 = 10,
        Value4 = 11
    }
}", g.Output));
        }