Пример #1
0
        public void Build_ForBrowser_ReturnsTree()
        {
            var collection = DependencyTestData.CreateTestDataForTree();

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

            var browserNode = treeBuilder.Build(DependencyTestData.Browser);

            Assert.Equal(DependencyTestData.Browser, browserNode.Element);

            Assert.Equal(2, browserNode.SubNodes.Count);

            var appNode = browserNode.SubNodes.Single(x => x.Element == DependencyTestData.Application);

            Assert.Equal(DependencyTestData.Application, appNode.Element);

            var shellNode = appNode.SubNodes.Single(x => x.Element == DependencyTestData.Shell);

            var vgaDriverNode = shellNode.SubNodes.Single(x => x.Element == DependencyTestData.VgaDriver);

            Assert.Single(vgaDriverNode.SubNodes);

            var kernelNode = vgaDriverNode.SubNodes.First();

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

            Assert.Empty(kernelNode.SubNodes);


            var networkDriverNode = browserNode.SubNodes.Single(x => x.Element == DependencyTestData.NetworkDriver);

            var kernelNode2 = networkDriverNode.SubNodes.Single(x => x.Element == DependencyTestData.Kernel);

            Assert.Empty(kernelNode2.SubNodes);
        }
        public void Sort_CollectionWithCircularReference_ThrowsException()
        {
            var collection = DependencyTestData.CreateTestDataWithCircularReference();

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

            var exception = Assert.Throws <CircularReferenceException>(() => sorter.Sort());

            Assert.Contains(exception.PossibleCircularReferences, x => (string)x == DependencyTestData.Application);
            Assert.Contains(exception.PossibleCircularReferences, x => (string)x == DependencyTestData.Shell);
        }
        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));
        }
Пример #4
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]));
            }
        }
Пример #5
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]));
            }
        }
Пример #6
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);
        }
Пример #8
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);
        }
Пример #9
0
        public void CheckForCircularReferences_CollectionHasCircularReferences_ReturnsTrue()
        {
            var collection = DependencyTestData.CreateTestDataWithCircularReference();

            Assert.True(collection.CheckForCircularReferences());
        }
Пример #10
0
        public void CheckForCircularReferences_CollectionHasNoCircularReferences_ReturnsFalse()
        {
            var collection = DependencyTestData.CreateTestData();

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