TestCollection FindOrCreateNamespace(TestCollection collection, string parentNamespace, string @namespace)
        {
            if (parentNamespace == @namespace)
            {
                return(collection);
            }
            foreach (var node in collection.OfType <TestNamespace>())
            {
                if (@namespace == node.NamespaceName)
                {
                    return(node.NestedTests);
                }
                if (@namespace.StartsWith(node.NamespaceName + ".", StringComparison.Ordinal))
                {
                    return(FindOrCreateNamespace(node.NestedTests, node.NamespaceName, @namespace));
                }
            }
            // Create missing namespace node:

            // Figure out which part of the namespace we can remove due to the parent namespace:
            int startPos = 0;

            if (@namespace.StartsWith(parentNamespace + ".", StringComparison.Ordinal))
            {
                startPos = parentNamespace.Length + 1;
            }
            // Get the next dot
            int dotPos = @namespace.IndexOf('.', startPos);

            if (dotPos < 0)
            {
                var newNode = new TestNamespace(this, @namespace);
                collection.Add(newNode);
                return(newNode.NestedTests);
            }
            else
            {
                var newNode = new TestNamespace(this, @namespace.Substring(0, dotPos));
                collection.Add(newNode);
                return(FindOrCreateNamespace(newNode.NestedTests, newNode.NamespaceName, @namespace));
            }
        }
		TestCollection FindOrCreateNamespace(TestCollection collection, string parentNamespace, string @namespace)
		{
			if (parentNamespace == @namespace)
				return collection;
			foreach (var node in collection.OfType<TestNamespace>()) {
				if (@namespace == node.NamespaceName)
					return node.NestedTests;
				if (@namespace.StartsWith(node.NamespaceName + ".", StringComparison.Ordinal)) {
					return FindOrCreateNamespace(node.NestedTests, node.NamespaceName, @namespace);
				}
			}
			// Create missing namespace node:
			
			// Figure out which part of the namespace we can remove due to the parent namespace:
			int startPos = 0;
			if (@namespace.StartsWith(parentNamespace + ".", StringComparison.Ordinal)) {
				startPos = parentNamespace.Length + 1;
			}
			// Get the next dot
			int dotPos = @namespace.IndexOf('.', startPos);
			if (dotPos < 0) {
				var newNode = new TestNamespace(this, @namespace);
				collection.Add(newNode);
				return newNode.NestedTests;
			} else {
				var newNode = new TestNamespace(this, @namespace.Substring(0, dotPos));
				collection.Add(newNode);
				return FindOrCreateNamespace(newNode.NestedTests, newNode.NamespaceName, @namespace);
			}
		}
		public void TestNamespaceSpecifiedInInitialize()
		{
			var testNamespace = new TestNamespace(testProject, "Project.MyTests");
			NUnitConsoleApplication app = new NUnitConsoleApplication(new[] { testNamespace });
			app.NoLogo = false;
			app.ShadowCopy = true;
			app.NoXmlOutputFile = false;
			
			string expectedCommandLine = "\"C:\\Projects\\MyTests\\MyTests.dll\" /run=\"Project.MyTests\"";
			Assert.AreEqual(expectedCommandLine, app.GetArguments());
		}