Ejemplo n.º 1
0
        public void ShouldUpdateMilestoneWithNewInformation()
        {
            int expectedMilestoneId = 10;
            Milestone milestone = new Milestone(100d, "Testing", DateTime.Now);
            Milestone existingMilestone = new Milestone(100d, "Testing", null);

            //Setup the mocks
            mockRepository.Setup(r => r.Get(It.Is<int>(val => val == expectedMilestoneId))).Returns(existingMilestone);
            mockRepository.Setup(r => r.Update(It.Is<int>(val => val == expectedMilestoneId), It.IsAny<Milestone>())).Returns<int, Milestone>
            (
                (id, unsavedMilestone) =>
                {
                    unsavedMilestone.Id = id;
                    return unsavedMilestone;
                }
            );
            IMilestoneService service = new MilestoneService(mockRepository.Object);

            //Act
            Milestone updatedMilestone = service.UpdateMilestone(expectedMilestoneId, milestone);

            //Assert
            updatedMilestone.Should().NotBeNull();
            updatedMilestone.Id.Should().Be(expectedMilestoneId);
            updatedMilestone.Should().BeEquivalentTo(milestone);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Gets the list of contract milestone
        /// </summary>
        /// <param name="param"></param>
        /// <param name="contractMaintenanceId">ContractMaintenance Id</param>
        /// <returns>List of Milestones</returns>
        public ActionResult GetContractMilestoneList(MODEL.jQueryDataTableParamModel param, int contractMaintenanceId)
        {
            try
            {
                MilestoneService   milestoneService = new MilestoneService();
                List <MilestoneVO> milestoneVOList  = milestoneService.GetMilestoneList(contractMaintenanceId);

                List <MODEL.Milestone> milestoneList = new List <Milestone>();

                foreach (var item in milestoneVOList)
                {
                    milestoneList.Add(new MODEL.Milestone(item));
                }

                //get the field on with sorting needs to happen and set the
                //ordering function/delegate accordingly.
                int sortColumnIndex  = Convert.ToInt32(Request["iSortCol_0"]);
                var orderingFunction = GetMilestoneOrderingFunction(sortColumnIndex);

                var result = GetFilteredObjects(param, milestoneList, orderingFunction);
                return(result);
            }
            catch (Exception e)
            {
                return(new HttpStatusCodeAndErrorResult(500, e.Message));
            }
        }
Ejemplo n.º 3
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);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Get Milestone billing lines
        /// </summary>
        /// <param name="id">Milestone Id</param>
        /// <returns>Milestone billing lines view</returns>
        public ActionResult GetMilestoneBillingLines(int id)
        {
            var milestone = new Milestone();

            try
            {
                //Get milestone details
                var         milestoneService = new MilestoneService();
                MilestoneVO milestoneVO      = milestoneService.GetMilestoneById(id);

                if (milestoneVO == null)
                {
                    ModelState.AddModelError("", String.Format(Constants.ITEM_NOT_FOUND, Constants.MILESTONE));
                }
                else
                {
                    milestone = new Milestone(milestoneVO)
                    {
                        MilestoneStatusList = GetMilestoneStatusList()
                    };
                    FillMilestoneBillingLines(milestone, milestone.MilestoneBillingLines);
                }
            }
            catch (Exception e)
            {
                ModelState.AddModelError("", e.Message);
            }
            return(PartialView("_BillingLines", milestone));
        }
Ejemplo n.º 5
0
        public ActionResult ApproveMaintenanceSave(Milestone model)
        {
            try
            {
                var milestoneService = new MilestoneService();

                if (ModelState.IsValid)
                {
                    //Get user id
                    int?userId = Session.GetUserId();
                    //ApproveMaintenanceVO approveMaintenanceVO = new ApproveMaintenanceVO(model, userId);
                    //var milestoneVO = new MilestoneVO(model, userId);

                    var milestoneVO = model.Transpose(userId);

                    milestoneService.UpdateMilestone(milestoneVO);
                    return(new HttpStatusCodeResult(200));
                }
                else
                {
                    throw new ApplicationException(String.Format(Constants.CANNOT_SAVE, Constants.MILESTONE));
                }
            }
            catch (ApplicationException e)
            {
                return(new HttpStatusCodeAndErrorResult(500, e.Message));
            }
        }
