private static TestDataNode AddMetadataNode(TestData testData, string metadataType, 
     TestTreeNode rootNode, Node parentNode)
 {
     var testDataNode = new TestDataNode(testData);
     
     var metadataList = testData.Metadata[metadataType];
     if (metadataList.Count > 0)
     {
         foreach (string metadata in metadataList)
         {
             var metadataNode = FindOrAddMetadataNode(metadataType, rootNode, metadata);
             metadataNode.Nodes.Add(testDataNode);
             testDataNode = new TestDataNode(testData); // can't re-use node
         }
     }
     else if (parentNode != null)
     {
         parentNode.Nodes.Add(testDataNode);
     }
     else
     {
         var metadataNode = FindOrAddMetadataNode(metadataType, rootNode, "None");
         metadataNode.Nodes.Add(testDataNode);
     }
     return testDataNode;
 }
        private static TestTreeNode AddNode(TestData testData, TestTreeNode parent,
            TreeBuilderOptions options)
        {
            var testTreeNode = new TestDataNode(testData);

            if (options.NamespaceHierarchy == NamespaceHierarchy.Flat)
            {
                if (FixtureNode(testData) && parent.TestKind != TestKinds.Namespace)
                {
                    var @namespace = testData.CodeReference.NamespaceName;
                    parent = FindOrAddNamespaceNode(parent, @namespace, @namespace);
                }
                else if (testTreeNode.TestKind == TestKinds.Namespace)
                {
                    return parent;
                }
            }

            if (FixtureNode(testData) && parent.TestKind != TestKinds.Namespace) 
            {
                parent = BuildNamespaceNode(testData, parent, options);
            }
            
            parent.Nodes.Add(testTreeNode);
         
            return testTreeNode;
        }
        public void Text_should_be_name_from_test_data()
        {
            var testData = new TestData("id", "name", "fullName");

            var testDataNode = new TestDataNode(testData);

            Assert.AreEqual(testData.Name, testDataNode.Text);
        }
        public void Test_kind_should_be_group_if_metadata_unavailable()
        {
            var testData = new TestData("id", "name", "fullName");

            var testDataNode = new TestDataNode(testData);

            Assert.AreEqual(TestKinds.Group, testDataNode.TestKind);
        }
        public void File_name_should_come_from_metadata_if_available()
        {
            var testData = new TestData("id", "name", "fullName");
            const string file = "blahblah";
            testData.Metadata.Add(MetadataKeys.File, file);

            var testDataNode = new TestDataNode(testData);

            Assert.AreEqual(file, testDataNode.FileName);
        }
        public void Test_kind_should_come_from_metadata_if_available()
        {
            var testData = new TestData("id", "name", "fullName");
            const string testKind = TestKinds.Assembly;
            testData.Metadata.Add(MetadataKeys.TestKind, testKind);

            var testDataNode = new TestDataNode(testData);

            Assert.AreEqual(testKind, testDataNode.TestKind);
        }
        public TestTreeNode BuildTree(IProgressMonitor progressMonitor, TestModelData testModelData,
            TreeBuilderOptions options)
        {
            var root = new TestDataNode(testModelData.RootTest);

            progressMonitor.Worked(1);

            PopulateNamespaceTree(progressMonitor, testModelData.RootTest.Children, 
                root, options);

            return root;
        }
        public void If_applied_filter_set_is_any_filter_then_the_root_should_be_checked()
        {
            var testTreeNode = new TestDataNode(new TestData("root", "root", "root"))
            {
                CheckState = CheckState.Unchecked
            };
            testTreeModel.Stub(ttm => ttm.Root).Return(testTreeNode);           
            var filterSet = new FilterSet<ITestDescriptor>(new AnyFilter<ITestDescriptor>());

            filterService.ApplyFilterSet(filterSet);

            Assert.AreEqual(CheckState.Checked, testTreeNode.CheckState);
        }
        public TestTreeNode BuildTree(IProgressMonitor progressMonitor, 
            TestModelData testModelData, TreeBuilderOptions options)
        {
            var root = new TestDataNode(testModelData.RootTest);

            progressMonitor.Worked(1);

            foreach (var childTestData in testModelData.RootTest.Children)
            {
                PopulateMetadataTree(progressMonitor, options.TreeViewCategory, 
                    childTestData, null, root);
            }

            return root;
        }
        public void Filter_sets_should_be_applied_appropriately()
        {
            var root = new TestDataNode(new TestData("root", "root", "root"));
            var test1 = new TestDataNode(new TestData("test1", "test1", "test1"));
            var test2 = new TestDataNode(new TestData("test2", "test2", "test2"));
            root.Nodes.Add(test1);
            root.Nodes.Add(test2);
            testTreeModel.Stub(ttm => ttm.Root).Return(root);
            var filterSet = new FilterSet<ITestDescriptor>(new OrFilter<ITestDescriptor>(new[]
            {
                new IdFilter<ITestDescriptor>(new EqualityFilter<string>("test2"))
            }));

            filterService.ApplyFilterSet(filterSet);

            Assert.AreEqual(CheckState.Indeterminate, root.CheckState);
            Assert.AreEqual(CheckState.Unchecked, test1.CheckState);
            Assert.AreEqual(CheckState.Checked, test2.CheckState);
        }
        public void SourceCodeAvailable_should_be_false_if_code_location_is_unknown()
        {
            var testData = new TestData("id", "name", "fullName")
            {
                CodeLocation = CodeLocation.Unknown
            };

            var testDataNode = new TestDataNode(testData);

            Assert.IsFalse(testDataNode.SourceCodeAvailable);
        }
        public void File_name_should_be_null_if_metadata_unavailable()
        {
            var testData = new TestData("id", "name", "fullName");

            var testDataNode = new TestDataNode(testData);

            Assert.IsNull(testDataNode.FileName);
        }
        public void CheckState_should_be_checked_otherwise()
        {
            var testData = new TestData("id", "name", "fullName");

            var testDataNode = new TestDataNode(testData);

            Assert.AreEqual(CheckState.Checked, testDataNode.CheckState);
        }
        public void CheckState_should_be_unchecked_if_test_is_pending()
        {
            var testData = new TestData("id", "name", "fullName");
            testData.Metadata.Add(MetadataKeys.PendingReason, "");

            var testDataNode = new TestDataNode(testData);

            Assert.AreEqual(CheckState.Unchecked, testDataNode.CheckState);
        }
        public void IsTest_should_be_same_as_test_data()
        {
            var testData = new TestData("id", "name", "fullName")
            {
                IsTestCase = true
            };

            var testDataNode = new TestDataNode(testData);

            Assert.AreEqual(testData.IsTestCase, testDataNode.IsTest);
        }
        public void SourceCodeAvailable_should_be_true_if_code_location_is_set()
        {
            var testData = new TestData("id", "name", "fullName")
            {
                CodeLocation = new CodeLocation("", 1, 1)
            };

            var testDataNode = new TestDataNode(testData);

            Assert.IsTrue(testDataNode.SourceCodeAvailable);
        }