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 TeamRepository_GetAllAsync_ReturnsAllValues() { await using var context = new TimeTrackingDbContext(_dbOptions); var teamRepository = new TeamRepository(context); var expected = TeamsDbSet.Get(); var actual = await teamRepository.GetAllAsync(); Assert.That(actual.OrderBy(x => x.Id), Is.EqualTo(expected.OrderBy(x => x.Id)) .Using(EqualityComparers.TeamComparer)); }
public async Task TeamRepository_UpdateAsync_UpdateEntity() { await using var context = new TimeTrackingDbContext(_dbOptions); var teamRepository = new TeamRepository(context); var entityToUpdate = TeamsDbSet.Get().First(); entityToUpdate.Name = "New name"; var actual = await teamRepository.UpdateAsync(entityToUpdate); Assert.That(actual, Is.EqualTo(entityToUpdate).Using(EqualityComparers.TeamComparer)); }
public async Task TeamRepository_GetById_ShouldReturnCorrectItem(string id) { var guidId = Guid.Parse(id); await using var context = new TimeTrackingDbContext(_dbOptions); var expected = TeamsDbSet.Get().First(x => x.Id == guidId); var teamRepository = new TeamRepository(context); var actual = await teamRepository.GetByIdAsync(guidId); Assert.That(actual, Is.EqualTo(expected).Using(EqualityComparers.TeamComparer)); }
public async Task GetTeamById_WhenFound_ReturnsTeam() { var expected = TeamsDbSet.Get().First(); var teamId = expected.Id; var httpResponse = await GetAsync(TeamControllerRoutes.BaseRoute + "/" + teamId); httpResponse.EnsureSuccessStatusCode(); var response = await httpResponse.BodyAs <ApiResponse <TeamDetailsDto> >(); response.VerifySuccessResponse(); response.Data.Should().BeEquivalentTo(GetTeamDetails(expected)); }
public async Task TeamRepository_DeleteAsync_DeletesEntity() { var guidId = Guid.Parse("9245950B-0F82-4B9E-9AF7-DEC9ACF171FA"); var entityToDelete = TeamsDbSet.Get().First(x => x.Id == guidId); var expectedCount = TeamsDbSet.Get().ToList().Count - 1; await using var context = new TimeTrackingDbContext(_dbOptions); var teamRepository = new TeamRepository(context); await teamRepository.DeleteAsync(entityToDelete); context.Teams.Should().HaveCount(expectedCount); }
public async Task TeamRepository_AddAsync_AddsValueToDatabase() { var expectedCount = TeamsDbSet.Get().ToList().Count + 1; var entityToAdd = TeamsDbSet.TeamBuilder().Create(); await using var context = new TimeTrackingDbContext(_dbOptions); var teamRepository = new TeamRepository(context); await teamRepository.AddAsync(entityToAdd); context.Teams.Should().HaveCount(expectedCount); var entityFound = await context.Teams.FindAsync(entityToAdd.Id); Assert.That(entityFound, Is.EqualTo(entityToAdd).Using(EqualityComparers.TeamComparer)); }
public async Task TeamRepository_GetByIdWithDetails_ReturnsTeamWithProjectById() { var teamId = new Guid("40B40CF5-46E1-4F03-8968-FA1F5DA459B3"); await using var context = new TimeTrackingDbContext(_dbOptions); var teamRepository = new TeamRepository(context); var expected = TeamsDbSet.Get() .Include(e => e.Project) .First(e => e.Id.Equals(teamId)); var actual = await teamRepository.GetByIdWithDetails(teamId); Assert.That(actual, Is.EqualTo(expected).Using(EqualityComparers.TeamComparer)); Assert.That(actual.Project, Is.EqualTo(expected.Project).Using(EqualityComparers.ProjectComparer)); }
public async Task GetAllTeams_WhenRequestValid_ReturnsAllTeams(int page, int size, int expectedPage, int expectedSize) { var expected = TeamsDbSet.Get().ToList(); var pagedRequest = new PagedRequest() { Page = page, PageSize = size }; var httpResponse = await GetAsync(TeamControllerRoutes.BaseRoute + "?" + pagedRequest.ToQueryString()); httpResponse.EnsureSuccessStatusCode(); var response = await httpResponse.BodyAs <ApiPagedResponse <TeamDetailsDto> >(); response.EnsurePagedResult(expected.Count, expectedSize, expectedPage); }
public async Task AddUserToTeam_WhenUserNotFound_ReturnTeamNotFound() { var claims = new Claim("roles", "TeamLead"); var token = GetJwtToken(new[] { claims }); AddAuth(token); var request = new AssignUserToTeamRequest() { TeamId = TeamsDbSet.Get().First().Id, UserId = Guid.NewGuid() }; var httpResponse = await PostAsync(UserControllerRoutes.AddUserToTeam, request); httpResponse.EnsureSuccessStatusCode(); var response = await httpResponse.BodyAs <ApiResponse <TimeTrackingUserDetailsDto> >(); response.VerifyNotSuccessResponseWithErrorCodeAndMessage(ErrorCode.UserNotFound); }
public async Task GetAllTeams_WhenRequestValid_ReturnsValidTeams() { var pagedRequest = new PagedRequest() { Page = 1, PageSize = 2 }; var expected = TeamsDbSet.Get().Take(pagedRequest.PageSize).ToList(); var mappedExpectedResult = expected.Select(GetTeamDetails).ToList(); var httpResponse = await GetAsync(TeamControllerRoutes.BaseRoute + "?" + pagedRequest.ToQueryString()); httpResponse.EnsureSuccessStatusCode(); var response = await httpResponse.BodyAs <ApiPagedResponse <TeamDetailsDto> >(); response.Data.Should().BeEquivalentTo(mappedExpectedResult, opt => opt.ExcludingMissingMembers() .Excluding(e => e.ProjectAbbreviation) .Excluding(e => e.ProjectName)); }
public async Task TeamRepository_GetAllPagedAsync_ReturnsAllResultsPaged() { var page = 1; var size = 1; await using var context = new TimeTrackingDbContext(_dbOptions); var teamRepository = new TeamRepository(context); var expected = TeamsDbSet.Get() .Skip(0) .Take(size) .OrderBy(e => e.Id) .ToList(); var actual = await teamRepository.GetAllPagedAsync(page, size); actual.EnsurePagedResult(TeamsDbSet.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.TeamComparer)); }
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(); }
public async Task CreateTeamAsync_WhenModelValid_CreatesTeamInDbAndReturnsSuccessResponse() { var claims = new Claim("roles", "TeamLead"); var token = GetJwtToken(new[] { claims }); AddAuth(token); var projectCount = TeamsDbSet.Get().Count(); var request = new TeamDto() { ProjectId = ProjectsDbSet.Get().First().Id, MembersCount = 2, Name = "name" }; var httpResponse = await PostAsync(TeamControllerRoutes.CreateTeam, request); httpResponse.EnsureSuccessStatusCode(); var response = await httpResponse.BodyAs <ApiResponse <TeamDto> >(); await CheckTeamAddedToDatabase(response.Data, projectCount + 1); response.VerifySuccessResponse(); await ReSeedDatabase(); }