public void SortByPrerequisite_InvalidDependency_ThrowsException()
        {
            // Arrange
            ClassLogic logic = new ClassLogic();
            List<string> inputStringArray = new List<string>
            {
                @"TestClass2:TestClass3", @"TestClass1"
            };

            // Act and Assert
            DependencyException<ClassItem> exception = Assert.Throws<DependencyException<ClassItem>>(() => logic.SortByPrerequisite(inputStringArray));
            Assert.Equal(1, exception.AffectedItems.Count);
            Assert.Equal("TestClass3", exception.AffectedItems[0].Name);
        }
        public void SortByPrerequisite_SingleClassNoDependencySpecified_CanSortByPrerequisite()
        {
            // Arrange
            ClassLogic logic = new ClassLogic();
            List<string> inputStringArray = new List<string>
            {
                @"TestClass1"
            };

            // Act
            List<string> sortedArray = logic.SortByPrerequisite(inputStringArray).ToList();

            // Assert
            Assert.Equal(1, sortedArray.Count);
            Assert.Equal("TestClass1", sortedArray[0]);
        }
        public void SortByPrerequisite_EmptyLine_CanSortByPrerequisite()
        {
            // Arrange
            ClassLogic logic = new ClassLogic();
            List<string> inputStringArray = new List<string>
            {
                @"TestClass2:TestClass1", "		 ", @"TestClass1"
            };

            // Act
            List<string> sortedArray = logic.SortByPrerequisite(inputStringArray).ToList();

            // Assert
            Assert.Equal(2, sortedArray.Count);
            Assert.Equal("TestClass1", sortedArray[0]);
            Assert.Equal("TestClass2", sortedArray[1]);
        }
Exemplo n.º 4
0
        static void Main(string[] args)
        {
            if (args.Count() != 1)
            {
                Console.WriteLine("Usage: Justin.1800Contacts.App.Exe [source]");
                Console.WriteLine();
                Console.WriteLine("\tsource\tSpecifies the location of the source file.");
                Console.WriteLine();
                Console.WriteLine("Press any key to continue...");
                Console.ReadKey();
            }

            string sourceFilePath = args[0];
            if (!File.Exists(sourceFilePath))
            {
                Console.WriteLine("'{0}' could not be found.", sourceFilePath);
                Console.WriteLine();
                Console.WriteLine("Press any key to continue...");
                Console.ReadKey();
            }

            try
            {
                IList<string> fileInputList = new List<string>();
                using (StreamReader file = new StreamReader(sourceFilePath))
                {
                    string line;
                    while((line = file.ReadLine()) != null)
                    {
                        fileInputList.Add(line);
                    }
                }

                IClassLogic classLogic = new ClassLogic();
                Console.WriteLine(string.Join(", ", classLogic.SortByPrerequisite(fileInputList)));
            }
            catch (Exception e)
            {
                Console.WriteLine("Error: {0}", e.Message);
            }

            Console.WriteLine();
            Console.WriteLine("Press any key to continue...");
            Console.ReadKey();
        }