Inheritance: IIdentifiableEntity, IVersionableEntity
        public void GetByProjectCodeAndIssueNumberTest()
        {
            Mock<IProjectRepository> fakeProjectRepo = new Mock<IProjectRepository>();
            Mock<IIssueRepository> fakeIssueRepo = new Mock<IIssueRepository>();
            Mock<IStateWorkflowRepository> fakeStateWorkflowRepo = new Mock<IStateWorkflowRepository>();
            Mock<ICommentRepository> fakeCommentRepo = new Mock<ICommentRepository>();

            var issueService = new IssueService(fakeIssueRepo.Object, fakeCommentRepo.Object);

            var firstProject = new Project() { Code = "COD"};
            var secodProject = new Project() { Code = "COP" };

            var firstIssueId = Guid.NewGuid();
            var secondIssueId = Guid.NewGuid();
            var thirdIssueId = Guid.NewGuid();
            var fourthIssueId = Guid.NewGuid();

            var firstIssue = new Issue() { Active = true, CodeNumber = 1, Description = "firstIssue", Id = firstIssueId, Name = "first", Type = Entities.IssueType.Bug, Project = firstProject };
            var secondIssue = new Issue() { Active = true, CodeNumber = 2, Description = "secondIssue", Id = firstIssueId, Name = "second", Type = Entities.IssueType.Task, Project = secodProject };
            var thirdIssue = new Issue() { Active = true, CodeNumber = 3, Description = "thirdIssue", Id = firstIssueId, Name = "third", Type = Entities.IssueType.Question, Project = secodProject };
            var fourthIssue = new Issue() { Active = true, CodeNumber = 4, Description = "fourthIssue", Id = firstIssueId, Name = "fourth", Type = Entities.IssueType.Bug, Project = secodProject };

            List<Issue> issues = new List<Issue>()
            {
                firstIssue,secondIssue,thirdIssue,fourthIssue
            };

            fakeIssueRepo.Setup(i => i.Fetch()).Returns(issues.AsQueryable());

            var actual = issueService.GetByProjectCodeAndIssueNumber("COD", 1);
            var expected = firstIssue;

            Assert.AreEqual(expected, actual);
        }
        public void GetProjectsForUserTest()
        {
            Mock<IProjectRepository> fakeProjectRepo = new Mock<IProjectRepository>();
            Mock<IIssueRepository> fakeIssueRepo = new Mock<IIssueRepository>();
            Mock<IApplicationUserRepository> fakeUserRepo = new Mock<IApplicationUserRepository>();

            var projectService = new ProjectService(fakeProjectRepo.Object, fakeIssueRepo.Object, fakeUserRepo.Object);

            var firstProjectId = Guid.NewGuid();
            var secondProjectId = Guid.NewGuid();
            var thirdProjectId = Guid.NewGuid();

            var firstUserId = Guid.NewGuid();
            var secondUserId = Guid.NewGuid();
            var thirdUserId = Guid.NewGuid();
            var fourthUserId = Guid.NewGuid();

            List<ApplicationUser> firstAndSecondUsers = new List<ApplicationUser>()
            {
                new ApplicationUser {Id = firstUserId, UserName = "******" },
                new ApplicationUser {Id = secondUserId, UserName = "******" }
            };

            List<ApplicationUser> thirdAndFourth = new List<ApplicationUser>()
            {
                new ApplicationUser {Id = thirdUserId, UserName = "******" },
                new ApplicationUser {Id = fourthUserId, UserName = "******" }
            };

            var firstProject = new Project() { Active = true, Code = "my-code", CreatedAt = DateTime.Now, Id = firstProjectId, Title = "first project title", Users = firstAndSecondUsers, OwnerId = thirdUserId };
            var secondProject = new Project() { Active = true, Code = "secondCode", CreatedAt = DateTime.Now, Id = secondProjectId, Title = "second project", Users = thirdAndFourth, OwnerId = firstUserId };
            var secondsecondProject = new Project() { Active = true, Code = "secondCode", CreatedAt = DateTime.Now.AddDays(1), Id = secondProjectId, Title = "second project with edited title", Users = thirdAndFourth, OwnerId = firstUserId };
            var thirdProject = new Project() { Active = false, Code = "thirdCode", CreatedAt = DateTime.Now, Id = thirdProjectId, Title = "third project", Users = thirdAndFourth, OwnerId = fourthUserId };

            List<Project> projects = new List<Project>()
            {
                firstProject,
                secondProject,
                secondsecondProject,
                thirdProject
            };

            fakeProjectRepo.Setup(i => i.FindBy(It.IsAny<Expression<Func<Project, bool>>>()))
                .Returns((Expression<Func<Project, bool>> expression) => projects.AsQueryable().Where(expression));

            var actual = projectService.GetProjectsForUser(firstUserId);

            Assert.AreEqual(actual.Contains(firstProject), true);
            Assert.AreEqual(actual.Contains(secondsecondProject), true);
        }
        public void ProjectCodeIsNotUniqueTest()
        {
            Mock<IProjectRepository> fakeProjectRepo = new Mock<IProjectRepository>();
            Mock<IIssueRepository> fakeIssueRepo = new Mock<IIssueRepository>();
            Mock<IApplicationUserRepository> fakeUserRepo = new Mock<IApplicationUserRepository>();

            var projectService = new ProjectService(fakeProjectRepo.Object, fakeIssueRepo.Object, fakeUserRepo.Object);

            var firstProjectId = Guid.NewGuid();
            var secondProjectId = Guid.NewGuid();
            var thirdProjectId = Guid.NewGuid();

            var firstProject = new Project() { Active = true, Code = "my-code", CreatedAt = DateTime.Now, Id = firstProjectId, Title = "first project title" };
            var secondProject = new Project() { Active = true, Code = "SECONDCODE", CreatedAt = DateTime.Now, Id = secondProjectId, Title = "second project" };
            var secondsecondProject = new Project() { Active = true, Code = "SECONDCODE", CreatedAt = DateTime.Now.AddDays(1), Id = secondProjectId, Title = "second project with edited title" };
            var thirdProject = new Project() { Active = false, Code = "thirdCode", CreatedAt = DateTime.Now, Id = thirdProjectId, Title = "third project" };

            List<Project> projects = new List<Project>()
            {
                firstProject,
                secondProject,
                secondsecondProject,
                thirdProject
            };

            fakeProjectRepo.Setup(i => i.GetAll()).Returns(projects);

            var actual = projectService.ProjectCodeIsNotUnique("secondCode");
            var expected = true;

            Assert.AreEqual(expected, actual);

            actual = projectService.ProjectCodeIsNotUnique("newcode");
            expected = false;

            Assert.AreEqual(expected, actual);
        }
        public void GetIssueCountTest()
        {
            Mock<IProjectRepository> fakeProjectRepo = new Mock<IProjectRepository>();
            Mock<IIssueRepository> fakeIssueRepo = new Mock<IIssueRepository>();
            Mock<IStateWorkflowRepository> fakeStateWorkflowRepo = new Mock<IStateWorkflowRepository>();
            Mock<ICommentRepository> fakeCommentRepo = new Mock<ICommentRepository>();

            var issueService = new IssueService(fakeIssueRepo.Object, fakeCommentRepo.Object);

            var firstProjectId = Guid.NewGuid();
            var secondProjectId = Guid.NewGuid();

            var firstProject = new Project() { Code = "COD", Id = firstProjectId };
            var secodProject = new Project() { Code = "COP", Id = secondProjectId };

            var firstIssueId = Guid.NewGuid();
            var secondIssueId = Guid.NewGuid();
            var thirdIssueId = Guid.NewGuid();
            var fourthIssueId = Guid.NewGuid();

            var firstIssue = new Issue() { Active = true, CodeNumber = 1, Description = "firstIssue", Id = firstIssueId, Name = "first", Type = Entities.IssueType.Bug, ProjectId = firstProjectId };
            var secondIssue = new Issue() { Active = true, CodeNumber = 2, Description = "secondIssue", Id = firstIssueId, Name = "second", Type = Entities.IssueType.Task, ProjectId = firstProjectId };
            var thirdIssue = new Issue() { Active = true, CodeNumber = 3, Description = "thirdIssue", Id = firstIssueId, Name = "third", Type = Entities.IssueType.Question, ProjectId = secondProjectId };
            var fourthIssue = new Issue() { Active = true, CodeNumber = 4, Description = "fourthIssue", Id = firstIssueId, Name = "fourth", Type = Entities.IssueType.Bug, ProjectId = secondProjectId };

            List<Issue> issues = new List<Issue>()
            {
                firstIssue,secondIssue,thirdIssue,fourthIssue
            };

            fakeIssueRepo.Setup(i => i.FindBy(It.IsAny<Expression<Func<Issue, bool>>>()))
                .Returns((Expression<Func<Issue, bool>> expression) => issues.AsQueryable().Where(expression));

            Project nullProject = null;

            var actual = issueService.GetIssueCount(Entities.IssueType.Bug, nullProject, true);
            var expected = 2;

            Assert.AreEqual(expected, actual);

            actual = issueService.GetIssueCount(Entities.IssueType.Bug, secodProject, true);
            expected = 1;

            Assert.AreEqual(expected, actual);
        }
        public void GetResolvedIssuesTest()
        {
            Mock<IProjectRepository> fakeProjectRepo = new Mock<IProjectRepository>();
            Mock<IIssueRepository> fakeIssueRepo = new Mock<IIssueRepository>();
            Mock<IStateWorkflowRepository> fakeStateWorkflowRepo = new Mock<IStateWorkflowRepository>();
            Mock<ICommentRepository> fakeCommentRepo = new Mock<ICommentRepository>();

            var issueService = new IssueService(fakeIssueRepo.Object, fakeCommentRepo.Object);

            var firstProjectId = Guid.NewGuid();
            var secondProjectId = Guid.NewGuid();

            var firstProject = new Project() { Code = "COD", Id = firstProjectId };
            var secodProject = new Project() { Code = "COP", Id = secondProjectId };

            var newState = new State() { IsInitial = true };
            var inProgress = new State() { IsInitial = false };

            var firstIssueId = Guid.NewGuid();
            var secondIssueId = Guid.NewGuid();
            var thirdIssueId = Guid.NewGuid();
            var fourthIssueId = Guid.NewGuid();

            var firstIssue = new Issue() { Active = true, CodeNumber = 1, Description = "firstIssue", Id = firstIssueId, Name = "first", Type = Entities.IssueType.Bug, ProjectId = firstProjectId, State = newState, ResolvedAt = new DateTime(2015, 1, 22) };
            var secondIssue = new Issue() { Active = true, CodeNumber = 2, Description = "secondIssue", Id = firstIssueId, Name = "second", Type = Entities.IssueType.Task, ProjectId = firstProjectId, State = inProgress, ResolvedAt = new DateTime(2015, 1, 28) };
            var thirdIssue = new Issue() { Active = true, CodeNumber = 3, Description = "thirdIssue", Id = firstIssueId, Name = "third", Type = Entities.IssueType.Question, ProjectId = secondProjectId, State = inProgress, ResolvedAt = new DateTime(2015, 3, 22) };
            var fourthIssue = new Issue() { Active = true, CodeNumber = 4, Description = "fourthIssue", Id = firstIssueId, Name = "fourth", Type = Entities.IssueType.Bug, ProjectId = secondProjectId, State = newState, ResolvedAt = new DateTime(2015, 1, 25) };

            List<Issue> issues = new List<Issue>()
            {
                firstIssue,secondIssue,thirdIssue,fourthIssue
            };

            fakeIssueRepo.Setup(i => i.FindBy(It.IsAny<Expression<Func<Issue, bool>>>()))
                .Returns((Expression<Func<Issue, bool>> expression) => issues.AsQueryable().Where(expression));

            var actual = issueService.GetResolvedIssues(firstProjectId ,new DateTime(2015, 1, 12), new DateTime(2015, 1, 25)).Count;
            var expected = 1;

            Assert.AreEqual(expected, actual);

            actual = issueService.GetResolvedIssues(firstProjectId, 2015, 1).Count;
            expected = 2;

            Assert.AreEqual(expected, actual);

            actual = issueService.GetResolvedIssues(secondProjectId, 2015, 1, 2).Count;
            expected = 1;

            Assert.AreEqual(expected, actual);
        }
Beispiel #6
0
        public int GetIssueCount(IssueType issueType, Project project, bool includeClosedIssue = true)
        {
            Guid? projectId;

            if (project == null)
            {
                projectId = null;
            }
            else
            {
                projectId = project.Id;
            }

            return GetIssueCount(issueType, projectId, includeClosedIssue);
        }
Beispiel #7
0
 public ICollection<Issue> GetIssuesInProgress(Project project)
 {
     var projectId = project?.Id;
     return GetIssuesInProgress(projectId);
 }