Beispiel #1
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();
 }
Beispiel #2
0
        public async Task MilestoneRepository_GetAllAsync_ReturnsAllValues()
        {
            await using var context = new TimeTrackingDbContext(_dbOptions);
            var milestoneRepository = new MilestoneRepository(context);
            var expected            = MilestonesDbSet.Get();

            var actual = await milestoneRepository.GetAllAsync();

            Assert.That(actual.OrderBy(x => x.Id), Is.EqualTo(expected.OrderBy(x => x.Id))
                        .Using(EqualityComparers.MilestoneComparer));
        }
Beispiel #3
0
        public async Task MilestoneRepository_UpdateAsync_UpdateEntity()
        {
            await using var context = new TimeTrackingDbContext(_dbOptions);
            var milestoneRepository = new MilestoneRepository(context);
            var entityToUpdate      = MilestonesDbSet.Get().First();

            entityToUpdate.Description = "New description";

            var actual = await milestoneRepository.UpdateAsync(entityToUpdate);

            Assert.That(actual, Is.EqualTo(entityToUpdate).Using(EqualityComparers.MilestoneComparer));
        }
Beispiel #4
0
        public async Task MilestoneRepository_GetById_ShouldReturnCorrectItem(string id)
        {
            var guidId = Guid.Parse(id);

            await using var context = new TimeTrackingDbContext(_dbOptions);
            var expected            = MilestonesDbSet.Get().First(x => x.Id == guidId);
            var milestoneRepository = new MilestoneRepository(context);

            var actual = await milestoneRepository.GetByIdAsync(guidId);

            Assert.That(actual, Is.EqualTo(expected).Using(EqualityComparers.MilestoneComparer));
        }
Beispiel #5
0
        public async Task MilestoneRepository_DeleteAsync_DeletesEntity()
        {
            var guidId         = Guid.Parse("9245950B-0F82-4B9E-9AF7-DEC9ACF171FA");
            var entityToDelete = MilestonesDbSet.Get().First(x => x.Id == guidId);
            var expectedCount  = MilestonesDbSet.Get().ToList().Count - 1;

            await using var context = new TimeTrackingDbContext(_dbOptions);
            var milestoneRepository = new MilestoneRepository(context);

            await milestoneRepository.DeleteAsync(entityToDelete);

            context.Milestones.Should().HaveCount(expectedCount);
        }
        public async Task GetMileStoneById_WhenFound_ReturnsMilestone()
        {
            var expected    = MilestonesDbSet.Get().First();
            var milestoneId = expected.Id;

            var httpResponse = await GetAsync(MilestoneControllerRoutes.BaseRoute + "/" + milestoneId);

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

            response.VerifySuccessResponse();
            response.Data.Should().BeEquivalentTo(GetMilestoneDetails(expected));
        }
Beispiel #7
0
        public async Task MilestoneRepository_AddAsync_AddsValueToDatabase()
        {
            var expectedCount = MilestonesDbSet.Get().ToList().Count + 1;
            var entityToAdd   = MilestonesDbSet.MilestoneBuilder().Create();

            await using var context = new TimeTrackingDbContext(_dbOptions);
            var milestoneRepository = new MilestoneRepository(context);

            await milestoneRepository.AddAsync(entityToAdd);

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

            Assert.That(entityFound, Is.EqualTo(entityToAdd).Using(EqualityComparers.MilestoneComparer));
        }
        public async Task GetAllMilestones_WhenRequestValid_ReturnsAllMilestones(int page, int size, int expectedPage,
                                                                                 int expectedSize)
        {
            var expected     = MilestonesDbSet.Get().ToList();
            var pagedRequest = new PagedRequest()
            {
                Page     = page,
                PageSize = size
            };
            var httpResponse = await GetAsync(MilestoneControllerRoutes.BaseRoute + "?" + pagedRequest.ToQueryString());

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

            response.EnsurePagedResult(expected.Count, expectedSize, expectedPage);
        }
        public async Task GetAllIssuesAsync_WhenRequestValid_ReturnsValidIssues()
        {
            var pagedRequest = new PagedRequest()
            {
                Page     = 1,
                PageSize = 2
            };
            var expected             = MilestonesDbSet.Get().Take(pagedRequest.PageSize).ToList();
            var mappedExpectedResult = expected.Select(GetMilestoneDetails).ToList();

            var httpResponse = await GetAsync(MilestoneControllerRoutes.BaseRoute + "?" + pagedRequest.ToQueryString());

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

            response.Data.Should().BeEquivalentTo(mappedExpectedResult);
        }
        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));
        }
Beispiel #11
0
        public async Task MilestoneRepository_GetAllPagedAsync_ReturnsAllResultsPaged()
        {
            var page = 1;
            var size = 1;

            await using var context = new TimeTrackingDbContext(_dbOptions);
            var milestoneRepository = new MilestoneRepository(context);
            var expected            = MilestonesDbSet.Get()
                                      .Skip(0)
                                      .Take(size)
                                      .OrderBy(e => e.Id)
                                      .ToList();

            var actual = await milestoneRepository.GetAllPagedAsync(page, size);

            actual.EnsurePagedResult(MilestonesDbSet.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.MilestoneComparer));
        }
        public async Task CreateMilestone_WhenModelValid_CreatesMilestoneInDbAndReturnsSuccessResponse()
        {
            var milestonesCount = MilestonesDbSet.Get().Count();
            var request         = new MilestoneDto()
            {
                State       = State.Closed,
                Description = "description",
                DueDate     = DateTimeOffset.UtcNow.AddDays(-3050),
                ProjectId   = ProjectsDbSet.Get().First().Id,
                Title       = "tittle"
            };

            var httpResponse = await PostAsync(MilestoneControllerRoutes.CreateMilestone, request);

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

            await CheckMilestoneIsAddedToDatabase(response.Data, milestonesCount + 1);

            response.VerifySuccessResponse();
            await ReSeedDatabase();
        }