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);
        }
예제 #2
0
        public void WhenGenerate_OutputIsFormated()
        {
            var builder = new TsModelBuilder();

            builder.Add <Address>();
            var model = builder.Build();

            var target = new TsGenerator();
            var script = target.Generate(model);

            using (var reader = new StringReader(script))
            {
                var line = string.Empty;
                while ((line = reader.ReadLine()) != null)
                {
                    if (line.Contains("interface Address {"))
                    {
                        Assert.StartsWith("\t", line);
                    }
                    if (line.Contains("ID: Guid"))
                    {
                        Assert.StartsWith("\t\t", line);
                    }
                }
            }
        }
예제 #3
0
        public void SimpleExportedInterfaceGeneratorTest()
        {
            Class @class = new Class
            {
                Name       = "Some",
                Properties = new[]
                {
                    new Property
                    {
                        Name   = "Prop",
                        CsType = null,
                    }
                }
            };

            ICsToTsTypeConverter typeConverter = Substitute.For <ICsToTsTypeConverter>();

            typeConverter.GetTypeScriptType(null).Returns("");

            TsGenerator generator = new TsGenerator(typeConverter);

            string generatedCode = generator.GenerateInterface(@class, true, false);

            generatedCode.Should().Contain("Some", "because this is the class name");
            generatedCode.Should().Contain("interface", "because we are generating an interface");
            generatedCode.Should().Contain("Prop:", "because that is the name op the property");
            generatedCode.Should().Contain("export", "because export is true");
        }
예제 #4
0
        public static void RegisterDictionaryMemberFormatter(this TsGenerator tsGenerator, TypeConverter conv)
        {
            tsGenerator.SetMemberTypeFormatter((tsProperty, memberTypeName) =>
            {
                var dictionaryInterface =
                    tsProperty.PropertyType.Type.GetDnxCompatible().GetInterface(typeof(IDictionary <,>).Name) ??
                    tsProperty.PropertyType.Type.GetDnxCompatible().GetInterface(typeof(IDictionary).Name);

                if (dictionaryInterface != null)
                {
                    if (dictionaryInterface.GetDnxCompatible().IsGenericType)
                    {
                        var args = dictionaryInterface.GetDnxCompatible().GetGenericArguments();
                        var t1   = conv.GetTypeScriptName(args[0]);
                        var t2   = conv.GetTypeScriptName(args[1]);
                        return($"{{ [key: {t1}]: {t2} }}");
                    }
                    else
                    {
                        return("{ [key: string]: any }");
                    }

                    return(tsGenerator.GetFullyQualifiedTypeName(new TsClass(dictionaryInterface)));
                }
                else
                {
                    return(tsGenerator.DefaultMemberTypeFormatter(tsProperty, memberTypeName));
                }
            });
        }
예제 #5
0
        public void WhenModeIsClasses_InterfacesArentGenerated()
        {
            var builder = new TsModelBuilder();

            builder.Add <Employee>();
            builder.Add <User>();
            var model = builder.Build();

            var target = new TsGenerator
            {
                Mode = TsGenerationModes.Classes
            };
            var script = target.Generate(model);

            var classCount = Regex.Matches(script, Regex.Escape("class")).Count;

            Assert.True(classCount > 0, script);

            var moduleCount = Regex.Matches(script, Regex.Escape("module")).Count;

            Assert.True(moduleCount > 0, script);

            var interfaceCount = Regex.Matches(script, Regex.Escape("interface")).Count;

            Assert.True(interfaceCount == 0, script);

            var namespaceCount = Regex.Matches(script, Regex.Escape("namespace")).Count;

            Assert.True(namespaceCount == 0, script);
        }