Ejemplo n.º 6
0
 public ProjectsController()
 {
     if (Projects == null) { Projects = new ProjectService(); }
     if (Tasks == null) { Tasks = new MilestoneService(); }
     if (Timeframes == null) { Timeframes = new TimeframesService(); }
     if (Divisions == null) { Divisions = new DivisionService(); }
     if (Tyypes == null) { Tyypes = new TypeService(); }
     base.Initialize(new System.Web.Routing.RequestContext());
 }
    public async Task Should_Include_Closed_Milestone_If_Specified()
    {
        // Given
        var dbContextOptions = new DbContextOptionsBuilder <GitBucketDbContext>()
                               .UseInMemoryDatabase(databaseName: "Should_Include_Closed_Milestone_If_Specified")
                               .Options;

        var dbContext = new GitBucketDbContext(dbContextOptions);
        var options   = new MilestoneOptions {
            ExecutedDate = new DateTime(2018, 7, 1), IncludeClosed = true
        };

        dbContext.Milestones.Add(new Milestone
        {
            MilestoneId    = 1,
            Title          = "v0.1.0",
            RepositoryName = "test1",
            DueDate        = new DateTime(2018, 7, 1),
            ClosedDate     = new DateTime(2018, 7, 1),
            Description    = "Implement xxx feature",
            UserName       = "******",
            Issues         = new[]
            {
                new Issue
                {
                    IssueId          = 1,
                    AssignedUserName = "******",
                    UserName         = "******",
                    RepositoryName   = "test1",
                    OpenedUserName   = "******",
                    Title            = "Implement xxx feature",
                }
            }
        });

        dbContext.SaveChanges();

        var service = new MilestoneService(dbContext, FakeConsole);

        // When
        var result = await service.ShowMilestones(options);

        // Then
        Assert.Equal(0, result);
        Assert.Equal(3, FakeConsole.Messages.Count);
        Assert.Empty(FakeConsole.WarnMessages);
        Assert.Empty(FakeConsole.ErrorMessages);

        Assert.Equal("There are 1 milestone.", FakeConsole.Messages[0]);
        Assert.Equal(string.Empty, FakeConsole.Messages[1]);

        Assert.Equal("* [root/test1], [v0.1.0], [2018/07/01], [Implement xxx feature], [user1]", FakeConsole.Messages[2]);
    }
Ejemplo n.º 8
0
        public void ShouldNotUpdateAMilestoneIfItDoesNotExist()
        {
            int expectedMilestoneId = 10;
            Milestone milestone = new Milestone(100d, "Testing", DateTime.Now);

            //Setup the mocks
            mockRepository.Setup(r => r.Get(It.Is<int>(val => val == expectedMilestoneId))).Returns<Milestone>(null);
            IMilestoneService service = new MilestoneService(mockRepository.Object);

            Action failAction = () => service.UpdateMilestone(expectedMilestoneId, milestone);

            //Assert
            failAction.Should().Throw<ArgumentException>();
        }
Ejemplo n.º 9
0
 /// <summary>
 /// Delete milestone(s)
 /// </summary>
 /// <param name="Ids">Ids of milestones to be deleted</param>
 public ActionResult MilestoneDelete(List <int> Ids)
 {
     try
     {
         //Get user id
         int?userId = Session.GetUserId();
         MilestoneService milestoneService = new MilestoneService();
         milestoneService.DeleteMilestone(Ids, userId);
         return(new HttpStatusCodeResult(200));
     }
     catch (Exception e)
     {
         return(new HttpStatusCodeAndErrorResult(500, e.Message));
     }
 }
