public void WhenCreateFromEnum_EnumValueIsAddedWithInformationFromConfigurationProvider() { var enumType = typeof(EnumWithoutAttribute); var enumTypeInfo = enumType.GetTypeInfo(); var enumValueFieldInfo = enumTypeInfo.GetField("EnumValue1"); _configurationProviderMock .Setup(o => o.GetEnumValueConfiguration(It.Is <FieldInfo>(f => f == enumValueFieldInfo))) .Returns(new TsEnumValueConfiguration() { Name = "EnumValue1", Value = "1" }); var enumResolvedType = new TsBasicType() { Context = typeof(EnumWithoutAttribute), TypeName = "EnumWithoutAttribute" }; _typeResolverMock .Setup(o => o.ResolveType(It.Is <Type>(t => t == typeof(EnumWithoutAttribute)))) .Returns(enumResolvedType); var @enum = TsEnum.CreateFrom <EnumWithoutAttribute>(_typeResolverMock.Object, _configurationProviderMock.Object); var enumValue = @enum.Values.Single(); Assert.Equal("EnumValue1", enumValue.Name); Assert.Equal("1", enumValue.Value); }
public void WhenInitialized_NameIsSet() { var typeName = new TsBasicType() { Context = typeof(EnumWithoutAttribute), TypeName = "EnumWithoutAttribute" }; var sut = new TsEnum(typeName); Assert.Same(typeName, sut.Name); }
public void WhenInitialized_ValuesIsEmptyCollection() { var typeName = new TsBasicType() { Context = typeof(EnumWithoutAttribute), TypeName = "EnumWithoutAttribute" }; var sut = new TsEnum(typeName); Assert.Empty(sut.Values); }
public void WhenInitialized_PropertiesCollectionIsEmpty() { var typeName = new TsBasicType() { Context = typeof(ClassWithoutAttribute), TypeName = "ClassWithoutAttribute" }; var sut = new TsClass(typeName); Assert.Empty(sut.Properties); }
protected TsBasicType SetupTypeResolverFor <T>() { var classType = typeof(T); var classResolvedType = new TsBasicType() { Context = classType, TypeName = classType.Name }; _typeResolverMock .Setup(o => o.ResolveType(It.Is <Type>(t => t == classType))) .Returns(classResolvedType); return(classResolvedType); }
public virtual TsType ResolveType(Type t) { if (_knownTypes.ContainsKey(t)) { return(_knownTypes[t]); } var typeInfo = t.GetTypeInfo(); var typeConfiguration = _configurationProvider.GetConfiguration(t) as TsModuleMemberConfiguration; if (t.IsNullable()) { return(this.ResolveType(t.GetNullableValueType())); } if (t.IsCollection()) { var collectionItemType = t.GetCollectionItemType(); if (collectionItemType == null) { return(this.CacheAndReturn(t, new TsCollectionType() { ItemType = TsBasicType.Any, Context = t })); } else { return(this.CacheAndReturn(t, new TsCollectionType() { ItemType = this.ResolveType(collectionItemType), Context = t })); } } if ((typeInfo.IsClass || typeInfo.IsGenericType || typeInfo.IsInterface || typeInfo.IsValueType) && typeConfiguration != null) { var resolvedType = new TsBasicType() { Context = t }; resolvedType.TypeName = typeConfiguration.Name; resolvedType.Module = typeConfiguration.Module; if (typeInfo.IsGenericType) { foreach (var arg in typeInfo.GenericTypeArguments) { resolvedType.GenericArguments.Add(this.ResolveType(arg)); } } if (typeInfo.IsGenericTypeDefinition) { foreach (var arg in typeInfo.GenericTypeParameters) { resolvedType.GenericArguments.Add(this.ResolveType(arg)); } } return(this.CacheAndReturn(t, resolvedType)); } return(TsBasicType.Any); }
public void WhenInitialized_GenericArgumentsIsEmpty() { var type = new TsBasicType(); Assert.Empty(type.GenericArguments); }