예제 #6
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 WhenClassContainsNullableEnumProperty_ExceptionIsNotThrown()
        {
            var builder = new TsModelBuilder();
            builder.Add<Issue24Example>();

            var generator = new TsGenerator();
            var model = builder.Build();

            Assert.DoesNotThrow(() => generator.Generate(model));
        }
        public void WhenPropertyWithDbGeometryTypeIsAnnotedWithTsIgnoreAttribute_GeneratorDoesntCrash()
        {
            var builder = new TsModelBuilder();
            builder.Add<DbGeometryTestClass>();

            var generator = new TsGenerator();
            var model = builder.Build();

            Assert.DoesNotThrow(() => generator.Generate(model));
        }
        public void WhenClassContainsNullableAndNonNullableStruct_StructureIsIncludedInModelOnlyOnce()
        {
            var builder = new TsModelBuilder();
            builder.Add<NullableAndNonNullableContainer>();

            var generator = new TsGenerator();
            var model = builder.Build();

            Assert.Single(model.Classes.Where(o => o.Type == typeof(Structure1)));
        }
        public void WhenClassIsReferencedAndOutputIsSetToConstants_ClassIsntInOutput()
        {
            var builder = new TsModelBuilder();
            builder.Add<Item>();
            var model = builder.Build();
            var target = new TsGenerator();
            var script = target.Generate(model, TsGeneratorOutput.Constants);

            Assert.DoesNotContain("interface Item", script);
        }
        public void WhenClassContainsPropertyOfSystemType_InvalidCastExceptionIsntThrown()
        {
            var builder = new TsModelBuilder();
            builder.Add<Issue15Example>();

            var generator = new TsGenerator();
            var model = builder.Build();

            Assert.DoesNotThrow(() => generator.Generate(model));
        }
        public void PropertyIsMarkedOptional_OptionalPropertyIsGenerated()
        {
            var builder = new TsModelBuilder();
            builder.Add<Address>();
            var model = builder.Build();

            var target = new TsGenerator();
            var script = target.Generate(model);

            Assert.Contains("CountryID?: number", script);
        }
        public void WhenAssemblyContainsEnumWithoutClass_EnumIsGeneratedInTheOutput()
        {
            var builder = new TsModelBuilder();
            builder.Add(typeof(TypeLite.Tests.AssemblyWithEnum.TestEnum).Assembly);

            var generator = new TsGenerator();
            var model = builder.Build();
            var result = generator.Generate(model, TsGeneratorOutput.Enums);

            Assert.Contains("TestEnum", result);
        }
        public void WhenClassReferencesItself_ClassIsGenerated()
        {
            var builder = new TsModelBuilder();
            builder.Add<GenericWithSelfReference>();

            var generator = new TsGenerator();
            var model = builder.Build();
            var result = generator.Generate(model);

            Assert.Contains("Children: TypeLite.Tests.RegressionTests.GenericWithSelfReference[]", result);
        }
예제 #15
0
        public void WhenDateTimePropertyIsInModel_DateWithUppercaseDIsGenerated()
        {
            var builder = new TsModelBuilder();
            builder.Add<ModelWithDateTime>();

            var generator = new TsGenerator();
            var model = builder.Build();
            var result = generator.Generate(model);

            Assert.Contains("Property: Date", result);
        }
        public void WhenClassIsIgnoredByAttribute_InterfaceForClassIsntGenerated()
        {
            var builder = new TsModelBuilder();
            builder.Add<IgnoreTestBase>();
            var model = builder.Build();

            var target = new TsGenerator();
            var script = target.Generate(model);

            Assert.DoesNotContain("IgnoreTestBase", script);
        }
        public void WhenClassContainsNullableEnumProperty_ExceptionIsNotThrown()
        {
            var builder = new TsModelBuilder();

            builder.Add <Issue24Example>();

            var generator = new TsGenerator();
            var model     = builder.Build();

            Assert.DoesNotThrow(() => generator.Generate(model));
        }
예제 #18
0
        public void WhenEnumIsReferencedAndOutputIsSetToFields_ConstantIsntInOutput()
        {
            var builder = new TsModelBuilder();

            builder.Add <Item>();
            var model  = builder.Build();
            var target = new TsGenerator();
            var script = target.Generate(model, TsGeneratorOutput.Fields);

            Assert.DoesNotContain("MaxItems", script);
        }
        public void WhenModuleDoesntContainsAnyEnums_ItIsntGeneratedWithEnumsOption()
        {
            var builder = new TsModelBuilder();
            builder.Add<MyTestClass>();

            var generator = new TsGenerator();
            var model = builder.Build();
            var result = generator.Generate(model, TsGeneratorOutput.Enums);

            Assert.DoesNotContain("MyTestModule", result);
        }
