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 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 IssueRepository_GetAllAsync_ReturnsAllValues() { await using var context = new TimeTrackingDbContext(_dbOptions); var issueRepository = new IssueRepository(context); var expected = IssuesDbSet.Get(); var actual = await issueRepository.GetAllAsync(); Assert.That(actual.OrderBy(e => e.Id), Is.EqualTo(expected.OrderBy(e => e.Id)) .Using(EqualityComparers.IssueComparer)); }
public async Task IssueRepository_GetById_ShouldReturnCorrectItem(string id) { var guidId = Guid.Parse(id); await using var context = new TimeTrackingDbContext(_dbOptions); var expected = IssuesDbSet.Get().First(x => x.Id == guidId); var issueRepository = new IssueRepository(context); var issue = await issueRepository.GetByIdAsync(guidId); Assert.That(issue, Is.EqualTo(expected).Using(EqualityComparers.IssueComparer)); }
public async Task IssueRepository_UpdateAsync_UpdateEntity() { await using var context = new TimeTrackingDbContext(_dbOptions); var issueRepository = new IssueRepository(context); var entityToUpdate = IssuesDbSet.Get().First(); entityToUpdate.Title = "New title"; var actual = await issueRepository.UpdateAsync(entityToUpdate); Assert.That(actual, Is.EqualTo(entityToUpdate).Using(EqualityComparers.IssueComparer)); }
public async Task IssueRepository_DeleteAsync_DeletesEntity() { var guidId = Guid.Parse("EC3CB528-45E3-4ABA-8E6E-DB40D0C0A400"); var entityToDelete = IssuesDbSet.Get().First(x => x.Id == guidId); var expectedCount = IssuesDbSet.Get().ToList().Count - 1; await using var context = new TimeTrackingDbContext(_dbOptions); var issueRepository = new IssueRepository(context); await issueRepository.DeleteAsync(entityToDelete); context.Issues.Should().HaveCount(expectedCount); }
public async Task GetIssueById_WhenFound_ReturnsIssue() { var expected = IssuesDbSet.Get().First(); var issueId = expected.Id; var httpResponse = await GetAsync(IssueControllerRoutes.BaseRoute + "/" + issueId); httpResponse.EnsureSuccessStatusCode(); var response = await httpResponse.BodyAs <ApiResponse <IssueDetailsDto> >(); response.VerifySuccessResponse(); response.Data.Should().BeEquivalentTo(GetIssueDetails(expected)); }
public async Task IssueRepository_AddAsync_AddsValueToDatabase() { var expectedCount = IssuesDbSet.Get().ToList().Count + 1; var entityToAdd = IssuesDbSet.IssueBuilder().Create(); await using var context = new TimeTrackingDbContext(_dbOptions); var issueRepository = new IssueRepository(context); await issueRepository.AddAsync(entityToAdd); context.Issues.Should().HaveCount(expectedCount); var entityFound = context.Issues.Find(entityToAdd.Id); entityFound.Should().BeEquivalentTo(entityFound); }
public async Task GetAllIssuesAsync_WhenRequestValid_ReturnsAllIssues(int page, int size, int expectedPage, int expectedSize) { var expected = IssuesDbSet.Get().ToList(); var pagedRequest = new PagedRequest() { Page = page, PageSize = size }; var httpResponse = await GetAsync(IssueControllerRoutes.BaseRoute + "?" + pagedRequest.ToQueryString()); httpResponse.EnsureSuccessStatusCode(); var response = await httpResponse.BodyAs <ApiPagedResponse <IssueDetailsDto> >(); response.EnsurePagedResult(expected.Count, expectedSize, expectedPage); }
public async Task AssignIssueToUser_WhenUserNotFound_ReturnsUserNotFound() { var claims = new Claim("roles", "TeamLead"); var token = GetJwtToken(new[] { claims }); AddAuth(token); var request = new AssignIssueToUserRequest() { IssueId = IssuesDbSet.Get().First().Id, UserId = Guid.NewGuid() }; var httpResponse = await PostAsync(IssueControllerRoutes.AssignToUser, request); httpResponse.EnsureSuccessStatusCode(); var response = await httpResponse.BodyAs <ApiResponse <IssueDto> >(); response.VerifyNotSuccessResponseWithErrorCodeAndMessage(ErrorCode.UserNotFound); }
public async Task GetAllIssuesAsync_WhenRequestValid_ReturnsValidIssues() { var pagedRequest = new PagedRequest() { Page = 1, PageSize = 2 }; var expected = IssuesDbSet.Get().Take(pagedRequest.PageSize).ToList(); var mappedExpectedResult = expected.Select(GetIssueDetails).ToList(); var httpResponse = await GetAsync(IssueControllerRoutes.BaseRoute + "?" + pagedRequest.ToQueryString()); httpResponse.EnsureSuccessStatusCode(); var response = await httpResponse.BodyAs <ApiPagedResponse <IssueDetailsDto> >(); response.Data.Should().BeEquivalentTo(mappedExpectedResult, opt => opt.Excluding(e => e.TotalRemainingTimeInSeconds) .Excluding(e => e.TotalSpentTimeInSeconds)); }
public async Task ChangeIssueStatus_WhenRequestIsValid_ReturnsSuccessStatus() { var request = new ChangeIssueStatusRequest() { IssueId = IssuesDbSet.Get().First().Id, Status = Status.Closed }; var httpResponse = await PostAsync(IssueControllerRoutes.ChangeIssueStatus, request); httpResponse.EnsureSuccessStatusCode(); var response = await httpResponse.BodyAs <ApiResponse <IssueDto> >(); var issue = await GetIssueFromDatabase(request.IssueId); issue.Status.Should().Be(request.Status); response.StatusCode.Should().Be(200); await ReSeedDatabase(); }
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 IssueRepository_GetAllPagedAsync_ReturnsAllResultsPaged() { var page = 1; var size = 1; await using var context = new TimeTrackingDbContext(_dbOptions); var issueRepository = new IssueRepository(context); var expected = IssuesDbSet.Get() .Skip(0) .Take(size) .OrderBy(e => e.Id) .ToList(); var issues = await issueRepository.GetAllPagedAsync(page, size); issues.EnsurePagedResult(IssuesDbSet.Get().ToList().Count, size, page); var actualItems = issues.Items.ToList(); Assert.That(actualItems.OrderBy(e => e.Id), Is.EqualTo(expected.OrderBy(e => e.Id)) .Using(EqualityComparers.IssueComparer)); }
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 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(); }