Ejemplo n.º 10
0
        public void ShouldNotDeleteMilestoneFromSystemIfItHasBeenCompleted()
        {
            int expectedMilestoneId = 10;
            Milestone expectedMilestone = new Milestone(expectedMilestoneId, 100d, "Testing", DateTime.Now);

            //Setup the mocks
            mockRepository.Setup(r => r.Get(It.Is<int>(val => val == expectedMilestoneId))).Returns(expectedMilestone);
            IMilestoneService service = new MilestoneService(mockRepository.Object);

            //Act
            Action failAction = () => service.DeleteMilestone(expectedMilestoneId);

            //Assert
            failAction.Should().Throw<Exception>();
        }
Ejemplo n.º 11
0
        public void ShouldReturnAMilestoneGivenAKnownId()
        {
            int expectedMilestoneId = 2;
            Milestone expectedMilestone = new Milestone(2, 250d, "Testing", null);

            mockRepository.Setup(r => r.Get(It.Is<int>(val => val == expectedMilestoneId))).Returns(expectedMilestone);

            IMilestoneService service = new MilestoneService(mockRepository.Object);

            //Act
            Milestone milestone = service.GetMilestone(expectedMilestoneId);

            //Assert
            milestone.Should().NotBeNull();
            milestone.Id.Should().Be(expectedMilestoneId);
            milestone.Should().BeEquivalentTo(expectedMilestone);
        }
Ejemplo n.º 12
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>();
        }
Ejemplo n.º 13
0
        public void ShouldDeleteMilestoneFromSystemByKnownId()
        {
            int expectedMilestoneId = 10;
            Milestone expectedMilestone = new Milestone(expectedMilestoneId, 100d, "Testing", null);

            //Setup the mocks
            mockRepository.Setup(r => r.Get(It.Is<int>(val => val == expectedMilestoneId))).Returns(expectedMilestone);
            mockRepository.Setup(r => r.Delete(It.Is<int>(val => val == expectedMilestoneId))).Returns(expectedMilestone);
            IMilestoneService service = new MilestoneService(mockRepository.Object);

            //Act
            Milestone removedMilestone = service.DeleteMilestone(expectedMilestoneId);

            //Assert
            removedMilestone.Should().NotBeNull();
            removedMilestone.Id.Should().Be(expectedMilestoneId);
            removedMilestone.Should().BeEquivalentTo(expectedMilestone);
        }
Ejemplo n.º 14
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>();
        }
Ejemplo n.º 15
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>();
        }
Ejemplo n.º 16
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!");
            }
        }
Ejemplo n.º 17
0
        private async Task SetupAchievementProgressDetails(string currentUserId, QuizViewModel viewModel)
        {
            if (TempData != null)
            {
                // if the user just completed a quiz before viewing this action, check various achievement and milestone progress
                if (TempData["DidUserJustCompleteQuiz"] != null)
                {
                    // what is the user's current progress on the "points obtained" achievement set
                    // show the increase to the user based on the points they earned by completing the quiz
                    viewModel.PointsObtainedProgress = await MilestoneService.GetAchievementProgressForUserAsync(currentUserId, (int)MilestoneTypeValues.PointsObtained);

                    viewModel.PointsObtainedProgress.IncreaseAchievedCount = viewModel.PointsEarned;

                    // what is the user's current progress on the "quizzes completed" achievement set?
                    // show the increase tot he user based on a constant "1" (they completed 1 quiz)
                    viewModel.QuizzesCompletedProgress = await MilestoneService.GetAchievementProgressForUserAsync(currentUserId, (int)MilestoneTypeValues.QuizzesCompletedSuccessfully);

                    viewModel.QuizzesCompletedProgress.IncreaseAchievedCount = 1;

                    // what is the user's current progress on the "tags obtained" achievement set?
                    // show the increase to the user based on the tags awarded when the quiz was completed and scored
                    viewModel.TagsAwardedProgress = await MilestoneService.GetAchievementProgressForUserAsync(currentUserId, (int)MilestoneTypeValues.TagsAwarded);

                    viewModel.TagsAwardedProgress.IncreaseAchievedCount = TempData["TagsAwardedCount"] != null?Int32.Parse(TempData["TagsAwardedCount"].ToString()) : 0;

                    // did the user unlock any achievements?
                    if (TempData["MilestoneIdsUnlocked"] != null)
                    {
                        IReadOnlyCollection <int> milestoneIdsUnlocked = TempData["MilestoneIdsUnlocked"] as IReadOnlyCollection <int>;
                        if (milestoneIdsUnlocked != null && milestoneIdsUnlocked.Count > 0)
                        {
                            // get details of any achievements that the user unlocked as a result of completing the quiz
                            viewModel.UnlockedAchievements = await MilestoneService.GetMilestoneDetailsAsync(milestoneIdsUnlocked);
                        }
                    }
                }
            }
        }
