public void EmitOpenGenericTypesWithTypeArgumentProperty()
        {
            var context = new ProxyGeneratorContext(new[] { typeof(GenericClassWithTypeArgumentProperty <>) },
                                                    new Configuration());

            Assert.Contains(
                @"
export module Cirqus.TypeScript.Tests {
    export interface GenericClassWithTypeArgumentProperty<T> {
        item: T;
    }
}
", context.GetDefinitions(CirqusType.Other));

            Assert.DoesNotContain(@"export class T", context.GetDefinitions(CirqusType.Other));
        }
        public void EmitOpenGenericTypesWithMultipleParams()
        {
            var context = new ProxyGeneratorContext(new[] { typeof(GenericClass <,>) }, new Configuration());

            Assert.Contains(
                @"export module Cirqus.TypeScript.Tests {
    export interface GenericClass<T, U> {
        
    }
}
", context.GetDefinitions(CirqusType.Other));
        }
        public void IgnoresMarkedProperties()
        {
            var context = new ProxyGeneratorContext(new[] { typeof(ClassWithIgnoredProperty) }, new Configuration());

            Assert.Contains(
                @"export module Cirqus.TypeScript.Tests {
    export interface ClassWithIgnoredProperty {
        
    }
}
", context.GetDefinitions(CirqusType.Other));
        }
        public void EmitClosedGenericAsFreeType()
        {
            var context = new ProxyGeneratorContext(new[] { typeof(GenericClass <int>) }, new Configuration());

            Assert.Contains(
                @"export module Cirqus.TypeScript.Tests {
    export interface GenericClass<T> {
        
    }
}
", context.GetDefinitions(CirqusType.Other));
        }
        public void EmitEnumerableGenericTypesClosedWithTypeArgument()
        {
            var context = new ProxyGeneratorContext(new[] { typeof(MotherOfEnumerableOf <>) }, new Configuration());

            Assert.Contains(
                @"export module Cirqus.TypeScript.Tests {
    export interface MotherOfEnumerableOf<T> {
        type: T[];
    }
}
", context.GetDefinitions(CirqusType.Other));
        }
예제 #6
0
        public IEnumerable <ProxyGenerationResult> GetProxyGenerationResults(Configuration configuration)
        {
            var types = configuration.Types;

            Console.WriteLine("Found {0} types", types.Count);

            var context = new ProxyGeneratorContext(types, configuration);

            var apiCode    = context.GetDefinitions(CirqusType.Command, CirqusType.View, CirqusType.Other, CirqusType.Primitive);
            var systemCode = context.GetSystemDefinitions();

            yield return(new ProxyGenerationResult(apiCode + systemCode));
        }
        public void EmitsEnumWithImplicitValues()
        {
            var context = new ProxyGeneratorContext(new[] { typeof(Enum) }, new Configuration());

            Assert.Contains(
                @"
export module Cirqus.TypeScript.Tests {
    export enum Enum {
        None = 0,
        Value1 = 1,
        Value2 = 2
    }
}
", context.GetDefinitions(CirqusType.Other));
        }
        public void CanAliasNamespaces()
        {
            var context = new ProxyGeneratorContext(new[] { typeof(SomeClass) }, new Configuration()
            {
                NamespaceAliases =
                {
                    Tuple.Create("Cirqus.TypeScript", "HAT")
                }
            });

            Assert.Contains(
                @"export module HAT.Tests {
    export interface SomeClass {
        
    }
}
", context.GetDefinitions(CirqusType.Other));
        }
        public void EmitClosedGenericAsUsedType()
        {
            var context = new ProxyGeneratorContext(new[] { typeof(FatherOfGenericClass) }, new Configuration());

            Assert.Contains(
                @"export module Cirqus.TypeScript.Tests {
    export interface FatherOfGenericClass {
        type: Cirqus.TypeScript.Tests.GenericClass<number>;
    }
}

export module Cirqus.TypeScript.Tests {
    export interface GenericClass<T> {
        
    }
}
", context.GetDefinitions(CirqusType.Other));
        }
        public void CommandIsExportedAsClassAndMetaDataIsIgnored()
        {
            var context = new ProxyGeneratorContext(new[] { typeof(CommandClass) }, new Configuration());

            Assert.Contains(
                @"export module Cirqus.TypeScript.Tests {
    export class CommandClass implements Command {

        constructor(args: {prop: number}) {
            this.prop = args.prop;
        }

        $commandType = ""Cirqus.TypeScript.Tests.CommandClass, Cirqus.TypeScript.Tests"";
        $commandName = ""CommandClass"";
        prop: number;
    }
}
", context.GetDefinitions(CirqusType.Command));
        }
        public void EmitsEnumFromNullableProperty()
        {
            var context = new ProxyGeneratorContext(new[] { typeof(ClassWithEnum) }, new Configuration());

            Assert.Contains(
                @"
export module Cirqus.TypeScript.Tests {
    export interface ClassWithEnum {
        enum: Cirqus.TypeScript.Tests.Enum;
    }
}

export module Cirqus.TypeScript.Tests {
    export enum Enum {
        None = 0,
        Value1 = 1,
        Value2 = 2
    }
}
", context.GetDefinitions(CirqusType.Other));
        }