Example #1
0
        public async Task CreateIssue_WhenModelValid_CreatesIssueInDbAndReturnSuccessResponse()
        {
            var claims = new Claim("roles", "ProjectManager");
            var token  = GetJwtToken(new[] { claims });

            AddAuth(token);
            var issuesCount = IssuesDbSet.Get().Count();
            var request     = new IssueDto()
            {
                ProjectId        = ProjectsDbSet.Get().First().Id,
                MilestoneId      = null,
                Description      = "description",
                Status           = Status.Closed,
                AssignedToUserId = UsersDbSet.Get().First().Id,
                ReportedByUserId = UsersDbSet.Get().First().Id,
                Title            = "title"
            };

            var httpResponse = await PostAsync(IssueControllerRoutes.CreateIssue, request);

            httpResponse.EnsureSuccessStatusCode();
            var response = await httpResponse.BodyAs <ApiResponse <IssueDto> >();

            response.VerifySuccessResponse();
            await CheckIssueIsAddedToDatabase(response.Data, issuesCount + 1);

            response.VerifySuccessResponse();
            await ReSeedDatabase();
        }
        public async Task GetActivitiesForUser_WhenModelValid_ReturnsUserActivities()
        {
            var user    = UsersDbSet.Get().First();
            var request = new ActivitiesRequest()
            {
                ProjectId = ProjectsDbSet.Get().First().Id,
                UserId    = user.Id
            };
            var workLogItems = WorklogsDbSet.Get().Where(e => e.UserId.Equals(request.UserId))
                               .Include(e => e.Issue)
                               .ThenInclude(e => e.Project)
                               .Where(e => e.Issue.ProjectId.Equals(request.ProjectId));
            var httpResponse = await GetAsync(WorkLogControllerRoutes.GetUserWorkLogs + "?" + request.ToQueryString());

            httpResponse.EnsureSuccessStatusCode();
            var response = await httpResponse.BodyAs <ApiResponse <UserActivityDto> >();

            response.VerifySuccessResponse();
            response.Data.UserId.Should().Be(request.UserId);
            response.Data.UserName.Should().Be(user.FirstName);
            response.Data.UserSurname.Should().Be(user.LastName);
            response.Data.UserEmail.Should().Be(user.Email);
            response.Data.ProjectName.Should().Be(workLogItems?.Select(e => e.Issue.Project.Name).FirstOrDefault());
            response.Data.TotalWorkLogInSeconds.Should().Be((long?)workLogItems?.Sum(e => e.TimeSpent));
            response.Data.WorkLogItems.Should()
            .BeEquivalentTo(workLogItems?.Select(e => GetWorkLogDetails(e)).ToList());
            await ReSeedDatabase();
        }
