Exemple #1
0
        public void ShouldNotGenerateMilestonesForGoalIfTheyExistAlready()
        {
            //Arrange
            const int expectedGoalId = 10;
            const string expectedGoalName = "Testing Goal";
            Goal goal = new Goal(expectedGoalId, expectedGoalName, "Test", 100, GoalStatus.Open, false);

            //Set up the mocks
            mockRepository.Setup(r => r.GetForGoal(It.Is<int>(val => val == expectedGoalId)))
                .Returns(new List<Milestone>() { new Milestone(10, 100, "Testing", null) });

            IMilestoneService service = new MilestoneService(mockRepository.Object);

            //Act
            Action failAction = () => service.GenerateMilestones(goal).ToArray();
            failAction.Should().Throw<Exception>();
        }
Exemple #2
0
        public void ShouldGenerateMilestonesForGoal()
        {
            //Arrange
            const int expectedGoalId = 10;
            const string expectedGoalName = "Testing Goal";
            Goal goal = new Goal(expectedGoalId, expectedGoalName, "Test", 100, GoalStatus.Open, false);

            //Set up the mocks
            mockRepository.Setup(r => r.GetForGoal(It.Is<int>(val => val == expectedGoalId))).Returns(new List<Milestone>());
            mockRepository.Setup(r => r.CreateMultipleForGoal(It.IsAny<IEnumerable<Milestone>>(), It.Is<int>(val => val == expectedGoalId)))
            .Returns<IEnumerable<Milestone>, int>
            (
                (unsavedMilestones, goalId) =>
                {
                    int id = 1;
                    foreach (var milestone in unsavedMilestones)
                    {
                        milestone.Id = id;
                        id++;
                    }
                    return unsavedMilestones;
                }
            );
            IMilestoneService service = new MilestoneService(mockRepository.Object);

            //Act
            Milestone[] milestones = service.GenerateMilestones(goal).ToArray();

            //Assert
            milestones.Should().NotBeNull();
            milestones.Count().Should().Be(EXPECTED_GENERATION_COUNT);
            milestones.Select(m => m.Id).Should().BeInAscendingOrder();
            for (int i = 1; i <= EXPECTED_GENERATION_COUNT; i++)
            {
                Milestone testMilestone = milestones[i - 1];
                testMilestone.Target.Should().Be((goal.Target / EXPECTED_GENERATION_COUNT) * i);
                testMilestone.Description.Should().Be($"{goal.Name} - {i}/{EXPECTED_GENERATION_COUNT} completed!");
            }
        }