예제 #1
0
        public void HierarchyPrinterCreationTest()
        {
            IDataPrinter hierarchyPrinter = new HierarchyPrinter();

            Assert.NotNull(hierarchyPrinter);
            Assert.IsType <HierarchyPrinter>(hierarchyPrinter);
        }
예제 #2
0
        public void HierarchyPrinterPrintStringNotEmptyTest()
        {
            IDataPrinter hierarchyPrinter = new HierarchyPrinter();

            var result = hierarchyPrinter.PrintString(_rootManager);

            Assert.NotEmpty(result);
        }
예제 #3
0
        public void HierarchyPrinterPrintStringTest()
        {
            IDataPrinter hierarchyPrinter = new HierarchyPrinter();

            var result = hierarchyPrinter.PrintString(_rootManager);

            // Expected Output:
            //-----------------
            // Jeff
            // Employees of: Jeff
            //     Dave
            //     Employees of: Dave
            //         Andy
            //         Dan
            //         Jason
            //         Rick
            //         Suzanne
            //     Cory

            var builder = new StringBuilder();

            builder.Append("Jeff\n");
            builder.Append("Employees of: Jeff\n");
            builder.Append("\tDave\n");
            builder.Append("\tEmployees of: Dave\n");
            builder.Append("\t\tAndy\n");
            builder.Append("\t\tDan\n");
            builder.Append("\t\tJason\n");
            builder.Append("\t\tRick\n");
            builder.Append("\t\tSuzanne\n");
            builder.Append("\tCory\n");

            var expectedString = builder.ToString();

            Assert.Equal(expectedString, result);
        }
예제 #4
0
        public void HierarchyPrinterPrintStringArgumentExceptionTest()
        {
            IDataPrinter hierarchyPrinter = new HierarchyPrinter();

            Assert.Throws <ArgumentException>(() => hierarchyPrinter.PrintString(null));
        }
예제 #5
0
        // Main
        static void Main(string[] args)
        {
            // Try to load AppSettings.json configuration file first
            var builder = new ConfigurationBuilder()
                          .SetBasePath(Environment.CurrentDirectory)
                          .AddJsonFile(_AppSettingsFileName);

            // Read the AppSettings file and create a ConfigurationRoot object
            var configs = builder.Build();


            // Get the Employee Hierarchy filename from the AppSettings file
            var employeeHierarchyFileName = configs[_AppSetting_HierarchyFileName];

            // Throw exception if there was a problem
            if (String.IsNullOrEmpty(employeeHierarchyFileName))
            {
                throw new ApplicationException($"ERROR :: Problem reading App Setting '{_AppSetting_HierarchyFileName}'!");
            }


            // Create filepath to Employee Hierarchy json file
            var employeeHierarchyFilePath = Path.Combine(Environment.CurrentDirectory, employeeHierarchyFileName);


            // Convert AppSettings parameter 'SortHierarchyOutput' to Boolean
            var castSortEmployeeHierarchySuccess = bool.TryParse(configs[_AppSetting_SortHierarchyOutput], out bool sortEmployeeHierarchy);

            if (castSortEmployeeHierarchySuccess == false)
            {
                throw new ApplicationException($"ERROR :: Problem reading App Setting '{_AppSetting_SortHierarchyOutput}'!");
            }


            // Use the Composition Root & Dependency Injection patterns to compose the application's functionality
            // IFormatReader formatReader = new MockFormatReader();
            IFormatReader formatReader     = new JsonFormatReader(employeeHierarchyFilePath);
            IDataReader   dataReader       = new DataReader(formatReader);
            IDataPrinter  hierarchyPrinter = null;


            // If AppSettings parameter 'SortHierarchyOutput' set to True: create 'SortedHierarchyPrinter'
            //  otherwise, create an unsorted 'HierarchyPrinter'
            if (sortEmployeeHierarchy)
            {
                hierarchyPrinter = new SortedHierarchyPrinter();
            }
            else
            {
                hierarchyPrinter = new HierarchyPrinter();
            }


            // Create the Salaray Requirement Printer
            IDataPrinter salaryRequirementPrinter = new SalaryRequirementPrinter();


            // Read Employee data from the data source
            var rootManager = dataReader.Read();


            // Get String representations for the Employee Hierarchy & Salary Requirement
            var hierarchyString         = hierarchyPrinter.PrintString(rootManager);
            var salaryRequirementString = salaryRequirementPrinter.PrintString(rootManager);


            // Print the Employee Hierarchy & Salary Requirement
            Console.WriteLine(hierarchyString);
            Console.WriteLine(salaryRequirementString);

            // Keep the console window open
            Console.WriteLine("\n\nPress 'enter' to exit...");
            Console.ReadLine();
        }