Esempio n. 1
0
        public async Task GetProjectCountCollectionAsync_ValidInput_ReturnsProjectCountCollection()
        {
            //arrange
            Guid    projectId       = Guid.NewGuid();
            Project expectedProject = new Project()
            {
                Name            = "Project 1",
                Description     = "Project 1 description.",
                DateTimeCreated = DateTime.UtcNow.AddDays(-1),
                ProjectId       = 1,
                PublicProjectId = projectId
            };
            ProjectCountCollection expectedProjectCountCollection = new ProjectCountCollection()
            {
                ProjectId  = projectId.ToString(),
                BugCount   = 4,
                EpicCount  = 3,
                StoryCount = 7
            };
            var projectRepositoryMock = new Mock <IProjectRepository>(MockBehavior.Strict);

            projectRepositoryMock.Setup(x => x.GetProjectAsync(projectId))
            .ReturnsAsync(expectedProject);
            projectRepositoryMock.Setup(x => x.GetProjectCountCollectionAsync(expectedProject.ProjectId))
            .ReturnsAsync(expectedProjectCountCollection);
            IProjectManager projectManager = new ProjectManager(projectRepositoryMock.Object);

            //act
            ProjectCountCollection projectCountCollection = await projectManager.GetProjectCountCollectionAsync(projectId);

            //assert
            Assert.Equal(projectCountCollection, expectedProjectCountCollection);
        }
Esempio n. 2
0
 /// <summary>
 /// Maps the given ProjectCountCollection to an OutputProjectCountCollection.
 /// </summary>
 /// <param name="projectCountCollection">The ProjectCountCollection to convert.</param>
 /// <returns>An OutputProjectCountCollection.</returns>
 public OutputProjectCountCollection MapOutputProjectCountCollection(ProjectCountCollection projectCountCollection)
 {
     return(new OutputProjectCountCollection()
     {
         ProjectId = projectCountCollection.ProjectId,
         EpicCount = projectCountCollection.EpicCount,
         StoryCount = projectCountCollection.StoryCount,
         BugCount = projectCountCollection.BugCount
     });
 }
        /// <summary>
        /// Gets the counts of Epics, Stories, and Bugs for the specified Project.
        /// </summary>
        /// <param name="publicProjectId">The public ID of the Project.</param>
        /// <returns>An awaitable Task of type ProjectCountCollection.</returns>
        public async Task <ProjectCountCollection> GetProjectCountCollectionAsync(Guid publicProjectId)
        {
            //check Project exists
            Project project = await projectRepository.GetProjectAsync(publicProjectId);

            if (project == null)
            {
                throw new NotFoundException();
            }
            //get counts
            ProjectCountCollection projectCountCollection = await projectRepository.GetProjectCountCollectionAsync(project.ProjectId);

            return(projectCountCollection);
        }
        /// <summary>
        /// Gets the counts of Epics, Stories, and Bugs for the specified Project.
        /// </summary>
        /// <param name="projectId">The ID of the Project.</param>
        /// <returns>An awaitable Task of type ProjectCountCollection.</returns>
        public async Task <ProjectCountCollection> GetProjectCountCollectionAsync(int projectId)
        {
            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                string storedProcedureName = "Projects_GetCounts";
                var    parameters          = new
                {
                    projectId
                };
                ProjectCountCollection projectCountCollection = await connection.QuerySingleAsync <ProjectCountCollection>(storedProcedureName,
                                                                                                                           parameters,
                                                                                                                           commandType : CommandType.StoredProcedure);

                return(projectCountCollection);
            }
        }
        public async Task <ActionResult <OutputProjectCountCollection> > GetCounts(Guid projectId)
        {
            try
            {
                logger.LogInformation($"Beginning request: /api/projects/{projectId}/counts GET");
                ProjectCountCollection projectCountCollection = await projectManager.GetProjectCountCollectionAsync(projectId);

                OutputProjectCountCollection output = projectMapper.MapOutputProjectCountCollection(projectCountCollection);
                logger.LogInformation($"Request complete: /api/projects/{projectId}/counts GET");
                return(Ok(output));
            }
            catch (Exception ex)
            {
                return(exceptionManager.Handle(ex));
            }
        }