Example #1
0
        public void ShouldCreateMultipleMilestonesForAGivenGoalId()
        {
            int expectedGoalId = 1;
            List <Model.Milestone> milestones = new List <Model.Milestone>()
            {
                new Model.Milestone(100, "Testing", null),
                new Model.Milestone(200, "Testing", null),
                new Model.Milestone(300, "Testing", null)
            };
            List <Model.Milestone> createdMilestones = new List <Model.Milestone>()
            {
                new Model.Milestone(1, 100, "Testing", null),
                new Model.Milestone(2, 200, "Testing", null),
                new Model.Milestone(3, 300, "Testing", null)
            };
            string expectedSqlStatement = "INSERT INTO saver.Milestone (target, description, datemet, goalid) VALUES (@Target, @Description, @DateMet, @GoalId);";

            mockDataAccess.Setup
            (
                da => da.ExecuteWithGenericParameters
                (
                    It.Is <string>(val => val.Equals(expectedSqlStatement)),
                    It.IsAny <object>()
                )
            ).Returns(createdMilestones.Count);

            mockDataAccess.Setup
            (
                da => da.ExecuteQueryWithGenericParameterType <Model.Milestone>
                (
                    It.Is <string>(val => val.Equals(expectedSqlStatement)),
                    It.IsAny <object>()
                )
            ).Returns(createdMilestones);
            mockSqlStringService.Setup(ss => ss.GetSqlFromResource(It.IsAny <string>())).Returns(expectedSqlStatement);

            IMilestoneRepository repository = new MilestoneRepository(mockDataAccess.Object, mockSqlStringService.Object);

            //Act
            IEnumerable <Model.Milestone> returnedMilestones = repository.CreateMultipleForGoal(milestones, expectedGoalId);

            //Assert
            returnedMilestones.Should().NotBeNull();
            returnedMilestones.Count().Should().Be(createdMilestones.Count);
            returnedMilestones.Select(s => s.Id).Should().Contain(createdMilestones.Select(s => s.Id));
        }