Exemplo n.º 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 SchedulePlanOutput Build(List <SchedulePlan> schedulePlans, int index, List <TaskPlan> taskPlans)
        {
            SchedulePlan schedulePlan = schedulePlans[index];

            SchedulePlanOutput output = new SchedulePlanOutput();

            // Assign duplicated data from the original SchedulePlan object
            output.Week             = schedulePlan.Week;
            output.Begin            = schedulePlan.Begin;
            output.PlannedTaskHours = schedulePlan.PlannedTaskHours;

            // Cumulative planned task hours is the total number of hours that will be spent up to this week
            output.CumulativePlannedTaskHours = Math.Round(schedulePlans
                                                           .Take(index + 1)
                                                           .Select(s => s.PlannedTaskHours)
                                                           .Sum(), 2);

            // Cumulative planned value is the amount of value that will be achieved by the current week
            double sum = 0;

            output.CumulativePlannedValue = Math.Round(taskPlans
                                                       .TakeWhile(t =>
            {
                if (sum >= output.CumulativePlannedTaskHours)
                {
                    // Stop taking TaskPlan objects because we don't have enough time to finish this task
                    return(false);
                }
                else
                {
                    // We will be able to complete this task
                    sum += t.HoursToComplete;
                    return(true);
                }
            })
                                                       .Select(t => t.HoursToComplete)
                                                       .Sum() / output.CumulativePlannedTaskHours, 2);

            // Cumulate planned value is the total percentage value that should be earned up to this week
            output.CumulativePlannedValue = Math.Round(output.CumulativePlannedTaskHours /
                                                       schedulePlans
                                                       .Select(s => s.PlannedTaskHours)
                                                       .Sum(), 2);

            return(output);
        }