Example #3
0
 public static void SeedData(TimeTrackingDbContext context)
 {
     context.Issues.AddRange(IssuesDbSet.Get().ToList());
     context.Projects.AddRange(ProjectsDbSet.Get().ToList());
     context.Milestones.AddRange(MilestonesDbSet.Get().ToList());
     context.Teams.AddRange(TeamsDbSet.Get().ToList());
     context.WorkLogs.AddRange(WorklogsDbSet.Get().ToList());
     context.Users.AddRange(UsersDbSet.Get().ToList());
     context.SaveChanges();
 }
        public async Task UserRepository_GetAllAsync_ReturnsAllValues()
        {
            await using var context = new TimeTrackingDbContext(_dbOptions);
            var userRepository = new UserRepository(context);
            var expected       = UsersDbSet.Get();

            var actual = await userRepository.GetAllAsync();

            Assert.That(actual.OrderBy(x => x.Id), Is.EqualTo(expected.OrderBy(x => x.Id))
                        .Using(EqualityComparers.TimeTrackingUserComparer));
        }
        public async Task UserRepository_UpdateAsync_UpdateEntity()
        {
            await using var context = new TimeTrackingDbContext(_dbOptions);
            var userRepository = new UserRepository(context);
            var entityToUpdate = UsersDbSet.Get().First();

            entityToUpdate.FirstName = "New first name";

            var actual = await userRepository.UpdateAsync(entityToUpdate);

            actual.Should().BeEquivalentTo(entityToUpdate);
        }
        public async Task UserRepository_GetById_ShouldReturnCorrectItem(string id)
        {
            var guidId = Guid.Parse(id);

            await using var context = new TimeTrackingDbContext(_dbOptions);
            var expected       = UsersDbSet.Get().First(x => x.Id == guidId);
            var userRepository = new UserRepository(context);

            var actual = await userRepository.GetByIdAsync(guidId);

            Assert.That(actual, Is.EqualTo(expected).Using(EqualityComparers.TimeTrackingUserComparer));
        }
        public async Task GetUserById_WhenFound_ReturnsTeam()
        {
            var expected = UsersDbSet.Get().First();
            var userId   = expected.Id;

            var httpResponse = await GetAsync(UserControllerRoutes.BaseRoute + "/" + userId);

            httpResponse.EnsureSuccessStatusCode();
            var response = await httpResponse.BodyAs <ApiResponse <TimeTrackingUserDetailsDto> >();

            response.VerifySuccessResponse();
            response.Data.Should().BeEquivalentTo(GetUserDetails(expected));
        }
        public async Task UserRepository_DeleteAsync_DeletesEntity()
        {
            var guidId         = Guid.Parse("57C10EE7-4108-4FD9-BCE9-5477FE8BFF9B");
            var entityToDelete = UsersDbSet.Get().First(x => x.Id == guidId);
            var expectedCount  = UsersDbSet.Get().ToList().Count - 1;

            await using var context = new TimeTrackingDbContext(_dbOptions);
            var userRepository = new UserRepository(context);

            await userRepository.DeleteAsync(entityToDelete);

            context.Users.Should().HaveCount(expectedCount);
        }
        public async Task GenerateReport_WhenValidParameters_GeneratesReportAsFile()
        {
            var request = new ReportGeneratorRequest()
            {
                ProjectId = ProjectsDbSet.Get().First().Id,
                UserId    = UsersDbSet.Get().First().Id
            };

            var httpResponse = await GetAsync(ReportControllerRoutes.BaseRoute + "?" + request.ToQueryString());

            httpResponse.EnsureSuccessStatusCode();

            httpResponse.Content.Should().NotBeNull();
        }
        public async Task UserRepository_AddAsync_AddsValueToDatabase()
        {
            var expectedCount = UsersDbSet.Get().ToList().Count + 1;
            var entityToAdd   = UsersDbSet.TimeTrackingUserBuilder().Create();

            await using var context = new TimeTrackingDbContext(_dbOptions);
            var userRepository = new UserRepository(context);

            await userRepository.AddAsync(entityToAdd);

            context.Users.Should().HaveCount(expectedCount);
            var entityFound = await context.Users.FindAsync(entityToAdd.Id);

            entityFound.Should().BeEquivalentTo(entityFound);
            Assert.That(entityToAdd, Is.EqualTo(entityFound).Using(EqualityComparers.TimeTrackingUserComparer));
        }
        public async Task GetAllUsers_WhenRequestValid_ReturnsValidPageResult(int page, int size, int expectedPage,
                                                                              int expectedSize)
        {
            var expected     = UsersDbSet.Get().ToList();
            var pagedRequest = new PagedRequest()
            {
                Page     = page,
                PageSize = size
            };
            var httpResponse = await GetAsync(UserControllerRoutes.AllUsers + "?" + pagedRequest.ToQueryString());

            httpResponse.EnsureSuccessStatusCode();
            var response = await httpResponse.BodyAs <ApiPagedResponse <TimeTrackingUserDetailsDto> >();

            response.EnsurePagedResult(expected.Count, expectedSize, expectedPage);
        }