Ejemplo n.º 18
0
        public void ShouldReturnOrderedMilestonesForAGivenGoalId()
        {
            //Arrange
            int expectedGoalId = 1;
            IEnumerable<Milestone> expectedMilestones = new List<Milestone>()
            {
                new Milestone(1, 100, "Testing 1", null),
                new Milestone(2, 300, "Testing 3", null),
                new Milestone(3, 500, "Testing 5", null)
            };
            IEnumerable<Milestone> expectedOrderedMilestones = expectedMilestones.OrderBy(m => m.Id);
            mockRepository.Setup(r => r.GetForGoal(It.Is<int>(val => val == expectedGoalId))).Returns(expectedMilestones);

            IMilestoneService service = new MilestoneService(mockRepository.Object);

            //Act
            IEnumerable<Milestone> milestones = service.GetMilestonesForGoal(expectedGoalId);

            //Assert
            milestones.Should().NotBeNull();
            milestones.Should().ContainInOrder(expectedOrderedMilestones);
            milestones.Count().Should().Be(expectedOrderedMilestones.Count());
        }
    public async Task Should_Return_If_No_Milestone()
    {
        // Given
        var dbContextOptions = new DbContextOptionsBuilder <GitBucketDbContext>()
                               .UseInMemoryDatabase(databaseName: "Should_Return_If_No_Milestone")
                               .Options;

        var dbContext = new GitBucketDbContext(dbContextOptions);
        var options   = new MilestoneOptions {
            ExecutedDate = new DateTime(2018, 7, 29)
        };
        var service = new MilestoneService(dbContext, FakeConsole);

        // When
        var result = await service.ShowMilestones(options);

        // Then
        Assert.Equal(0, result);
        Assert.Single(FakeConsole.Messages);
        Assert.Empty(FakeConsole.WarnMessages);
        Assert.Empty(FakeConsole.ErrorMessages);

        Assert.Equal("There are no milestone.", FakeConsole.Messages[0]);
    }
