public void WhenInitializedWithClassThatHasBaseClass_BaseTypeIsSet() { var target = new TsClass(typeof(Employee)); Assert.NotNull(target.BaseType); Assert.Equal(typeof(Person), target.BaseType.Type); }
public void WhenInitializedWithClassThatHasBaseClass_OnlyPropertiesDefinedInDerivedClassAreCreated() { var target = new TsClass(typeof(Employee)); Assert.Single(target.Properties.Where(o => o.MemberInfo == typeof(Employee).GetProperty("Salary"))); Assert.Empty(target.Properties.Where(o => o.MemberInfo == typeof(Employee).GetProperty("Street"))); Assert.Empty(target.Properties.Where(o => o.MemberInfo == typeof(Employee).GetProperty("Street"))); }
public void WhenInitializedWithClassWithEnum_PropertiesCreated() { var target = new TsClass(typeof(Item)); Assert.Single(target.Properties.Where(o => o.MemberInfo == typeof(Item).GetProperty("Type"))); Assert.Single(target.Properties.Where(o => o.MemberInfo == typeof(Item).GetProperty("Id"))); Assert.Single(target.Properties.Where(o => o.MemberInfo == typeof(Item).GetProperty("Name"))); Assert.Null(target.BaseType); }
/// <summary> /// Resolves references in the class. /// </summary> /// <param name="classModel"></param> public override void VisitClass(TsClass classModel) { if (classModel.Module != null) { classModel.Module = this.ResolveModule(classModel.Module.Name); } if (classModel.BaseType != null && classModel.BaseType != TsType.Any) { classModel.BaseType = this.ResolveType(classModel.BaseType, false); } for (int i = 0; i < classModel.Interfaces.Count; i++) { classModel.Interfaces[i] = this.ResolveType(classModel.Interfaces[i], false); } }
public void WhenInitializedWithClassWithEnum_EnumPropertyCreated() { var target = new TsClass(typeof(Item)); Assert.Single(target.Properties.Where(o => o.MemberInfo == typeof(Item).GetProperty("Type"))); var property = target.Properties.Single(o => o.MemberInfo == typeof(Item).GetProperty("Type")); Assert.True(property.PropertyType.GetType() == typeof(TsEnum)); var enumtype = property.PropertyType as TsEnum; Assert.NotNull(enumtype); Assert.True(enumtype.Values.Any()); Assert.True(enumtype.Values.Any(a => a.Name == "Book" && a.Value == ((int)ItemType.Book).ToString())); Assert.True(enumtype.Values.Any(a => a.Name == "Music" && a.Value == ((int)ItemType.Music).ToString())); Assert.True(enumtype.Values.Any(a => a.Name == "Clothing" && a.Value == ((int)ItemType.Clothing).ToString())); Assert.Null(target.BaseType); }
protected override void AppendClassDefinition(TsClass classModel, ScriptBuilder sb, TsGeneratorOutput generatorOutput) { string typeName = this.GetTypeName(classModel); string visibility = this.GetTypeVisibility(classModel, typeName) ? "export " : ""; sb.AppendFormatIndented( "{0}class {1} extends {2}", visibility, typeName, //all bottom-level classes must extend Backbone.Model. classModel.BaseType != null ? this.GetFullyQualifiedTypeName(classModel.BaseType) : "Backbone.Model"); sb.AppendLine(" {"); var members = new List<TsProperty>(); if ((generatorOutput & TsGeneratorOutput.Properties) == TsGeneratorOutput.Properties) { members.AddRange(classModel.Properties); } if ((generatorOutput & TsGeneratorOutput.Fields) == TsGeneratorOutput.Fields) { members.AddRange(classModel.Fields); } using (sb.IncreaseIndentation()) { foreach (var property in members) { if (property.IsIgnored) { continue; } sb.AppendLineIndented(string.Format( "get {0}(): {1} {{ return this.get(\"{0}\"); }}", this.GetPropertyName(property), this.GetPropertyType(property))); sb.AppendLineIndented(string.Format( "set {0}(v: {1}) {{ this.set(\"{0}\", v); }}", this.GetPropertyName(property), this.GetPropertyType(property))); } } sb.AppendLineIndented("}"); _generatedClasses.Add(classModel); }
public void WhenModuleIsSet_ClassIsAddedToModule() { var module = new TsModule("Tests"); var target = new TsClass(typeof(Address)); target.Module = module; Assert.Contains(target, module.Classes); }
public void WhenInitializedWithInnerClass_ModuleIsSetToNamespaceAndOuterClass() { var target = new TsClass(typeof(TypeLite.Tests.TestModels.Outer.Inner)); Assert.NotNull(target.Module); Assert.Equal(typeof(TypeLite.Tests.TestModels.Outer.Inner).Namespace + ".Outer", target.Module.Name); }
public void WhenInitialized_FieldsAreCreated() { var target = new TsClass(typeof(Address)); Assert.Single(target.Fields.Where(o => o.MemberInfo == typeof(Address).GetField("PostalCode"))); }
public void WhenInitializedWithClassWithBaseTypeObject_BaseTypeIsSetToNull() { var target = new TsClass(typeof(Address)); Assert.Null(target.BaseType); }
public void WhenInitialized_IsIgnoredIsFalse() { var target = new TsClass(typeof(Person)); Assert.False(target.IsIgnored); }
public void WhenInitialized_ConstantsHaveCorrectValues() { var target = new TsClass(typeof(Person)); var maxAddresses = target.Constants.Single(o => o.MemberInfo == typeof(Person).GetField("MaxAddresses")); Assert.Equal(Person.MaxAddresses, maxAddresses.ConstantValue); }
public void AppendClassDoc(ScriptBuilder sb, TsClass classModel, string className) { AppendModelDoc(sb, classModel.Type); }
public void WhenModuleIsSetToOtherModule_ClassIsRemovedFromOriginalModule() { var originalModule = new TsModule("Tests.Original"); var module = new TsModule("Tests"); var target = new TsClass(typeof(Address)); target.Module = originalModule; target.Module = module; Assert.DoesNotContain(target, originalModule.Classes); }
public void WhenInitialized_PropertiesAreCreated() { var target = new TsClass(typeof(Address)); Assert.Single(target.Properties.Where(o => o.MemberInfo == typeof(Address).GetProperty("Street"))); Assert.Single(target.Properties.Where(o => o.MemberInfo == typeof(Address).GetProperty("Town"))); }
public void WhenInitialized_NameIsSet() { var target = new TsClass(typeof(Person)); Assert.Equal("Person", target.Name); }
public void WhenInitialized_ModuleIsSetToNamespaceModule() { var target = new TsClass(typeof(Address)); Assert.NotNull(target.Module); Assert.Equal(typeof(Address).Namespace, target.Module.Name); }
/// <summary> /// When overridden in a derived class, it can examine or modify the class model. /// </summary> /// <param name="classModel">The model class being visited.</param> public virtual void VisitClass(TsClass classModel) { }
public void WhenInitializedAndClassHasCustomNameInAttribute_CustomNameIsUsed() { var target = new TsClass(typeof(CustomClassName)); Assert.Equal("MyClass", target.Name); }
public void AppendClassDoc(ScriptBuilder sb, TsClass classModel, string className) { }
public void WhenInitialized_ConstantsAreCreated() { var target = new TsClass(typeof(Person)); Assert.Single(target.Constants.Where(o => o.MemberInfo == typeof(Person).GetField("MaxAddresses"))); }