public async Task UpdateWorkLog_WhenModelValid_UpdatesWorkLogInDatabase() { var request = new WorkLogUpdateRequest() { Description = "description", ActivityType = ActivityType.Coding, StartDate = DateTimeOffset.MaxValue.AddDays(-3333), TimeSpent = TimeSpan.FromDays(2).Seconds, WorkLogId = WorklogsDbSet.Get().First().Id }; var httpResponse = await PostAsync(WorkLogControllerRoutes.UpdateWorkLog, request); httpResponse.EnsureSuccessStatusCode(); var response = await httpResponse.BodyAs <ApiResponse <WorkLogDto> >(); response.VerifySuccessResponse(); var worklog = await GetWorkLogFromDatabase(request.WorkLogId); worklog.Description.Should().Be(request.Description); worklog.ActivityType.Should().Be(request.ActivityType); worklog.StartDate.Should().Be(request.StartDate); worklog.TimeSpent.Should().Be(request.TimeSpent); 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(); }
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 WorklogRepository_GetAllAsync_ReturnsAllValues() { await using var context = new TimeTrackingDbContext(_dbOptions); var workLogRepository = new WorklogRepository(context); var expected = WorklogsDbSet.Get(); var actual = await workLogRepository.GetAllAsync(); Assert.That(actual.OrderBy(x => x.Id), Is.EqualTo(expected.OrderBy(x => x.Id)) .Using(EqualityComparers.WorkLogComparer)); }
public async Task WorklogRepository_GetById_ShouldReturnCorrectItem(string id) { var guidId = Guid.Parse(id); await using var context = new TimeTrackingDbContext(_dbOptions); var expected = WorklogsDbSet.Get().First(x => x.Id == guidId); var workLogRepository = new WorklogRepository(context); var actual = await workLogRepository.GetByIdAsync(guidId); Assert.That(actual, Is.EqualTo(expected).Using(EqualityComparers.WorkLogComparer)); }
public async Task WorklogRepository_UpdateAsync_UpdateEntity() { await using var context = new TimeTrackingDbContext(_dbOptions); var workLogRepository = new WorklogRepository(context); var entityToUpdate = WorklogsDbSet.Get().First(); entityToUpdate.Description = "New description"; var actual = await workLogRepository.UpdateAsync(entityToUpdate); actual.Should().BeEquivalentTo(entityToUpdate); }
public async Task WorklogRepository_DeleteAsync_DeletesEntity() { var guidId = Guid.Parse("29C2F600-4F76-4753-A54D-A422DEF8EB9E"); var entityToDelete = WorklogsDbSet.Get().First(x => x.Id == guidId); var expectedCount = WorklogsDbSet.Get().ToList().Count - 1; await using var context = new TimeTrackingDbContext(_dbOptions); var workLogRepository = new WorklogRepository(context); await workLogRepository.DeleteAsync(entityToDelete); context.WorkLogs.Should().HaveCount(expectedCount); }
public async Task DeleteWorklog_WhenFound_DeletesWorkLogFromDatabase() { var expected = WorklogsDbSet.Get().First(); var workLogId = expected.Id; var httpResponse = await DeleteAsync(WorkLogControllerRoutes.BaseRoute + "/" + workLogId); var response = await httpResponse.BodyAs <ApiResponse>(); response.StatusCode.Should().Be(200); var workLog = await GetWorkLogFromDatabase(workLogId); workLog.Should().BeNull(); await ReSeedDatabase(); }
public async Task WorklogRepository_AddAsync_AddsValueToDatabase() { var expectedCount = WorklogsDbSet.Get().ToList().Count + 1; var entityToAdd = WorklogsDbSet.WorkLogBuilder().Create(); await using var context = new TimeTrackingDbContext(_dbOptions); var workLogRepository = new WorklogRepository(context); await workLogRepository.AddAsync(entityToAdd); context.WorkLogs.Should().HaveCount(expectedCount); var entityFound = await context.WorkLogs.FindAsync(entityToAdd.Id); entityFound.Should().BeEquivalentTo(entityFound); }
public async Task WorklogRepository_GetByIdWithUserAsync_ReturnsWorkLogForWithUser() { var workLogId = new Guid("29C2F600-4F76-4753-A54D-A422DEF8EB9E"); await using var context = new TimeTrackingDbContext(_dbOptions); var workLogRepository = new WorklogRepository(context); var expected = WorklogsDbSet.Get().Where(e => e.Id == workLogId) .Include(e => e.TimeTrackingUser) .FirstOrDefault(); var actual = await workLogRepository.GetByIdWithUserAsync(workLogId); Assert.That(actual, Is.EqualTo(expected).Using(EqualityComparers.WorkLogComparer)); Assert.That(actual.TimeTrackingUser, Is.EqualTo(expected.TimeTrackingUser).Using(EqualityComparers.TimeTrackingUserComparer)); }
public async Task GetAllWorkLogsPaged_WhenRequestValid_ReturnsAllWorkLogs(int page, int size, int expectedPage, int expectedSize) { var expected = WorklogsDbSet.Get().ToList(); var pagedRequest = new PagedRequest() { Page = page, PageSize = size }; var httpResponse = await GetAsync(WorkLogControllerRoutes.BaseRoute + "?" + pagedRequest.ToQueryString()); httpResponse.EnsureSuccessStatusCode(); var response = await httpResponse.BodyAs <ApiPagedResponse <WorkLogDetailsDto> >(); response.EnsurePagedResult(expected.Count, expectedSize, expectedPage); }
public async Task GetWorkLog_WhenFound_ReturnsWorkLog() { var expected = WorklogsDbSet.Get().First(); var workLogId = expected.Id; var httpResponse = await GetAsync(WorkLogControllerRoutes.BaseRoute + "/" + workLogId); httpResponse.EnsureSuccessStatusCode(); var response = await httpResponse.BodyAs <ApiResponse <WorkLogDetailsDto> >(); response.VerifySuccessResponse(); response.Data.Should().BeEquivalentTo(GetWorkLogDetails(expected), opt => opt.ExcludingMissingMembers() .Excluding(e => e.WorkLogId) .Excluding(e => e.UserId)); }
public async Task GetAllProjects_WhenRequestValid_ReturnsValidProjects() { var pagedRequest = new PagedRequest() { Page = 1, PageSize = 6 }; var expected = WorklogsDbSet.Get().Take(pagedRequest.PageSize).ToList(); var mappedExpectedResult = expected.Select(GetWorkLogDto).ToList(); var httpResponse = await GetAsync(WorkLogControllerRoutes.BaseRoute + "?" + pagedRequest.ToQueryString()); httpResponse.EnsureSuccessStatusCode(); var response = await httpResponse.BodyAs <ApiPagedResponse <WorkLogDto> >(); response.Data.Should().BeEquivalentTo(mappedExpectedResult); }
public async Task WorklogRepository_GetActivitiesWithDetailsByUserId_ReturnstActivitiesWithDetails() { var userId = new Guid("57C10EE7-4108-4FD9-BCE9-5477FE8BFF9B"); var projectId = new Guid("40B40CF5-46E1-4F03-8968-FA1F5DA459B3"); await using var context = new TimeTrackingDbContext(_dbOptions); var workLogRepository = new WorklogRepository(context); var expected = WorklogsDbSet.Get().Where(e => e.UserId == userId) .Include(x => x.Issue) .ThenInclude(e => e.Project) .Where(e => e.Issue.ProjectId.Equals(projectId)) .ToList(); var actual = await workLogRepository.GetActivitiesWithDetailsByUserId(userId, projectId); Assert.That(actual.OrderBy(e => e.Id), Is.EqualTo(expected.OrderBy(e => e.Id)) .Using(EqualityComparers.WorkLogComparer)); }
public async Task WorklogRepository_GetAllPagedAsync_ReturnsAllResultsPaged() { var page = 1; var size = 6; await using var context = new TimeTrackingDbContext(_dbOptions); var workLogRepository = new WorklogRepository(context); var expected = WorklogsDbSet.Get().Take(size).ToList(); var actual = await workLogRepository.GetAllPagedAsync(page, size); actual.EnsurePagedResult(WorklogsDbSet.Get().ToList().Count, size, page); var actualItems = actual.Items.ToList(); actualItems.Should().BeEquivalentTo(expected, options => options .Excluding(e => e.TimeTrackingUser) .Excluding(e => e.Issue)); }
public async Task UpdateWorkLog_WhenModelNotValid_UpdatesWorkLogInDatabase() { var request = new WorkLogUpdateRequest() { ActivityType = ActivityType.Coding, StartDate = DateTimeOffset.MaxValue.AddDays(-3333), TimeSpent = TimeSpan.FromDays(2).Seconds, WorkLogId = WorklogsDbSet.Get().First().Id }; var httpResponse = await PostAsync(WorkLogControllerRoutes.UpdateWorkLog, request); httpResponse.EnsureSuccessStatusCode(); var response = await httpResponse.BodyAs <ApiResponse <WorkLogDto> >(); response.CheckValidationException(2); request = new WorkLogUpdateRequest() { ActivityType = ActivityType.Coding, TimeSpent = TimeSpan.FromDays(2).Seconds, WorkLogId = WorklogsDbSet.Get().First().Id }; httpResponse = await PostAsync(WorkLogControllerRoutes.UpdateWorkLog, request); httpResponse.EnsureSuccessStatusCode(); response = await httpResponse.BodyAs <ApiResponse <WorkLogDto> >(); response.CheckValidationException(3); request = new WorkLogUpdateRequest() { ActivityType = ActivityType.Coding, WorkLogId = WorklogsDbSet.Get().First().Id }; httpResponse = await PostAsync(WorkLogControllerRoutes.UpdateWorkLog, request); httpResponse.EnsureSuccessStatusCode(); response = await httpResponse.BodyAs <ApiResponse <WorkLogDto> >(); response.CheckValidationException(4); }
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 CreateWorkLog_WhenModelValid_CreatesWorkLogInDbAndReturnSuccessResponse() { var workLogCount = WorklogsDbSet.Get().Count(); var request = new WorkLogDto() { Description = "description", StartDate = DateTimeOffset.Now, IssueId = IssuesDbSet.Get().First().Id, ActivityType = ActivityType.Research, TimeSpent = TimeSpan.FromDays(2).Seconds, }; var httpResponse = await PostAsync(WorkLogControllerRoutes.CreateWorkLog, request); httpResponse.EnsureSuccessStatusCode(); var response = await httpResponse.BodyAs <ApiResponse <WorkLogDto> >(); response.VerifySuccessResponse(); await CheckWorkLogAddedToDatabase(response.Data, workLogCount + 1); response.VerifySuccessResponse(); await ReSeedDatabase(); }
public async Task UpdateWorkLogStatus_WhenModelNotValid_ReturnsValidationErrors() { var claims = new Claim("roles", "TeamLead"); var token = GetJwtToken(new[] { claims }); AddAuth(token); //description not set var request = new UpdateWorkLogStatusRequest { IsApproved = false, WorkLogId = WorklogsDbSet.Get().First().Id }; var httpResponse = await PostAsync(WorkLogControllerRoutes.UpdateWorkLogStatus, request); var response = await httpResponse.BodyAs <ApiResponse <WorkLogDto> >(); response.CheckValidationException(2); //description and work log id not set request = new UpdateWorkLogStatusRequest { IsApproved = false }; httpResponse = await PostAsync(WorkLogControllerRoutes.UpdateWorkLogStatus, request); response = await httpResponse.BodyAs <ApiResponse <WorkLogDto> >(); response.CheckValidationException(3); //empty request request = new UpdateWorkLogStatusRequest(); httpResponse = await PostAsync(WorkLogControllerRoutes.UpdateWorkLogStatus, request); response = await httpResponse.BodyAs <ApiResponse <WorkLogDto> >(); response.CheckValidationException(3); }
public async Task UpdateWorkLogStatus_WhenModelValidFound_UpdatesWorkLog() { var claims = new Claim("roles", "TeamLead"); var token = GetJwtToken(new[] { claims }); AddAuth(token); var request = new UpdateWorkLogStatusRequest { Description = "desc", IsApproved = false, WorkLogId = WorklogsDbSet.Get().First().Id }; var httpResponse = await PostAsync(WorkLogControllerRoutes.UpdateWorkLogStatus, request); httpResponse.EnsureSuccessStatusCode(); var response = await httpResponse.BodyAs <ApiResponse <WorkLogDto> >(); response.VerifySuccessResponse(); var workLog = await GetWorkLogFromDatabase(request.WorkLogId); workLog.IsApproved.Should().Be(request.IsApproved); await ReSeedDatabase(); }