예제 #20
0
        public void WhenClassIsReferencedAndOutputIsSetToConstants_EnumIsntInOutput()
        {
            var builder = new TsModelBuilder();

            builder.Add <Item>();
            var model  = builder.Build();
            var target = new TsGenerator();
            var script = target.Generate(model, TsGeneratorOutput.Constants);

            Assert.DoesNotContain("enum ItemType", script);
        }
예제 #21
0
        public void WhenClassWithEnumReferenced_FullyQualifiedNameIsUsed()
        {
            var builder = new TsModelBuilder();

            builder.Add <Item>();
            var model  = builder.Build();
            var target = new TsGenerator();
            var script = target.Generate(model);

            Assert.Contains("Type: TypeLitePlus.Tests.NetCore.TestModels.ItemType", script);
        }
        public void WhenModuleIsGeneratedWithFieldsOnlyOption_ModuleHasDeclareKeyword()
        {
            var builder = new TsModelBuilder();
            builder.Add<MyTestClass>();

            var generator = new TsGenerator();
            var model = builder.Build();
            var result = generator.Generate(model, TsGeneratorOutput.Fields);

            Assert.Contains("declare", result);
        }
        public void WhenModuleIsGeneratedWithEnumsOnlyOption_ModuleDoesntHaveDeclareKeyword()
        {
            var builder = new TsModelBuilder();
            builder.Add<MyTestClass>();

            var generator = new TsGenerator();
            var model = builder.Build();
            var result = generator.Generate(model, TsGeneratorOutput.Enums);

            Assert.DoesNotContain("declare", result);
        }
예제 #24
0
        public void WhenClassIsReferencedAndOutputIsSetToEnums_ClassIsntInOutput()
        {
            var builder = new TsModelBuilder();

            builder.Add <Item>();
            var model  = builder.Build();
            var target = new TsGenerator();
            var script = target.Generate(model, TsGeneratorOutput.Enums);

            Assert.DoesNotContain("interface Item", script);
        }
        public void WhenEnumIsGenerated_ItHasExportKeyword()
        {
            var builder = new TsModelBuilder();
            builder.Add<MyTestClass>();

            var generator = new TsGenerator();
            var model = builder.Build();
            var result = generator.Generate(model, TsGeneratorOutput.Enums);

            Assert.Contains("export", result);
        }
예제 #26
0
        public void DoesNotThrowNullReferenceException_WhenEnumPropertyInGenericClass()
        {
            Assert.DoesNotThrow(() => {
                var builder = new TsModelBuilder();
                builder.Add <Bob <object> >();

                var generator = new TsGenerator();
                var model     = builder.Build();
                var result    = generator.Generate(model);
            });
        }
예제 #27
0
        public void WhenClassContainsPropertyOfSystemType_InvalidCastExceptionIsntThrown()
        {
            var builder = new TsModelBuilder();

            builder.Add <Issue15Example>();

            var generator = new TsGenerator();
            var model     = builder.Build();

            Assert.DoesNotThrow(() => generator.Generate(model));
        }
예제 #28
0
        public void WhenPropertyWithDbGeometryTypeIsAnnotedWithTsIgnoreAttribute_GeneratorDoesntCrash()
        {
            var builder = new TsModelBuilder();

            builder.Add <DbGeometryTestClass>();

            var generator = new TsGenerator();
            var model     = builder.Build();

            Assert.DoesNotThrow(() => generator.Generate(model));
        }
예제 #29
0
        public void WhenModelContainsReference_ReferenceIsAddedToOutput()
        {
            var model = new TsModel();

            model.References.Add("knockout.d.ts");

            var target = new TsGenerator();
            var script = target.Generate(model);

            Assert.Contains("/// <reference path=\"knockout.d.ts\" />", script);
        }
예제 #30
0
        public void WhenClassContainsNullableAndNonNullableStruct_StructureIsIncludedInModelOnlyOnce()
        {
            var builder = new TsModelBuilder();

            builder.Add <NullableAndNonNullableContainer>();

            var generator = new TsGenerator();
            var model     = builder.Build();

            Assert.Single(model.Classes.Where(o => o.Type == typeof(Structure1)));
        }