Example #12
0
        public async Task CreateIssue_WhenNotValidModelPassed_ReturnsValidationError()
        {
            var claims = new Claim("roles", "ProjectManager");
            var token  = GetJwtToken(new[] { claims });

            AddAuth(token);
            var request = new IssueDto()
            {
                ProjectId        = ProjectsDbSet.Get().First().Id,
                MilestoneId      = null,
                AssignedToUserId = UsersDbSet.Get().First().Id,
                ReportedByUserId = UsersDbSet.Get().First().Id
            };
            var httpResponse = await PostAsync(IssueControllerRoutes.CreateIssue, request);

            var response = await httpResponse.BodyAs <ApiResponse <IssueDto> >();

            response.CheckValidationException(4);

            request = new IssueDto()
            {
                ProjectId   = ProjectsDbSet.Get().First().Id,
                MilestoneId = Guid.NewGuid(),
                Description = "description",
                Status      = Status.Closed,
                Title       = "title"
            };
            httpResponse = await PostAsync(IssueControllerRoutes.CreateIssue, request);

            response = await httpResponse.BodyAs <ApiResponse <IssueDto> >();

            response.CheckValidationException(1);

            request = new IssueDto()
            {
                ProjectId   = ProjectsDbSet.Get().First().Id,
                MilestoneId = Guid.NewGuid(),
                Status      = Status.Closed
            };
            httpResponse = await PostAsync(IssueControllerRoutes.CreateIssue, request);

            response = await httpResponse.BodyAs <ApiResponse <IssueDto> >();

            response.CheckValidationException(5);
        }
        public async Task GetAllUsers_WhenRequestValid_ReturnsValidUsers()
        {
            var pagedRequest = new PagedRequest()
            {
                Page     = 1,
                PageSize = 2
            };
            var expected             = UsersDbSet.Get().Take(pagedRequest.PageSize).ToList();
            var mappedExpectedResult = expected.Select(GetUserDetails).ToList();

            var httpResponse = await GetAsync(UserControllerRoutes.AllUsers + "?" + pagedRequest.ToQueryString());

            httpResponse.EnsureSuccessStatusCode();
            var response = await httpResponse.BodyAs <ApiPagedResponse <TimeTrackingUserDetailsDto> >();

            response.Data.Should().BeEquivalentTo(mappedExpectedResult,
                                                  opt => opt.ExcludingMissingMembers());
        }
        public async Task AddUserToTeam_WhenTeamNotFound_ReturnTeamNotFound()
        {
            var claims = new Claim("roles", "TeamLead");
            var token  = GetJwtToken(new[] { claims });

            AddAuth(token);
            var request = new AssignUserToTeamRequest()
            {
                TeamId = Guid.NewGuid(),
                UserId = UsersDbSet.Get().First().Id
            };

            var httpResponse = await PostAsync(UserControllerRoutes.AddUserToTeam, request);

            httpResponse.EnsureSuccessStatusCode();
            var response = await httpResponse.BodyAs <ApiResponse <TimeTrackingUserDetailsDto> >();

            response.VerifyNotSuccessResponseWithErrorCodeAndMessage(ErrorCode.TeamNotFound);
        }
