示例#1
0
        public void TwoPairsOfOverlappingEmployees_ShouldReturnLongerOverlappingEmployees()
        {
            // Arrange
            var employees = new List <Employee>
            {
                new Employee {
                    EmployeeId = 1, TeamId = 1, DateFrom = new DateTime(2017, 5, 5), DateTo = new DateTime(2017, 5, 10)
                },
                new Employee {
                    EmployeeId = 2, TeamId = 1, DateFrom = new DateTime(2017, 5, 5), DateTo = new DateTime(2017, 5, 10)
                },
                new Employee {
                    EmployeeId = 3, TeamId = 2, DateFrom = new DateTime(2017, 5, 5), DateTo = new DateTime(2017, 5, 8)
                },
                new Employee {
                    EmployeeId = 4, TeamId = 2, DateFrom = new DateTime(2017, 5, 5), DateTo = new DateTime(2017, 5, 10)
                }
            };

            var engine = new TeamWorkPeriodsEngine();

            // Act
            var result = engine.GetLongestPeriodEmployees(employees);

            // Assert
            Assert.Equal(TimeSpan.FromDays(5), result.WorkedTogetherFor);
            Assert.Equal(1, result.FirstEmployee.TeamId);
            Assert.InRange(result.FirstEmployee.EmployeeId, 1, 2);
            Assert.InRange(result.SecondEmployee.EmployeeId, 1, 2);
        }
示例#2
0
        public static void Main(string[] args)
        {
            while (true)
            {
                try
                {
                    Console.Write("Please insert a path to the text file for Employees and Teams, or type EXIT to end the application: ");
                    var input = Console.ReadLine();

                    if (input.ToUpper() == TerminationLiteral)
                    {
                        break;
                    }

                    if (!File.Exists(input))
                    {
                        Console.WriteLine("File does not exist - please input a valid path to a text file!");
                        continue;
                    }

                    var fileStream = new FileStream(input, FileMode.Open);

                    var employeesTeamsPeriods = DataConverter.Convert(fileStream);

                    if (employeesTeamsPeriods == null)
                    {
                        Console.WriteLine("File is empty, or is not in the proper format!(HINT: EmpID, ProjectID, DateFrom, DateTo)");
                        continue;
                    }

                    var engine    = new TeamWorkPeriodsEngine();
                    var employees = engine.GetLongestPeriodEmployees(employeesTeamsPeriods);

                    if (employees == null)
                    {
                        Console.WriteLine("No overlapping employees found - please check the text file and make sure there are employees that have worked together.");
                        continue;
                    }

                    Console.WriteLine($"The employees who've worked together the longest are: {employees.FirstEmployee.EmployeeId} and {employees.SecondEmployee.EmployeeId} for a total of {employees.WorkedTogetherFor.Days} days in team {employees.FirstEmployee.TeamId}.");

                    Console.Write("If you'd like to continue, enter any key, or type in EXIT to exit the application: ");
                    var endOfCycleCommand = Console.ReadLine();

                    if (endOfCycleCommand == TerminationLiteral)
                    {
                        break;
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Error during application execution - something went wrong.");
                    // TODO: Log the exception
                }
            }
        }
示例#3
0
        public void OnePairOfOverlappingEmployees_ShouldBeReturned()
        {
            // Arrange
            var employees = new List <Employee>
            {
                new Employee {
                    EmployeeId = 1, TeamId = 1, DateFrom = new DateTime(2017, 5, 5), DateTo = new DateTime(2017, 5, 10)
                },
                new Employee {
                    EmployeeId = 2, TeamId = 1, DateFrom = new DateTime(2017, 5, 5), DateTo = new DateTime(2017, 5, 10)
                }
            };

            var engine = new TeamWorkPeriodsEngine();

            // Act
            var result = engine.GetLongestPeriodEmployees(employees);

            // Assert
            Assert.Equal(TimeSpan.FromDays(5), result.WorkedTogetherFor);
        }