예제 #31
0
        public void WhenEnumIsGenerated_ItHasExportKeyword()
        {
            var builder = new TsModelBuilder();

            builder.Add <MyTestClass>();

            var generator = new TsGenerator();
            var model     = builder.Build();
            var result    = generator.Generate(model, TsGeneratorOutput.Enums);

            Assert.Contains("export", result);
        }
예제 #32
0
        public void WhenInterfaceIsAdded_InterfaceIsInOutput()
        {
            var builder = new TsModelBuilder();

            builder.Add <IShippingService>();
            var model  = builder.Build();
            var target = new TsGenerator();
            var script = target.Generate(model, TsGeneratorOutput.Properties);

            Assert.Contains("IShippingService", script);
            Assert.Contains("Price", script);
        }
예제 #33
0
        public void WhenDateTimePropertyIsInModel_DateWithUppercaseDIsGenerated()
        {
            var builder = new TsModelBuilder();

            builder.Add <ModelWithDateTime>();

            var generator = new TsGenerator();
            var model     = builder.Build();
            var result    = generator.Generate(model);

            Assert.Contains("Property: Date", result);
        }
        public void WhenAssemblyContainsEnumWithoutClass_EnumIsGeneratedInTheOutput()
        {
            var builder = new TsModelBuilder();

            builder.Add(typeof(TypeLite.Tests.AssemblyWithEnum.TestEnum).Assembly);

            var generator = new TsGenerator();
            var model     = builder.Build();
            var result    = generator.Generate(model, TsGeneratorOutput.Enums);

            Assert.Contains("TestEnum", result);
        }
        public void WhenModuleIsGeneratedWithConstantsAndProperties_ThrowsInvalidOperationException()
        {
            var builder = new TsModelBuilder();
            builder.Add<MyTestClass>();

            var generator = new TsGenerator();
            var model = builder.Build();
            Assert.Throws<InvalidOperationException>(() =>
            {
                generator.Generate(model, TsGeneratorOutput.Constants | TsGeneratorOutput.Properties);
            });
        }
        public void WhenEnumTypeAppearsOnlyInCollectionTypeProperty_EnumIsGenerated()
        {
            var builder = new TsModelBuilder();
            builder.Add<AuthenticationResult>();

            var generator = new TsGenerator();
            var model = builder.Build();
            var result = generator.Generate(model);

            Assert.True(model.Enums.Count == 1);
            Assert.True(model.Enums.Single().Type == typeof(AuthenticationError));
        }
        public void WhenModuleDoesntContainsAnyEnums_ItIsntGeneratedWithEnumsOption()
        {
            var builder = new TsModelBuilder();

            builder.Add <MyTestClass>();

            var generator = new TsGenerator();
            var model     = builder.Build();
            var result    = generator.Generate(model, TsGeneratorOutput.Enums);

            Assert.DoesNotContain("MyTestModule", result);
        }
        public void WhenModuleIsGeneratedWithFieldsOnlyOption_ModuleHasDeclareKeyword()
        {
            var builder = new TsModelBuilder();

            builder.Add <MyTestClass>();

            var generator = new TsGenerator();
            var model     = builder.Build();
            var result    = generator.Generate(model, TsGeneratorOutput.Fields);

            Assert.Contains("declare", result);
        }
예제 #39
0
        //
        // GET: /Home/

        public ActionResult Index()
        {
            var builder = new TsModelBuilder();

            builder.Add <Customer>();
            var model = builder.Build();

            var generator = new TsGenerator();
            var script    = generator.Generate(model);

            return(View());
        }
예제 #40
0
        public void WhenBaseClassIsIgnoredByAttribute_InterfaceForClassIsntGenerated()
        {
            var builder = new TsModelBuilder();

            builder.Add <IgnoreTest>();
            var model = builder.Build();

            var target = new TsGenerator();
            var script = target.Generate(model);

            Assert.DoesNotContain("interface IgnoreTestBase", script);
        }
        public void WhenModuleIsGeneratedWithConstantsOnlyOption_ModuleDoesntHaveDeclareKeyword()
        {
            var builder = new TsModelBuilder();

            builder.Add <MyTestClass>();

            var generator = new TsGenerator();
            var model     = builder.Build();
            var result    = generator.Generate(model, TsGeneratorOutput.Constants);

            Assert.DoesNotContain("declare", result);
        }
