This repository has been archived by the owner on Sep 3, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #422 from kysect/test/subject-course-users
test: subject course users
- Loading branch information
Showing
9 changed files
with
102 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
....Shreks.Application/DatabaseContextExtensions/GithubSubjectCourseAssociationExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using Kysect.Shreks.Core.Study; | ||
using Kysect.Shreks.Core.UserAssociations; | ||
using Microsoft.EntityFrameworkCore; | ||
|
||
namespace Kysect.Shreks.Application.DatabaseContextExtensions; | ||
|
||
public static class GithubSubjectCourseAssociationExtensions | ||
{ | ||
public static async Task<IReadOnlyCollection<GithubUserAssociation>> GetAllGithubUsers(this DbSet<SubjectCourse> subjectCourses, Guid subjectCourseId) | ||
{ | ||
return await subjectCourses | ||
.Where(sc => sc.Id == subjectCourseId) | ||
.SelectMany(sc => sc.Groups) | ||
.Select(g => g.StudentGroup) | ||
.SelectMany(g => g.Students) | ||
.Select(u => u.User) | ||
.SelectMany(u => u.Associations) | ||
.OfType<GithubUserAssociation>() | ||
.ToListAsync(); | ||
} | ||
} |
24 changes: 0 additions & 24 deletions
24
Source/Domain/Kysect.Shreks.Core/Specifications/Github/GetSubjectCourseGithubUsers.cs
This file was deleted.
Oops, something went wrong.
11 changes: 11 additions & 0 deletions
11
Source/Domain/Kysect.Shreks.Core/Users/StudentExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
using Kysect.Shreks.Core.UserAssociations; | ||
|
||
namespace Kysect.Shreks.Core.Users; | ||
|
||
public static class StudentExtensions | ||
{ | ||
public static GithubUserAssociation AddGithubAssociation(this Student student, string githubUsername) | ||
{ | ||
return new GithubUserAssociation(student.User, githubUsername); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
Source/Tests/Kysect.Shreks.Tests/DataAccess/GithubSubjectCourseAssociationTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
using FluentAssertions; | ||
using Kysect.Shreks.Application.DatabaseContextExtensions; | ||
using Kysect.Shreks.Core.Study; | ||
using Kysect.Shreks.Core.SubjectCourseAssociations; | ||
using Kysect.Shreks.Core.Users; | ||
using Kysect.Shreks.Seeding.EntityGenerators; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Xunit; | ||
|
||
namespace Kysect.Shreks.Tests.DataAccess; | ||
|
||
public class GithubSubjectCourseAssociationTest : DataAccessTestBase | ||
{ | ||
private readonly IEntityGenerator<GithubSubjectCourseAssociation> _subjectCourseAssociationGenerator; | ||
private readonly IEntityGenerator<StudentGroup> _studentGroupGenerator; | ||
private readonly IEntityGenerator<User> _userGenerator; | ||
|
||
public GithubSubjectCourseAssociationTest() | ||
{ | ||
_subjectCourseAssociationGenerator = Provider.GetRequiredService<IEntityGenerator<GithubSubjectCourseAssociation>>(); | ||
_userGenerator = Provider.GetRequiredService<IEntityGenerator<User>>(); | ||
_studentGroupGenerator = Provider.GetRequiredService<IEntityGenerator<StudentGroup>>(); | ||
} | ||
|
||
[Fact] | ||
public async Task GetSubjectCourseGithubUser_StudentAssociationExists_AssociationShouldReturn() | ||
{ | ||
// Arrange | ||
string userAssociation = Guid.NewGuid().ToString(); | ||
|
||
User user = _userGenerator.Generate(); | ||
StudentGroup group = _studentGroupGenerator.Generate(); | ||
GithubSubjectCourseAssociation subjectCourseAssociation = _subjectCourseAssociationGenerator.Generate(); | ||
|
||
var student = new Student(user, group); | ||
student.AddGithubAssociation(userAssociation); | ||
subjectCourseAssociation.SubjectCourse.AddGroup(group); | ||
group.AddStudent(student); | ||
|
||
// Act | ||
await Context.Users.AddAsync(user); | ||
await Context.Students.AddAsync(student); | ||
await Context.StudentGroups.AddAsync(group); | ||
await Context.SubjectCourseAssociations.AddAsync(subjectCourseAssociation); | ||
await Context.SaveChangesAsync(); | ||
|
||
// Assert | ||
IEnumerable<string> organizationUsers = Context | ||
.SubjectCourses | ||
.GetAllGithubUsers(subjectCourseAssociation.SubjectCourse.Id) | ||
.Result | ||
.Select(a => a.GithubUsername); | ||
|
||
organizationUsers.Should().Contain(userAssociation); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters