public void Resolve_ForElement_ReturnsDependentElements(string element, params string[] expectedDependencies)
        {
            var collection = DependencyTestData.CreateTestData();

            var resolver = new DependencyResolver <string>(collection);

            var dependencies = resolver.Resolve(element).ToArray();

            Assert.Equal(expectedDependencies.Length, dependencies.Length);

            dependencies.ForEach(x => Assert.Contains(dependencies, item => item == x));
        }
Пример #2
0
        public void RemoveRedundancies_CollectionHasNoRedundancies_CollectionIsLikeBefore()
        {
            var collection = DependencyTestData.CreateTestData();

            collection.RemoveRedundancies();

            var expected = DependencyTestData.CreateTestData();

            Assert.Equal(expected.DependencyObjects.Count, collection.DependencyObjects.Count);

            for (var i = 0; i < expected.DependencyObjects.Count; i++)
            {
                Assert.True(AreEqual(expected.DependencyObjects.ToList()[i], collection.DependencyObjects.ToList()[i]));
            }
        }
Пример #3
0
        public void AddElement_ElementIsNull()
        {
            var collection = DependencyTestData.CreateTestData();

            collection.AddElement(null);

            var expected = DependencyTestData.CreateTestData();

            Assert.Equal(expected.DependencyObjects.Count, collection.DependencyObjects.Count);

            for (var i = 0; i < expected.DependencyObjects.Count; i++)
            {
                Assert.True(AreEqual(expected.DependencyObjects.ToList()[i], collection.DependencyObjects.ToList()[i]));
            }
        }
Пример #4
0
        public void RemoveRedundancies_CollectionHasRedundancies_CollectionIsWithoutRedundancies()
        {
            var collection = DependencyTestData.CreateTestData();

            collection.AddDependency(DependencyTestData.Application, DependencyTestData.Shell);
            collection.AddDependency(DependencyTestData.Application, DependencyTestData.Cpu);

            collection.RemoveRedundancies();

            var expected = DependencyTestData.CreateTestData();

            Assert.Equal(expected.DependencyObjects.Count, collection.DependencyObjects.Count);

            for (var i = 0; i < expected.DependencyObjects.Count; i++)
            {
                Assert.True(AreEqual(expected.DependencyObjects.ToList()[i], collection.DependencyObjects.ToList()[i]));
            }
        }
        public void Sort_CorrectCollection_ReturnCorrectSortedElements()
        {
            var collection = DependencyTestData.CreateTestData();

            var sorter = new DependencySorter <string>(collection);

            var result = sorter.Sort().ToArray();

            var expected =
                new[]
            {
                DependencyTestData.Cpu,
                DependencyTestData.Kernel,
                DependencyTestData.VgaDriver,
                DependencyTestData.Shell,
                DependencyTestData.Application
            };

            Assert.Equal(expected, result);
        }
Пример #6
0
        public void Build_ForVgaDriver_ReturnsTree()
        {
            var collection = DependencyTestData.CreateTestData();

            var treeBuilder = new DependencyTreeBuilder <string>(collection);

            var vgaDriverNode = treeBuilder.Build(DependencyTestData.VgaDriver);

            Assert.Equal(DependencyTestData.VgaDriver, vgaDriverNode.Element);

            Assert.Single(vgaDriverNode.SubNodes);

            var kernelNode = vgaDriverNode.SubNodes.First();

            Assert.Equal(DependencyTestData.Kernel, kernelNode.Element);

            Assert.Single(kernelNode.SubNodes);

            var cpuNode = kernelNode.SubNodes.First();

            Assert.Equal(DependencyTestData.Cpu, cpuNode.Element);

            Assert.Empty(cpuNode.SubNodes);
        }
Пример #7
0
        public void CheckForCircularReferences_CollectionHasNoCircularReferences_ReturnsFalse()
        {
            var collection = DependencyTestData.CreateTestData();

            Assert.False(collection.CheckForCircularReferences());
        }