예제 #42
0
        public void WhenClassIsReferenced_FullyQualifiedNameIsUsed()
        {
            var builder = new TsModelBuilder();

            builder.Add <Person>();
            var model  = builder.Build();
            var target = new TsGenerator();
            var script = target.Generate(model);

            Assert.Contains("PrimaryAddress: TypeLitePlus.Tests.NetCore.TestModels.Address", script);
            Assert.Contains("Addresses: TypeLitePlus.Tests.NetCore.TestModels.Address[]", script);
        }
        public void WhenClassReferencesItself_ClassIsGenerated()
        {
            var builder = new TsModelBuilder();

            builder.Add <GenericWithSelfReference>();

            var generator = new TsGenerator();
            var model     = builder.Build();
            var result    = generator.Generate(model);

            Assert.Contains("Children: TypeLitePlus.Tests.NetCore.RegressionTests.GenericWithSelfReference[]", result);
        }
예제 #44
0
        public void PropertyIsMarkedOptional_OptionalPropertyIsGenerated()
        {
            var builder = new TsModelBuilder();

            builder.Add <Address>();
            var model = builder.Build();

            var target = new TsGenerator();
            var script = target.Generate(model);

            Assert.Contains("CountryID?: number", script);
        }
        public void WhenClassIsIgnored_InterfaceForClassIsntGenerated()
        {
            var builder = new TsModelBuilder();
            builder.Add<Address>();
            var model = builder.Build();
            model.Classes.Where(o => o.Name == "Address").Single().IsIgnored = true;

            var target = new TsGenerator();
            var script = target.Generate(model);

            Assert.DoesNotContain("Address", script);
        }
예제 #46
0
        public void WhenPropertyHastsIgnoreAttribute_TypeOfIgnoredPropertyIsExcludedFromModel()
        {
            var builder = new TsModelBuilder();

            builder.Add <Issue14Example>();

            var generator = new TsGenerator();
            var model     = builder.Build();
            var script    = generator.Generate(model);

            Assert.DoesNotContain("Person", script);
        }
예제 #47
0
        public void WhenClassHasGenericProperty_PropertyTypeIsResolvedToTypeOfGenericArgument()
        {
            var builder = new TsModelBuilder();

            builder.Add <ClassWithGenericArguments <Address> >();

            var generator = new TsGenerator();
            var model     = builder.Build();
            var result    = generator.Generate(model);

            Assert.Contains("Property: T", result);
        }
