PrepareNamespaceImports() public method

Prepares the specified namespace imports to prevent collisions with the types under test.
This method detects problematic namespaces like in the example below and prefixes them with global:: to prevent namespace collisions in the test unit files.

The namespace of the object to test is so the unit test becomes:

Take a look at the 'using MbUnit.Framework' import. In that way it conflicts with the 'NStub.CSharp.MbUnit' import and circumvents the name resolution of the TestAttribute. This method detects such concerns and puts a global:: prefix in front of the 'MbUnit.Framework' namespace import.

public PrepareNamespaceImports ( IEnumerable imports ) : IEnumerable
imports IEnumerable The namespace imports.
return IEnumerable
コード例 #1
0
ファイル: NamespaceDetectorTest.cs プロジェクト: Jedzia/NStub
        public void PrepareNamespaceImportsTest()
        {
            var imports = new[] { "System","System.Linq", "MbUnit.Framework" };
            var expected = ".Tests.SubNamespace";
            var actual = testObject.PrepareNamespaceImports(imports);
            Assert.AreElementsEqual(imports, actual.Select(e => e.Namespace));

            var expectedPrepared = new[] { "System", "System.Linq", "global::MbUnit.Framework" };
            typeDeclarations.Add(new CodeTypeDeclaration("Jedzia.Loves.Testing.MbUnit.SubClass"));
            this.testObject = new NamespaceDetector(this.typeDeclarations);
            actual = testObject.PrepareNamespaceImports(imports);
            Assert.AreElementsEqual(expectedPrepared, actual.Select(e => e.Namespace));
        }