Ejemplo n.º 20
0
        public void ShouldReturnAKnownCollectionOfOrderedMilestones()
        {
            //Arrange
            IEnumerable<Milestone> expectedMilestones = new List<Milestone>()
            {
                new Milestone(1, 100, "Testing 1", null),
                new Milestone(7, 200, "Testing 2", null),
                new Milestone(2, 300, "Testing 3", null),
                new Milestone(4, 400, "Testing 4", null),
                new Milestone(3, 500, "Testing 5", null)
            };
            IEnumerable<Milestone> expectedOrderedMilestones = expectedMilestones.OrderBy(m => m.Id);
            mockRepository.Setup(r => r.GetAll()).Returns(expectedMilestones);

            IMilestoneService service = new MilestoneService(mockRepository.Object);

            //Act
            IEnumerable<Milestone> milestones = service.GetAllMilestones();

            //Assert
            milestones.Should().NotBeNull();
            milestones.Should().ContainInOrder(expectedOrderedMilestones);
            milestones.Count().Should().Be(expectedOrderedMilestones.Count());
        }
    public async Task Should_Show_Multiple_Milestones()
    {
        // Given
        var dbContextOptions = new DbContextOptionsBuilder <GitBucketDbContext>()
                               .UseInMemoryDatabase(databaseName: "Should_Show_Multiple_Milestones")
                               .Options;

        var dbContext = new GitBucketDbContext(dbContextOptions);
        var options   = new MilestoneOptions {
            ExecutedDate = new DateTime(2018, 7, 1), IncludeClosed = true
        };

        dbContext.Milestones.AddRange(new List <Core.Models.Milestone>
        {
            new Milestone
            {
                MilestoneId    = 1,
                Title          = "v0.1.0",
                RepositoryName = "test1",
                DueDate        = new DateTime(2018, 6, 30),
                ClosedDate     = null,
                Description    = "Error",
                UserName       = "******",
                Issues         = new[]
                {
                    new Issue
                    {
                        IssueId          = 1,
                        AssignedUserName = "******",
                        UserName         = "******",
                        RepositoryName   = "test1",
                        OpenedUserName   = "******",
                        Title            = "Implement xxx feature",
                    }
                }
            },
            new Milestone
            {
                MilestoneId    = 2,
                Title          = "v0.2.0",
                RepositoryName = "test1",
                DueDate        = new DateTime(2018, 7, 1),
                ClosedDate     = new DateTime(2018, 7, 1),
                Description    = "Closed",
                UserName       = "******",
                Issues         = new[]
                {
                    new Issue
                    {
                        IssueId          = 2,
                        AssignedUserName = "******",
                        UserName         = "******",
                        RepositoryName   = "test1",
                        OpenedUserName   = "******",
                        Title            = "Implement xxx feature",
                    }
                }
            },
            new Milestone
            {
                MilestoneId    = 3,
                Title          = "v0.3.0",
                RepositoryName = "test1",
                DueDate        = new DateTime(2018, 7, 7),
                ClosedDate     = null,
                Description    = "Warn",
                UserName       = "******",
                Issues         = new[]
                {
                    new Issue
                    {
                        IssueId          = 3,
                        AssignedUserName = "******",
                        UserName         = "******",
                        RepositoryName   = "test1",
                        OpenedUserName   = "******",
                        Title            = "Implement xxx feature",
                    }
                }
            },
            new Milestone
            {
                MilestoneId    = 4,
                Title          = "v0.4.0",
                RepositoryName = "test1",
                DueDate        = new DateTime(2018, 7, 8),
                ClosedDate     = null,
                Description    = "Info",
                UserName       = "******",
                Issues         = new[]
                {
                    new Issue
                    {
                        IssueId          = 4,
                        AssignedUserName = "******",
                        UserName         = "******",
                        RepositoryName   = "test1",
                        OpenedUserName   = "******",
                        Title            = "Implement xxx feature",
                    }
                }
            }
        });

        dbContext.SaveChanges();

        var service = new MilestoneService(dbContext, FakeConsole);

        // When
        var result = await service.ShowMilestones(options);

        // Then
        Assert.Equal(0, result);
        Assert.Equal(4, FakeConsole.Messages.Count);
        Assert.Single(FakeConsole.WarnMessages);
        Assert.Single(FakeConsole.ErrorMessages);

        Assert.Equal("There are 4 milestones.", FakeConsole.Messages[0]);
        Assert.Equal(string.Empty, FakeConsole.Messages[1]);

        Assert.Equal("* [root/test1], [v0.1.0], [2018/06/30], [Error], [user1]", FakeConsole.ErrorMessages[0]);
        Assert.Equal("* [root/test1], [v0.2.0], [2018/07/01], [Closed], [user1]", FakeConsole.Messages[2]);
        Assert.Equal("* [root/test1], [v0.3.0], [2018/07/07], [Warn], [user1]", FakeConsole.WarnMessages[0]);
        Assert.Equal("* [root/test1], [v0.4.0], [2018/07/08], [Info], [user1]", FakeConsole.Messages[3]);
    }
Ejemplo n.º 22
0
 public MilestoneController(MilestoneService milestoneService)
 {
     _milestoneService = milestoneService;
 }