示例#1
0
        public void WhenAddingAssembly_ThenSafeUsingsDoNotContainGenerics()
        {
            var codegen = new CodeGeneration();

            codegen.AddType(typeof(IEnumerable <string>));
            codegen.AddType(typeof(IEnumerable));
            codegen.EndInit();

            Assert.False(codegen.SafeImports.Any(s => s.IndexOf('[') != -1));
        }
示例#2
0
        public void WhenTypeMapContainsFullNameAndAssemblyQualified_ThenAddsUsingAndSimplifiesBoth()
        {
            var codegen = new CodeGeneration();

            codegen.AddType("Foo.Bar, Foo");
            codegen.AddType("Foo.Bar");
            codegen.EndInit();

            Assert.Equal("Bar", codegen.GetTypeName("Foo.Bar, Foo"));
            Assert.Equal("Bar", codegen.GetTypeName("Foo.Bar"));
            Assert.True(codegen.SafeImports.Contains("Foo"));
        }
示例#3
0
        public void WhenSimplifyingGenericTypeWithCollidingParameter_ThenKeepsParameterFullName()
        {
            var codegen = new CodeGeneration();

            codegen.AddType(typeof(IEnumerable <StringConverter>));
            codegen.AddType(typeof(System.ComponentModel.StringConverter));
            codegen.EndInit();

            Assert.Equal("IEnumerable<NuPattern.Runtime.UnitTests.CodeGen.StringConverter>", codegen.GetTypeName(typeof(IEnumerable <StringConverter>)));
            Assert.True(codegen.SafeImports.Contains(typeof(IEnumerable <>).Namespace));
            Assert.False(codegen.SafeImports.Contains(typeof(StringConverter).Namespace));
        }
示例#4
0
        public void WhenSimplifyingMultipleGenerics_ThenSimplifiesAllParameters()
        {
            var codegen = new CodeGeneration();
            var type    = typeof(IDictionary <IList <KeyValuePair <string, StringConverter> >, NestedType>);

            codegen.AddType(type);
            codegen.AddType(typeof(System.ComponentModel.StringConverter));
            codegen.EndInit();

            Assert.Equal("IDictionary<IList<KeyValuePair<String, NuPattern.Runtime.UnitTests.CodeGen.StringConverter>>, CodeGenerationSpec.NestedType>", codegen.GetTypeName(type));
            Assert.True(codegen.SafeImports.Contains(typeof(IEnumerable <>).Namespace));
            Assert.True(codegen.SafeImports.Contains(typeof(CodeGenerationSpec).Namespace));
        }
示例#5
0
        public void WhenSimplifyingGenericAndNonGenericEnumerable_ThenAddsUsingForBoth()
        {
            var codegen = new CodeGeneration();

            codegen.AddType(typeof(IEnumerable <string>));
            codegen.AddType(typeof(IEnumerable));
            codegen.EndInit();

            Assert.Equal("IEnumerable<String>", codegen.GetTypeName(typeof(IEnumerable <string>)));
            Assert.Equal("IEnumerable", codegen.GetTypeName(typeof(IEnumerable)));
            Assert.True(codegen.SafeImports.Contains(typeof(IEnumerable <>).Namespace));
            Assert.True(codegen.SafeImports.Contains(typeof(IEnumerable).Namespace));
        }
示例#6
0
        public void WhenSimplifyingGenericType_ThenAddsUsingsAndSimplifiesGenericParameterType()
        {
            var codegen = new CodeGeneration();

            codegen.AddType(typeof(IEnumerable <NonNestedType>));
            codegen.EndInit();

            Assert.Equal("IEnumerable<NonNestedType>", codegen.GetTypeName(typeof(IEnumerable <NonNestedType>)));
            Assert.True(codegen.SafeImports.Contains(typeof(IEnumerable <>).Namespace));
            Assert.True(codegen.SafeImports.Contains(typeof(NonNestedType).Namespace));
        }
示例#7
0
        public void WhenSimplifyingGenericTypeWithNestedTypeParameter_ThenRemovesPlusFromNestedTypeName()
        {
            var codegen = new CodeGeneration();

            codegen.AddType(typeof(IEnumerable <NestedType>));
            codegen.EndInit();

            Assert.Equal("IEnumerable<CodeGenerationSpec.NestedType>", codegen.GetTypeName(typeof(IEnumerable <NestedType>)));
            Assert.True(codegen.SafeImports.Contains(typeof(IEnumerable <>).Namespace));
            Assert.True(codegen.SafeImports.Contains(typeof(NestedType).Namespace));
            Assert.False(codegen.SafeImports.Contains(typeof(CodeGenerationSpec).FullName), "The nested type parent should not be mistaken for a namespace.");
        }
示例#8
0
        public void WhenSimplifyingAllCoreLib_ThenAddsUsingForGenericsAndNonGenericEnumerable()
        {
            var codegen = new CodeGeneration();

            codegen.AddTypes(typeof(string).Assembly);
            codegen.AddType(typeof(IComparable <string>));
            codegen.EndInit();

            Assert.Equal("IComparable<String>", codegen.GetTypeName(typeof(IComparable <string>)));
            Assert.Equal("IComparable", codegen.GetTypeName(typeof(IComparable)));
            Assert.True(codegen.SafeImports.Contains(typeof(IComparable <>).Namespace));
        }