Skip to content

Commit

Permalink
Delete redundant properties in get by ID DTOs (#63)
Browse files Browse the repository at this point in the history
  • Loading branch information
romandykyi authored Dec 28, 2023
1 parent 208c3f7 commit 7fc591f
Show file tree
Hide file tree
Showing 8 changed files with 4 additions and 37 deletions.
3 changes: 1 addition & 2 deletions Core/Dtos/University/GroupViewDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@ namespace EUniversity.Core.Dtos.University;

public record GroupViewDto(int Id, string Name,
DateTimeOffset CreationDate, DateTimeOffset UpdateDate,
TeacherPreviewDto? Teacher, CoursePreviewDto Course,
IEnumerable<StudentPreviewDto> Students);
TeacherPreviewDto? Teacher, CoursePreviewDto Course);
3 changes: 1 addition & 2 deletions Core/Dtos/University/SemesterViewDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@

public record SemesterViewDto(int Id, string Name,
DateTimeOffset CreationDate, DateTimeOffset UpdateDate,
DateTimeOffset DateFrom, DateTimeOffset DateTo,
IEnumerable<StudentSemesterViewDto> StudentEnrollments);
DateTimeOffset DateFrom, DateTimeOffset DateTo);
1 change: 0 additions & 1 deletion Infrastructure/Services/University/GroupsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ public class GroupsService :
Entities
.Include(e => e.Course)
.Include(e => e.Teacher)
.Include(e => e.Students)
.AsNoTracking();

protected override IQueryable<Group> GetPageQuery =>
Expand Down
6 changes: 0 additions & 6 deletions Infrastructure/Services/University/SemestersService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,6 @@ public class SemestersService :
BaseCrudService<Semester, int, SemesterPreviewDto, SemesterViewDto, SemesterCreateDto, SemesterCreateDto>,
ISemestersService
{
protected override IQueryable<Semester> GetByIdQuery =>
Entities
.Include(e => e.StudentEnrollments)
.ThenInclude(e => e.Student)
.AsNoTracking();

public SemestersService(ApplicationDbContext dbContext) : base(dbContext)
{
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ protected override void AssertThatViewDtosAreEqual(GroupViewDto expected, GroupV
Assert.That(actual.Name, Is.EqualTo(expected.Name));
Assert.That(actual.Course, Is.EqualTo(expected.Course));
Assert.That(actual.Teacher, Is.EqualTo(expected.Teacher));
Assert.That(actual.Students, Is.EquivalentTo(expected.Students));
});
}

Expand All @@ -58,14 +57,10 @@ protected override GroupCreateDto GetInvalidUpdateDto()

protected override GroupViewDto GetTestDetailsDto()
{
List<StudentPreviewDto> students = new()
{
new(Guid.NewGuid().ToString(), "test-user", "Student1", "Student2", null)
};
return new(DefaultId, "Group",
DateTimeOffset.Now, DateTimeOffset.Now,
TeacherPreviewDto,
CoursePreviewDto, students);
CoursePreviewDto);
}

protected override GroupPreviewDto GetTestPreviewDto()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,6 @@ public override void SetUpService()
ServiceMock = WebApplicationFactory.SemestersServiceMock;
}

protected override void AssertThatViewDtosAreEqual(SemesterViewDto expected, SemesterViewDto actual)
{
Assert.Multiple(() =>
{
Assert.That(actual.Id, Is.EqualTo(expected.Id));
Assert.That(actual.Name, Is.EqualTo(expected.Name));
Assert.That(actual.DateFrom, Is.EqualTo(expected.DateFrom));
Assert.That(actual.DateTo, Is.EqualTo(expected.DateTo));
Assert.That(actual.StudentEnrollments, Is.EquivalentTo(expected.StudentEnrollments));
});
}

protected override bool AssertThatFilterWasApplied(IFilter<Semester> filter)
{
return filter is SemestersFilter semestersFilter &&
Expand All @@ -59,14 +47,9 @@ protected override SemesterCreateDto GetInvalidUpdateDto()

protected override SemesterViewDto GetTestDetailsDto()
{
StudentPreviewDto student = new("test-id", "test-user", "Test", "User", null);
List<StudentSemesterViewDto> enrollments = new()
{
new(student, DateTimeOffset.Now)
};
return new(DefaultId, "Test semester",
DateTimeOffset.Now, DateTimeOffset.Now,
DateTimeOffset.MinValue, DateTimeOffset.MaxValue, enrollments);
DateTimeOffset.MinValue, DateTimeOffset.MaxValue);
}

protected override SemesterPreviewDto GetTestPreviewDto()
Expand Down
1 change: 0 additions & 1 deletion IntegrationTests/Services/University/GroupsServiceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ public override async Task GetById_ElementExists_ReturnsValidElement()
Assert.That(result.Name, Is.EqualTo(expectedResult.Name));
Assert.That(result.Teacher, Is.EqualTo(expectedResult.Teacher));
Assert.That(result.Course, Is.EqualTo(expectedResult.Course));
Assert.That(result.Students, Is.EquivalentTo(expectedResult.Students));
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ public override async Task GetById_ElementExists_ReturnsValidElement()
Assert.That(result.Name, Is.EqualTo(expectedResult.Name));
Assert.That(result.DateFrom, Is.EqualTo(expectedResult.DateFrom));
Assert.That(result.DateTo, Is.EqualTo(expectedResult.DateTo));
Assert.That(result.StudentEnrollments, Is.EquivalentTo(expectedResult.StudentEnrollments));
});
}
}

0 comments on commit 7fc591f

Please sign in to comment.