예제 #48
0
        public void OrdersPropertiesAndFieldsByName()
        {
            var builder = new TsModelBuilder();

            builder.Add <DifferentNamespaces_Class2>();

            var generator = new TsGenerator();
            var model     = builder.Build();

            var result = generator.Generate(model);

            Assert.True(result.IndexOf("Property1") < result.IndexOf("Property2"), "Didn't order properties");
        }
        public void WhenClassHasNullableStructure_StructureIsAddedToModel()
        {
            var builder = new TsModelBuilder();
            builder.Add<NullableStructureContainer>();

            var generator = new TsGenerator();
            var model = builder.Build();
            var result = generator.Generate(model);

            Assert.Contains("NullableStructure: TypeLite.Tests.RegressionTests.Structure1;", result);
            Assert.Contains("NullableStructureCollection: TypeLite.Tests.RegressionTests.Structure2[];", result);
            Assert.Contains("NullableInt: number;", result);
        }
        public void WhenClosedGenericTypeAppearsAsPropertyTypeMultipleTimes_OnlyOneInterfaceGenerated()
        {
            var builder = new TsModelBuilder();
            builder.Add<GenericPropertiesBug>();

            var generator = new TsGenerator();
            var model = builder.Build();

            var result = generator.Generate(model);

            Assert.True(result.IndexOf("interface KeyValuePair") > -1, "KeyValuePair interface missing");
            Assert.True(result.IndexOf("interface KeyValuePair") == result.LastIndexOf("interface KeyValuePair"), "KeyValuePair interface generated too many times");

            Assert.True(result.Contains("Test1: System.Collections.Generic.KeyValuePair"));
            Assert.True(result.Contains("Test2: System.Collections.Generic.KeyValuePair"));
        }
        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);
        }
        public void WhenArrayOfArrayEncountered_ArrayOfArrayTypeScriptTypeGenerated()
        {
            var builder = new TsModelBuilder();
            builder.Add<TestClass>();

            var generator = new TsGenerator();
            var model = builder.Build();
            var result = generator.Generate(model);

            Assert.Contains("MyStringProperty: string;", result);
            Assert.Contains("MyArray: string[];", result);
            Assert.Contains("MyJaggedArray: string[][];", result);
            Assert.Contains("MyVeryJaggedArray: string[][][];", result);
            Assert.Contains("MyIEnumerableOfString: string[];", result);
            Assert.Contains("MyListOfString: string[];", result);

            Assert.Contains("MyListOfStringArrays: string[][];", result);
            Assert.Contains("MyListOfIEnumerableOfString: string[][];", result);
            Assert.Contains("MyListOfListOfStringArray: string[][][];", result);
        }
        public void WhenModelContainsReference_ReferenceIsAddedToOutput()
        {
            var model = new TsModel();
            model.References.Add("knockout.d.ts");

            var target = new TsGenerator();
            var script = target.Generate(model);

            Assert.Contains("/// <reference path=\"knockout.d.ts\" />", script);
        }
        public void WhenInterfaceIsAdded_InterfaceIsInOutput()
        {
            var builder = new TsModelBuilder();
            builder.Add<IShippingService>();
            var model = builder.Build();
            var target = new TsGenerator();
            var script = target.Generate(model, TsGeneratorOutput.Properties);

            Assert.Contains("IShippingService", script);
            Assert.Contains("Price", script);
        }
        public void WhenGenerate_OutputIsFormated()
        {
            var builder = new TsModelBuilder();
            builder.Add<Address>();
            var model = builder.Build();

            var target = new TsGenerator();
            var script = target.Generate(model);

            using (var reader = new StringReader(script)) {
                var line = string.Empty;
                while((line = reader.ReadLine()) != null) {
                    if (line.Contains("interface Address {")) {
                        Assert.True(line.StartsWith("\t"));
                    }
                    if (line.Contains("ID: Guid")) {
                        Assert.True(line.StartsWith("\t\t"));
                    }
                }
            }
        }
        public void WhenFieldIsIgnored_FieldIsExcludedFromInterface()
        {
            var builder = new TsModelBuilder();
            builder.Add<Address>();
            var model = builder.Build();
            model.Classes.Where(o => o.Name == "Address").Single().Fields.Where(f => f.Name == "PostalCode").Single().IsIgnored = true;

            var target = new TsGenerator();
            var script = target.Generate(model);

            Assert.False(script.Contains("PostalCode"));
        }
        public void WhenConvertorIsRegistered_ConvertedTypeNameIsUsedForFields()
        {
            var builder = new TsModelBuilder();
            builder.Add<Address>();
            var model = builder.Build();

            var target = new TsGenerator();
            target.RegisterTypeConvertor<string>(type => "KnockoutObservable<string>");
            var script = target.Generate(model, TsGeneratorOutput.Fields);

            Assert.Contains("PostalCode: KnockoutObservable<string>", script);
        }
        public void WhenEnumIsReferencedAndOutputIsSetToFields_ConstantIsntInOutput()
        {
            var builder = new TsModelBuilder();
            builder.Add<Item>();
            var model = builder.Build();
            var target = new TsGenerator();
            var script = target.Generate(model, TsGeneratorOutput.Fields);

            Assert.DoesNotContain("MaxItems", script);
        }
        public void WhenEnumIsReferencedAndOutputIsSetToProperties_EnumIsntInOutput()
        {
            var builder = new TsModelBuilder();
            builder.Add<Item>();
            var model = builder.Build();
            var target = new TsGenerator();
            var script = target.Generate(model, TsGeneratorOutput.Properties);

            Assert.DoesNotContain("enum ItemType", script);
        }
        public void WhenPropertyIsIgnored_PropertyIsExcludedFromInterface()
        {
            var builder = new TsModelBuilder();
            builder.Add<Address>();
            var model = builder.Build();
            model.Classes.Where(o => o.Name == "Address").Single().Properties.Where(p => p.Name == "Street").Single().IsIgnored = true;

            var target = new TsGenerator();
            var script = target.Generate(model);

            Assert.False(script.Contains("Street"));
        }