public void WhenAddingOpenGeneric_ThenSimplifiesConcreteGeneric() { var scope = Stringly.BeginScope(); scope.AddType(typeof(Lazy <>)); Assert.Equal("Lazy<System.String>", scope.GetTypeName(typeof(Lazy <string>))); }
public void WhenSimplifyingAssemblyQualifiedName_ThenAddsUsingAndSimplifiesTypeName() { var scope = Stringly.BeginScope(); scope.AddType("Foo.Bar, Foo"); Assert.Equal("Bar", scope.GetTypeName("Foo.Bar, Foo")); Assert.True(scope.SafeImports.Contains("Foo")); }
public void WhenSimplifyingOpenGenericTypeWithTwoParameters_ThenRendersValidCSharp() { var scope = Stringly.BeginScope(); scope.AddType(typeof(IDictionary <,>)); Assert.Equal("IDictionary<,>", scope.GetTypeName(typeof(IDictionary <,>))); Assert.True(scope.SafeImports.Contains(typeof(IDictionary <,>).Namespace)); }
public void WhenSimplifyingOpenGenericType_ThenRendersValidCSharp() { var scope = Stringly.BeginScope(); scope.AddType(typeof(IEnumerable <>)); Assert.Equal("IEnumerable<>", scope.GetTypeName(typeof(IEnumerable <>))); Assert.True(scope.SafeImports.Contains(typeof(IEnumerable <>).Namespace)); }
public void WhenAddingAssembly_ThenSafeUsingsDoNotContainGenerics() { var scope = Stringly.BeginScope(); scope.AddType(typeof(IEnumerable <string>)); scope.AddType(typeof(IEnumerable)); Assert.False(scope.SafeImports.Any(s => s.IndexOf('[') != -1)); }
public void WhenAddingTypesToScopeWithNoNamespace_ThenSucceeds() { var scope = Stringly.BeginScope(); scope.AddType("Foo"); scope.AddType("Bar"); Assert.Equal("Foo", scope.GetTypeName("Foo")); Assert.Equal("Bar", scope.GetTypeName("Bar")); }
public void When_Resolving_Open_Generic_Parameter_Then_Adds_Name() { var scope = Stringly.BeginScope(); var genericParam = typeof(IEnumerable <>).GetGenericTypeDefinition().GetGenericArguments()[0]; scope.AddType(genericParam); Assert.Equal("T", scope.GetTypeName(genericParam)); }
public void When_Adding_Open_Generic_Type_Then_Resolves_Without_Param_Name() { var scope = Stringly.BeginScope(); var genericType = typeof(Func <>); scope.AddType(genericType); Assert.Equal("Func<>", scope.GetTypeName(genericType)); }
public void WhenSimplifyingTypeMap_ThenUniqueTypeNamesAreSimplified() { var scope = Stringly.BeginScope(); scope.AddType("Foo.A"); scope.AddType("Bar.B"); Assert.Equal("A", scope.GetTypeName("Foo.A")); Assert.Equal("B", scope.GetTypeName("Bar.B")); }
public void WhenSimplifyingGenericType_ThenAddsUsingsAndSimplifiesGenericParameterType() { var scope = Stringly.BeginScope(); scope.AddType(typeof(IEnumerable <NonNestedType>)); Assert.Equal("IEnumerable<NonNestedType>", scope.GetTypeName(typeof(IEnumerable <NonNestedType>))); Assert.True(scope.SafeImports.Contains(typeof(IEnumerable <>).Namespace)); Assert.True(scope.SafeImports.Contains(typeof(NonNestedType).Namespace)); }
public void WhenGettingTypeNameOfTypeNotAddedWithAddedGeneric_ThenReturnsSimplifiedGenericParameter() { var scope = Stringly.BeginScope(); scope.AddType(typeof(string)); scope.AddType(typeof(bool)); Assert.Equal("System.Lazy<String>", scope.GetTypeName(typeof(Lazy <string>))); Assert.Equal("System.Lazy<System.Collections.Generic.KeyValuePair<String, Boolean>>", scope.GetTypeName(typeof(Lazy <KeyValuePair <string, bool> >))); }
public void WhenSimplifyingGenericTypeWithNestedTypeParameter_ThenRemovesPlusFromNestedTypeName() { var scope = Stringly.BeginScope(); scope.AddType(typeof(IEnumerable <NestedType>)); Assert.Equal("IEnumerable<StringlySpec.NestedType>", scope.GetTypeName(typeof(IEnumerable <NestedType>))); Assert.True(scope.SafeImports.Contains(typeof(IEnumerable <>).Namespace)); Assert.True(scope.SafeImports.Contains(typeof(NestedType).Namespace)); Assert.False(scope.SafeImports.Contains(typeof(StringlySpec).FullName), "The nested type parent should not be mistaken for a namespace."); }
public void WhenSimplifyingTwoGenerics_ThenSimplifiesAllParameters() { var scope = Stringly.BeginScope(); var type = typeof(IList <KeyValuePair <string, StringConverter> >); scope.AddType(type); scope.AddType(typeof(System.ComponentModel.StringConverter)); Assert.Equal("IList<KeyValuePair<String, NetFx.StringlyTyped.StringConverter>>", scope.GetTypeName(type)); Assert.True(scope.SafeImports.Contains(typeof(IEnumerable <>).Namespace)); }
public void WhenSimplifyingGenericTypeWithCollidingParameter_ThenKeepsParameterFullName() { var scope = Stringly.BeginScope(); scope.AddType(typeof(IEnumerable <StringConverter>)); scope.AddType(typeof(System.ComponentModel.StringConverter)); Assert.Equal("IEnumerable<NetFx.StringlyTyped.StringConverter>", scope.GetTypeName(typeof(IEnumerable <StringConverter>))); Assert.True(scope.SafeImports.Contains(typeof(IEnumerable <>).Namespace)); Assert.False(scope.SafeImports.Contains(typeof(StringConverter).Namespace)); }
public void WhenSimplifyingAllCoreLib_ThenAddsUsingForGenericsAndNonGenericComparable() { var scope = Stringly.BeginScope(); scope.AddTypes(typeof(string).Assembly); scope.AddTypes(new[] { typeof(IComparable), typeof(IComparable <string>) }); Assert.Equal("IComparable<String>", scope.GetTypeName(typeof(IComparable <string>))); Assert.Equal("IComparable", scope.GetTypeName(typeof(IComparable))); Assert.True(scope.SafeImports.Contains(typeof(IComparable <>).Namespace)); }
public void WhenSimplifyingTypeMap_ThenOnlySimplifiesNonCollidingTypeNames() { var scope = Stringly.BeginScope(); scope.AddType("Foo.A"); scope.AddType("Foo.B"); scope.AddType("Bar.A"); Assert.Equal("Foo.A", scope.GetTypeName("Foo.A")); Assert.Equal("B", scope.GetTypeName("Foo.B")); Assert.Equal("Bar.A", scope.GetTypeName("Bar.A")); }
public void When_Adding_CSharp_Generic_Then_Simplifies_Generic_Parameters() { var scope = Stringly.BeginScope(); scope.AddType("System.Device.Location.GeoCoordinate"); scope.AddType("System.Device.Location.GeoPositionChangedEventArgs<System.Device.Location.GeoCoordinate>"); scope.AddType("System.EventHandler<System.Device.Location.GeoPositionChangedEventArgs<System.Device.Location.GeoCoordinate>>"); scope.AddType("System.Device.Location.GeoCoordinate"); scope.AddType("System.Device.Location.GeoPositionChangedEventArgs<System.Device.Location.GeoCoordinate>"); Assert.Equal("GeoPositionChangedEventArgs<GeoCoordinate>", scope.GetTypeName("System.Device.Location.GeoPositionChangedEventArgs<System.Device.Location.GeoCoordinate>")); }
public void WhenGettingSafeUsings_ThenOnlyGetsNamespacesFromSimplifiedTypeNames() { var scope = Stringly.BeginScope(); scope.AddType("Foo.A"); scope.AddType("Foo.B"); scope.AddType("Bar.A"); scope.AddType("Baz.C"); Assert.True(scope.SafeImports.Contains("Foo")); Assert.True(scope.SafeImports.Contains("Baz")); Assert.False(scope.SafeImports.Contains("Bar")); }
public void When_Adding_Empty_TypeName_Then_Throws() { var scope = Stringly.BeginScope(); Assert.Throws <ArgumentException>(() => scope.AddType("")); }
public void WhenGettingTypeNameOfTypeNotAdded_ThenReturnsValidCodeName() { var scope = Stringly.BeginScope(); Assert.Equal("System.Lazy<System.String>", scope.GetTypeName(typeof(Lazy <string>))); }