Example #15
0
        public async Task AssignIssueToUser_WhenIssueNotFound_ReturnsIssueNotFound()
        {
            var claims = new Claim("roles", "TeamLead");
            var token  = GetJwtToken(new[] { claims });

            AddAuth(token);
            var request = new AssignIssueToUserRequest()
            {
                IssueId = Guid.NewGuid(),
                UserId  = UsersDbSet.Get().Last().Id
            };

            var httpResponse = await PostAsync(IssueControllerRoutes.AssignToUser, request);

            httpResponse.EnsureSuccessStatusCode();
            var response = await httpResponse.BodyAs <ApiResponse <IssueDto> >();

            response.VerifyNotSuccessResponseWithErrorCodeAndMessage(ErrorCode.IssueNotFound);
        }
        public async Task IssueRepository_GetIssueWithDetails_ShouldReturnCorrectItem(string id)
        {
            var guidId = Guid.Parse(id);

            await using var context = new TimeTrackingDbContext(_dbOptions);
            var issueRepository   = new IssueRepository(context);
            var expected          = IssuesDbSet.Get().First(x => x.Id == guidId);
            var expectedMilestone = MilestonesDbSet.Get().First(e => e.Id == expected.MilestoneId);
            var expectedWorkLogs  = WorklogsDbSet.Get().Where(e => e.IssueId == expected.Id).OrderBy(e => e.Id).ToList();
            var expectedTimeTrackingUserReporter = UsersDbSet.Get().First(e => e.Id == expected.ReportedByUserId);
            var expectedTimeTrackingUserAssigned = UsersDbSet.Get().First(e => e.Id == expected.AssignedToUserId);

            var issue = await issueRepository.GetIssueWithDetails(guidId);

            Assert.That(issue, Is.EqualTo(expected).Using(EqualityComparers.IssueComparer));
            Assert.That(issue.Milestone, Is.EqualTo(expectedMilestone).Using(EqualityComparers.MilestoneComparer));
            Assert.That(issue.WorkLogs.ToList(), Is.EqualTo(expectedWorkLogs).Using(EqualityComparers.WorkLogComparer));
            Assert.That(issue.TimeTrackingUserReporter, Is.EqualTo(expectedTimeTrackingUserReporter).Using(EqualityComparers.TimeTrackingUserComparer));
            Assert.That(issue.TimeTrackingUserAssigned, Is.EqualTo(expectedTimeTrackingUserAssigned).Using(EqualityComparers.TimeTrackingUserComparer));
        }
        public async Task UserRepository_GetAllPagedAsync_ReturnsAllResultsPaged()
        {
            var page = 1;
            var size = 3;

            await using var context = new TimeTrackingDbContext(_dbOptions);
            var userRepository = new UserRepository(context);
            var expected       = UsersDbSet.Get()
                                 .Skip(0)
                                 .Take(size)
                                 .OrderBy(e => e.Id)
                                 .ToList();

            var actual = await userRepository.GetAllPagedAsync();

            actual.EnsurePagedResult(UsersDbSet.Get().ToList().Count, size, page);
            var actualItems = actual.Items.ToList();

            Assert.That(actualItems.OrderBy(e => e.Id), Is.EqualTo(expected.OrderBy(e => e.Id))
                        .Using(EqualityComparers.TimeTrackingUserComparer));
        }
        public async Task AddUserToTeam_WhenRequestValid_ReturnValidationTimeTrackingUser()
        {
            var claims = new Claim("roles", "TeamLead");
            var token  = GetJwtToken(new[] { claims });

            AddAuth(token);
            var request = new AssignUserToTeamRequest()
            {
                TeamId = TeamsDbSet.Get().First().Id,
                UserId = UsersDbSet.Get().First().Id
            };

            var httpResponse = await PostAsync(UserControllerRoutes.AddUserToTeam, request);

            httpResponse.EnsureSuccessStatusCode();
            var response = await httpResponse.BodyAs <ApiResponse <TimeTrackingUserDetailsDto> >();

            response.VerifySuccessResponse();
            var user = await GetUserFromDatabase(request.UserId);

            user.TeamId.Should().Be(request.TeamId);
            await ReSeedDatabase();
        }
Example #19
0
        public async Task AssignIssueToUser_WhenRequestIsValid_ReturnsSuccessStatus()
        {
            var claims = new Claim("roles", "TeamLead");
            var token  = GetJwtToken(new[] { claims });

            AddAuth(token);
            var request = new AssignIssueToUserRequest()
            {
                IssueId = IssuesDbSet.Get().First().Id,
                UserId  = UsersDbSet.Get().Last().Id
            };

            var httpResponse = await PostAsync(IssueControllerRoutes.AssignToUser, request);

            httpResponse.EnsureSuccessStatusCode();
            var response = await httpResponse.BodyAs <ApiResponse <IssueDto> >();

            var issue = await GetIssueFromDatabase(request.IssueId);

            issue.AssignedToUserId.Should().Be(request.UserId);
            response.StatusCode.Should().Be(200);
            await ReSeedDatabase();
        }
Example #20
0
        public async Task CreateIssue_WhenMilestoneNotFound_ReturnsMilestoneNotFound()
        {
            var claims = new Claim("roles", "ProjectManager");
            var token  = GetJwtToken(new[] { claims });

            AddAuth(token);
            var request = new IssueDto()
            {
                ProjectId        = ProjectsDbSet.Get().First().Id,
                MilestoneId      = Guid.NewGuid(),
                Description      = "description",
                Status           = Status.Closed,
                AssignedToUserId = UsersDbSet.Get().First().Id,
                ReportedByUserId = UsersDbSet.Get().First().Id,
                Title            = "title"
            };

            var httpResponse = await PostAsync(IssueControllerRoutes.CreateIssue, request);

            httpResponse.EnsureSuccessStatusCode();
            var response = await httpResponse.BodyAs <ApiResponse <IssueDto> >();

            response.VerifyNotSuccessResponseWithErrorCodeAndMessage(ErrorCode.MileStoneNotFound);
        }