示例#1
0
        public void Should_Calculate_Earned_Value_Plan_And_Validate_Data(
            string schedulePlanPath,
            string taskPlanPath,
            string schedulePlanCorrectOutputPath,
            string taskPlanCorrectOutputPath)
        {
            // Read in the data from file
            List <SchedulePlan> schedulePlans = ReadSchedulePlan(schedulePlanPath);
            List <TaskPlan>     taskPlans     = ReadTaskPlan(taskPlanPath);

            // Validate the data, catching any illegal formatting
            Validator.Validate(schedulePlans);
            Validator.Validate(taskPlans);

            // Deserialize expected results
            List <SchedulePlanOutput> expectedSchedulePlanOutputs = ReadSchedulePlanOutputs(schedulePlanCorrectOutputPath);
            List <TaskPlanOutput>     expectedTaskPlanOutputs     = ReadTaskPlanOutputs(taskPlanCorrectOutputPath);

            // Generate & process the input data into the transformed output data
            List <SchedulePlanOutput> schedulePlanOutput = new List <SchedulePlanOutput>();

            for (int i = 0; i < schedulePlans.Count; i++)
            {
                SchedulePlanOutput result   = Builder.Build(schedulePlans, i, taskPlans);
                SchedulePlanOutput expected = expectedSchedulePlanOutputs[i];

                Assert.True(result.Begin.Equals(expected.Begin));
                Assert.True(result.CumulativePlannedTaskHours.Equals(expected.CumulativePlannedTaskHours));
                Assert.True(result.CumulativePlannedValue.Equals(expected.CumulativePlannedValue));
                Assert.True(result.PlannedTaskHours.Equals(expected.PlannedTaskHours));
                Assert.True(result.Week.Equals(expected.Week));

                schedulePlanOutput.Add(result);
            }
            Assert.True(schedulePlanOutput.Count.Equals(expectedSchedulePlanOutputs.Count));

            List <TaskPlanOutput> taskPlanOutput = new List <TaskPlanOutput>();

            for (int i = 0; i < taskPlans.Count; i++)
            {
                TaskPlanOutput result   = Builder.Build(taskPlans, i, schedulePlans);
                TaskPlanOutput expected = expectedTaskPlanOutputs[i];

                Assert.True(result.CumulativePlannedValue.Equals(expected.CumulativePlannedValue));
                Assert.True(result.CumulativeTaskHours.Equals(expected.CumulativeTaskHours));
                Assert.True(result.HoursToComplete.Equals(expected.HoursToComplete));
                Assert.True(result.PlannedValue.Equals(expected.PlannedValue));
                Assert.True(result.Task.Equals(expected.Task));
                Assert.True(result.WeekOfPlannedCompletion.Equals(expected.WeekOfPlannedCompletion));

                taskPlanOutput.Add(result);
            }
            Assert.True(taskPlanOutput.Count.Equals(expectedTaskPlanOutputs.Count));

            OutputData(schedulePlanPath, schedulePlanOutput, taskPlanPath, taskPlanOutput);
        }
        public TaskPlanOutput Build(List <TaskPlan> taskPlans, int index, List <SchedulePlan> schedulePlans)
        {
            TaskPlan taskPlan = taskPlans[index];

            TaskPlanOutput output = new TaskPlanOutput();

            // Assign duplicated data from the original TaskPlan object
            output.Task            = taskPlan.Task;
            output.HoursToComplete = taskPlan.HoursToComplete;

            // Cumulative task hours is the total number of hours spent on this project up through completing this task
            output.CumulativeTaskHours = Math.Round(taskPlans
                                                    .Take(index + 1)
                                                    .Select(t => t.HoursToComplete)
                                                    .Sum(), 2);

            // Planned value is the percentage of time this task will take out of all time allocated for this project
            output.PlannedValue = Math.Round(taskPlan.HoursToComplete /
                                             taskPlans
                                             .Select(t => t.HoursToComplete)
                                             .Sum(), 2);

            // Cumulative planned value is the value earned from the start of this project to the end of the current
            // task
            output.CumulativePlannedValue = Math.Round(output.CumulativeTaskHours /
                                                       taskPlans
                                                       .Select(t => t.HoursToComplete)
                                                       .Sum(), 2);

            // The week in which this task is planned to be completed
            double sum = 0; // Sum of scheduled hours up to the current week

            output.WeekOfPlannedCompletion = schedulePlans
                                             .TakeWhile(s => {
                if (sum >= output.CumulativeTaskHours)
                {
                    // Stop taking SchedulePlan objects if we have exceeded the hours necessary to complete this
                    // task
                    return(false);
                }
                else
                {
                    // We need more planned hours to completed this task. Keep iterating over the weeks.
                    sum += s.PlannedTaskHours;
                    return(true);
                }
            })
                                             // TODO: Will throw an exception if the first SchedulePlan's planned task hours is zero
                                             .Last().Week;

            return(output);
        }