Esempio n. 1
0
        private TypescriptClassToInterfaceConverter CreateTypescriptClassToInterfaceConverter()
        {
            var classToInterfaceConverterSettings = new TypescriptClassToInterfaceConverterSettings();

            classToInterfaceConverterSettings.PropertySettings.TypeConverters.AddRange(CustomTypeConverters);
            var classConverter = new TypescriptClassToInterfaceConverter(classToInterfaceConverterSettings, EnumSettings, NamespaceSettings);

            return(classConverter);
        }
 public TypescriptClassToInterfaceConverter(
     TypescriptClassToInterfaceConverterSettings settings,
     TypescriptEnumConverterSettings enumSettings,
     List <NamespaceSettings> namespaceSettings)
 {
     if (enumSettings == null)
     {
         throw new ArgumentNullException(nameof(enumSettings));
     }
     this.settings          = settings ?? throw new ArgumentNullException(nameof(settings));
     this.namespaceSettings = namespaceSettings ?? throw new ArgumentNullException(nameof(namespaceSettings));
     propertyConverter      = new TypescriptPropertyConverter(
         this.settings.PropertySettings,
         enumSettings,
         this.namespaceSettings);
 }
        public void NewtonsoftJsonIgnoreAndJsonPropertyAttributesAreUsed()
        {
            var settings = new TypescriptClassToInterfaceConverterSettings
            {
                PropertySettings =
                {
                    Casing = CasingType.CamelCase
                }
            };
            var sut = new TypescriptClassToInterfaceConverter(settings, enumSettings, namespaceSettings);

            var actual = sut.Convert(typeof(TestClass2));

            Assert.That(actual.Properties.Count, Is.EqualTo(2));
            Assert.That(actual.Properties.Exists(x => x.Name == "title"));
            Assert.That(!actual.Properties.Exists(x => x.Name == "number"));
            Assert.That(actual.Properties.Exists(x => x.Name == "customName"));
        }
        public void AllPublicPropertiesAreTransferred()
        {
            var settings = new TypescriptClassToInterfaceConverterSettings
            {
                PropertySettings =
                {
                    Casing = CasingType.CamelCase
                }
            };
            var sut = new TypescriptClassToInterfaceConverter(settings, enumSettings, namespaceSettings);

            var actual = sut.Convert(typeof(TestClass1));

            Assert.That(actual.Properties.Count, Is.EqualTo(3));
            Assert.That(actual.Properties.Exists(x => x.Name == "title"));
            Assert.That(actual.Properties.Exists(x => x.Name == "number"));
            Assert.That(actual.Properties.Exists(x => x.Name == "longName"));
        }
        public void GenericTypeIsConvertedToGenericInterface()
        {
            var settings = new TypescriptClassToInterfaceConverterSettings
            {
                PropertySettings =
                {
                    Casing = CasingType.CamelCase
                }
            };
            var sut = new TypescriptClassToInterfaceConverter(settings, enumSettings, namespaceSettings);

            var actual = sut.Convert(typeof(Range <>));

            Assert.That(actual.Properties.Count, Is.EqualTo(2));
            Assert.That(actual.Name, Is.EqualTo("Range<T>"));
            Assert.That(actual.Properties.Exists(x => x.Name == "from"));
            Assert.That(actual.Properties.Exists(x => x.Name == "to"));
            Assert.That(actual.Properties.All(x => x.FormattedType == "T"));
        }
        public void CustomTypeConverterIsApplied()
        {
            var settings = new TypescriptClassToInterfaceConverterSettings
            {
                PropertySettings =
                {
                    Casing = CasingType.CamelCase
                }
            };

            settings.PropertySettings.TypeConverters.Add(new UnitValueConverter());
            var sut = new TypescriptClassToInterfaceConverter(settings, enumSettings, namespaceSettings);

            var actual = sut.Convert(typeof(Bag));

            Assert.That(actual.Properties.Count, Is.EqualTo(2));
            Assert.That(actual.Properties.Exists(x => x.Name == "volume"));
            var volumeProperty = actual.Properties.Find(x => x.Name == "volume");

            Assert.That(volumeProperty.FormattedType, Is.EqualTo("math.Unit"));
        }