Example #1
0
        public void ShouldCreateMilestoneForGoal()
        {
            //Arrange
            const int expectedMilestoneId = 10, expectedGoalId = 13;
            Milestone milestone = new Milestone(100d, "Testing", null);
            Goal goal = new Goal(expectedGoalId, "Testing Goal", "Testing", 1000d, GoalStatus.Open, false);

            //Act

            //Set up the mocks
            mockRepository.Setup(r => r.GetForGoal(It.Is<int>(val => val == expectedGoalId))).Returns(new List<Milestone>());
            mockRepository.Setup(r => r.CreateForGoal(It.IsAny<Milestone>(), It.Is<int>(val => val == expectedGoalId)))
            .Returns<Milestone, int>
            (
                (unsavedMilestone, goalId) =>
                {
                    unsavedMilestone.Id = expectedMilestoneId;
                    return unsavedMilestone;
                }
            );
            IMilestoneService service = new MilestoneService(mockRepository.Object);

            //Act
            Milestone createdMilestone = service.CreateMilestoneForGoal(milestone, goal);

            //Assert
            createdMilestone.Should().NotBeNull();
            createdMilestone.Id.Should().Be(expectedMilestoneId);
            createdMilestone.Should().BeEquivalentTo(milestone);
        }
Example #2
0
        public void ShouldNotCreateMilestoneForGoalIfTargetIsZeroOrBelow()
        {
            //Arrange
            const int expectedGoalId = 13;
            Milestone milestone = new Milestone(0d, "Testing", null);
            Goal goal = new Goal(expectedGoalId, "Testing Goal", "Testing", 100d, GoalStatus.Open, false);

            //Act

            //Set up the mocks
            IMilestoneService service = new MilestoneService(mockRepository.Object);

            //Act
            Action failAction = () => service.CreateMilestoneForGoal(milestone, goal);

            //Assert
            failAction.Should().Throw<ArgumentException>();
        }
Example #3
0
        public void ShouldNotCreateMilestoneForAGoalWithADuplicateTargetValue()
        {
            //Arrange
            const double collisionTargetValue = 250d;
            const int expectedGoalId = 13;
            Milestone milestone = new Milestone(collisionTargetValue, "Testing", null);
            Goal goal = new Goal(expectedGoalId, "Testing Goal", "Testing", 1000d, GoalStatus.Open, false);

            //Set up the mocks
            mockRepository.Setup(r => r.GetForGoal(It.Is<int>(val => val == expectedGoalId))).Returns
            (
                new List<Milestone>() { new Milestone(15, collisionTargetValue, "Testing", null) }
            );
            IMilestoneService service = new MilestoneService(mockRepository.Object);

            //Act
            Action failAction = () => service.CreateMilestoneForGoal(milestone, goal);

            //Assert
            failAction.Should().Throw<ArgumentException>();
        }