From f5ef3676719e6e04cb62b9a7cd7f53880fc6a155 Mon Sep 17 00:00:00 2001 From: Volodya Petrov <89377379140@mail.ru> Date: Sat, 16 Apr 2022 01:36:42 +0300 Subject: [PATCH 01/20] init tests --- .../CourseService.IntegrationTests.csproj | 21 ++++++++ .../TestingWebAppFactory.cs | 49 +++++++++++++++++++ HwProj.sln | 7 +++ 3 files changed, 77 insertions(+) create mode 100644 HwProj.CoursesService/CourseService.IntegrationTests/CourseService.IntegrationTests.csproj create mode 100644 HwProj.CoursesService/CourseService.IntegrationTests/TestingWebAppFactory.cs diff --git a/HwProj.CoursesService/CourseService.IntegrationTests/CourseService.IntegrationTests.csproj b/HwProj.CoursesService/CourseService.IntegrationTests/CourseService.IntegrationTests.csproj new file mode 100644 index 000000000..d661c6f7c --- /dev/null +++ b/HwProj.CoursesService/CourseService.IntegrationTests/CourseService.IntegrationTests.csproj @@ -0,0 +1,21 @@ + + + + netcoreapp2.2 + + false + + + + + + + + + + + + + + + diff --git a/HwProj.CoursesService/CourseService.IntegrationTests/TestingWebAppFactory.cs b/HwProj.CoursesService/CourseService.IntegrationTests/TestingWebAppFactory.cs new file mode 100644 index 000000000..f594800b9 --- /dev/null +++ b/HwProj.CoursesService/CourseService.IntegrationTests/TestingWebAppFactory.cs @@ -0,0 +1,49 @@ +using System; +using System.Linq; +using HwProj.CoursesService.API; +using HwProj.CoursesService.API.Models; +using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.Mvc.Testing; +using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.DependencyInjection; + +namespace CourseService.IntegrationTests +{ + public class TestingWebAppFactory : WebApplicationFactory + { + protected override void ConfigureWebHost(IWebHostBuilder builder) + { + builder.ConfigureServices(services => + { + var descriptor = services.SingleOrDefault( + d => d.ServiceType == + typeof(DbContextOptions)); + + if (descriptor != null) + { + services.Remove(descriptor); + } + + var serviceProvider = new ServiceCollection() + .AddEntityFrameworkInMemoryDatabase() + .BuildServiceProvider(); + + services.AddDbContext(options => + { + options.UseInMemoryDatabase("InMemoryEmployeeTest"); + options.UseInternalServiceProvider(serviceProvider); + }); + + var sp = services.BuildServiceProvider(); + + using (var scope = sp.CreateScope()) + { + using (var appContext = scope.ServiceProvider.GetRequiredService()) + { + appContext.Database.EnsureCreated(); + } + } + }); + } + } +} \ No newline at end of file diff --git a/HwProj.sln b/HwProj.sln index 3961fc3c1..b58c85d5f 100644 --- a/HwProj.sln +++ b/HwProj.sln @@ -69,6 +69,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HwProj.SolutionsService.Cli EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HwProj.Exceptions", "HwProj.Common\HwProj.Exceptions\HwProj.Exceptions.csproj", "{51463655-7668-4C7D-9FDE-D4D7CDAA82B8}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CourseService.IntegrationTests", "HwProj.CoursesService\CourseService.IntegrationTests\CourseService.IntegrationTests.csproj", "{EC8823C4-A2E6-458D-8F49-08B3EB4543FA}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -159,6 +161,10 @@ Global {51463655-7668-4C7D-9FDE-D4D7CDAA82B8}.Debug|Any CPU.Build.0 = Debug|Any CPU {51463655-7668-4C7D-9FDE-D4D7CDAA82B8}.Release|Any CPU.ActiveCfg = Release|Any CPU {51463655-7668-4C7D-9FDE-D4D7CDAA82B8}.Release|Any CPU.Build.0 = Release|Any CPU + {EC8823C4-A2E6-458D-8F49-08B3EB4543FA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {EC8823C4-A2E6-458D-8F49-08B3EB4543FA}.Debug|Any CPU.Build.0 = Debug|Any CPU + {EC8823C4-A2E6-458D-8F49-08B3EB4543FA}.Release|Any CPU.ActiveCfg = Release|Any CPU + {EC8823C4-A2E6-458D-8F49-08B3EB4543FA}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -185,6 +191,7 @@ Global {0CBD72C5-1CCF-4C13-8046-732398816160} = {1EAEB779-E7C8-4EF9-B9A9-22CB8E3C246D} {C1ACAB32-4100-4C19-AE08-57FA9BA75DF2} = {A85A3030-2878-4923-B450-9683832CDAC1} {51463655-7668-4C7D-9FDE-D4D7CDAA82B8} = {77D857A8-45C6-4432-B4BF-A2F2C9ECA7FE} + {EC8823C4-A2E6-458D-8F49-08B3EB4543FA} = {CB37F9AC-88CB-425C-8200-1B40F372F38D} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {C03BF138-4A5B-4261-9495-6D3AC6CE9779} From 1d2f85db4c87c9f9b4b8630942d09421d47fbd40 Mon Sep 17 00:00:00 2001 From: Volodya Petrov <89377379140@mail.ru> Date: Thu, 21 Apr 2022 23:29:57 +0300 Subject: [PATCH 02/20] init tests --- .../CourseService.IntegrationTests.csproj | 2 + .../CourseServiceTests.cs | 39 +++++++++++++++++++ .../TestingWebAppFactory.cs | 7 +++- .../appsettings.json | 5 +++ .../Controllers/CoursesController.cs | 1 + 5 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 HwProj.CoursesService/CourseService.IntegrationTests/CourseServiceTests.cs create mode 100644 HwProj.CoursesService/CourseService.IntegrationTests/appsettings.json diff --git a/HwProj.CoursesService/CourseService.IntegrationTests/CourseService.IntegrationTests.csproj b/HwProj.CoursesService/CourseService.IntegrationTests/CourseService.IntegrationTests.csproj index d661c6f7c..ec52a99f6 100644 --- a/HwProj.CoursesService/CourseService.IntegrationTests/CourseService.IntegrationTests.csproj +++ b/HwProj.CoursesService/CourseService.IntegrationTests/CourseService.IntegrationTests.csproj @@ -10,12 +10,14 @@ + + diff --git a/HwProj.CoursesService/CourseService.IntegrationTests/CourseServiceTests.cs b/HwProj.CoursesService/CourseService.IntegrationTests/CourseServiceTests.cs new file mode 100644 index 000000000..a1c266726 --- /dev/null +++ b/HwProj.CoursesService/CourseService.IntegrationTests/CourseServiceTests.cs @@ -0,0 +1,39 @@ +using System; +using System.Net.Http; +using HwProj.CoursesService.API; +using HwProj.CoursesService.Client; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Options; +using Moq; +using Xunit; + +namespace CourseService.IntegrationTests +{ + public class CourseServiceTests : IClassFixture + { + private readonly TestingWebAppFactory _factory; + private readonly HttpClient _client; + + public CourseServiceTests(TestingWebAppFactory factory) + { + _factory = factory; + var client = _factory.CreateClient(); + } + + [Fact] + public async void TestGetAllCourses() + { + var mock = new Mock(); + var mockConfig = new Mock(); + var mockClientFactory = new Mock(); + mockClientFactory.Setup(f => f.CreateClient(Options.DefaultName)).Returns(_client); + mockConfig.Setup(c => c.GetSection("Services")["Courses"]).Returns("http://localhost:5002"); + //mock.Setup(m => m.HttpContext.User.FindFirst("_id").Value).Returns("lol"); + var courseClient = new CoursesServiceClient(mockClientFactory.Object, null, mockConfig.Object); + var result = await courseClient.GetAllCourses(); + + } + } +} \ No newline at end of file diff --git a/HwProj.CoursesService/CourseService.IntegrationTests/TestingWebAppFactory.cs b/HwProj.CoursesService/CourseService.IntegrationTests/TestingWebAppFactory.cs index f594800b9..4fcef6dba 100644 --- a/HwProj.CoursesService/CourseService.IntegrationTests/TestingWebAppFactory.cs +++ b/HwProj.CoursesService/CourseService.IntegrationTests/TestingWebAppFactory.cs @@ -2,6 +2,7 @@ using System.Linq; using HwProj.CoursesService.API; using HwProj.CoursesService.API.Models; +using HwProj.CoursesService.Client; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Mvc.Testing; using Microsoft.EntityFrameworkCore; @@ -30,7 +31,7 @@ protected override void ConfigureWebHost(IWebHostBuilder builder) services.AddDbContext(options => { - options.UseInMemoryDatabase("InMemoryEmployeeTest"); + options.UseInMemoryDatabase("CourseServiceTestDb"); options.UseInternalServiceProvider(serviceProvider); }); @@ -43,6 +44,10 @@ protected override void ConfigureWebHost(IWebHostBuilder builder) appContext.Database.EnsureCreated(); } } + + services.AddHttpClient(); + services.AddHttpContextAccessor(); + services.AddCoursesServiceClient(); }); } } diff --git a/HwProj.CoursesService/CourseService.IntegrationTests/appsettings.json b/HwProj.CoursesService/CourseService.IntegrationTests/appsettings.json new file mode 100644 index 000000000..2bed6354a --- /dev/null +++ b/HwProj.CoursesService/CourseService.IntegrationTests/appsettings.json @@ -0,0 +1,5 @@ +{ + "Services": { + "Courses": "http://localhost:5002" + } +} \ No newline at end of file diff --git a/HwProj.CoursesService/HwProj.CoursesService.API/Controllers/CoursesController.cs b/HwProj.CoursesService/HwProj.CoursesService.API/Controllers/CoursesController.cs index 6d3594b7d..224328c11 100644 --- a/HwProj.CoursesService/HwProj.CoursesService.API/Controllers/CoursesController.cs +++ b/HwProj.CoursesService/HwProj.CoursesService.API/Controllers/CoursesController.cs @@ -25,6 +25,7 @@ public CoursesController(ICoursesService coursesService, IMapper mapper) { _coursesService = coursesService; _mapper = mapper; + } [HttpGet] From af2a67ccc9c8d67b61aabc9dbc2df7cfc86e116b Mon Sep 17 00:00:00 2001 From: Volodya Petrov <89377379140@mail.ru> Date: Mon, 25 Apr 2022 00:59:09 +0300 Subject: [PATCH 03/20] added create course test --- .../CourseService.IntegrationTests.csproj | 1 + .../CourseServiceTests.cs | 74 +++++++++++++++---- 2 files changed, 59 insertions(+), 16 deletions(-) diff --git a/HwProj.CoursesService/CourseService.IntegrationTests/CourseService.IntegrationTests.csproj b/HwProj.CoursesService/CourseService.IntegrationTests/CourseService.IntegrationTests.csproj index ec52a99f6..93fb6245c 100644 --- a/HwProj.CoursesService/CourseService.IntegrationTests/CourseService.IntegrationTests.csproj +++ b/HwProj.CoursesService/CourseService.IntegrationTests/CourseService.IntegrationTests.csproj @@ -7,6 +7,7 @@ + diff --git a/HwProj.CoursesService/CourseService.IntegrationTests/CourseServiceTests.cs b/HwProj.CoursesService/CourseService.IntegrationTests/CourseServiceTests.cs index a1c266726..1caf390ee 100644 --- a/HwProj.CoursesService/CourseService.IntegrationTests/CourseServiceTests.cs +++ b/HwProj.CoursesService/CourseService.IntegrationTests/CourseServiceTests.cs @@ -1,7 +1,13 @@ using System; +using System.Net; using System.Net.Http; +using System.Security.Claims; +using AutoFixture; +using HwProj.AuthService.Client; using HwProj.CoursesService.API; using HwProj.CoursesService.Client; +using HwProj.Models.AuthService.ViewModels; +using HwProj.Models.CoursesService.ViewModels; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Configuration; @@ -11,29 +17,65 @@ namespace CourseService.IntegrationTests { - public class CourseServiceTests : IClassFixture + public class CourseServiceTests { - private readonly TestingWebAppFactory _factory; - private readonly HttpClient _client; + private RegisterViewModel GenerateRegisterViewModel() + { + var password = new Fixture().Create(); + var fixture = new Fixture().Build() + .With(vm => vm.Password, password) + .With(vm => vm.PasswordConfirm, password); + var viewModel = fixture.Create(); + viewModel.Email += "@mail.ru"; + return viewModel; + } + + private CreateCourseViewModel GenerateCourseViewModel() + { + var fixture = new Fixture().Build() + .With(cvm => cvm.IsOpen, true); + return fixture.Create(); + } - public CourseServiceTests(TestingWebAppFactory factory) + private CoursesServiceClient CreateCourseServiceClient(string userId) + { + var mockIConfiguration = new Mock(); + mockIConfiguration.Setup(x => x.GetSection("Services")["Courses"]).Returns("http://localhost:5002"); + var mockClientFactory = new Mock(); + mockClientFactory.Setup(x => x.CreateClient(Options.DefaultName)).Returns(new HttpClient()); + var mockHttpContextAccessor = new Mock(); + mockHttpContextAccessor.Setup(x => x.HttpContext.User.FindFirst("_id")).Returns(new Claim("", userId)); + return new CoursesServiceClient(mockClientFactory.Object, mockHttpContextAccessor.Object, mockIConfiguration.Object); + } + + private AuthServiceClient CreateAuthServiceClient() { - _factory = factory; - var client = _factory.CreateClient(); + var mockIConfiguration = new Mock(); + mockIConfiguration.Setup(x => x.GetSection("Services")["Auth"]).Returns("http://localhost:5001"); + var mockClientFactory = new Mock(); + mockClientFactory.Setup(x => x.CreateClient(Options.DefaultName)).Returns(new HttpClient()); + return new AuthServiceClient(mockClientFactory.Object, mockIConfiguration.Object); } + [Fact] - public async void TestGetAllCourses() + public async void TestCreateCourse() { - var mock = new Mock(); - var mockConfig = new Mock(); - var mockClientFactory = new Mock(); - mockClientFactory.Setup(f => f.CreateClient(Options.DefaultName)).Returns(_client); - mockConfig.Setup(c => c.GetSection("Services")["Courses"]).Returns("http://localhost:5002"); - //mock.Setup(m => m.HttpContext.User.FindFirst("_id").Value).Returns("lol"); - var courseClient = new CoursesServiceClient(mockClientFactory.Object, null, mockConfig.Object); - var result = await courseClient.GetAllCourses(); - + // Arrange + var authClient = CreateAuthServiceClient(); + var userData = GenerateRegisterViewModel(); + await authClient.Register(userData); + var userId = await authClient.FindByEmailAsync(userData.Email); + await authClient.InviteNewLecturer(new InviteLecturerViewModel() {Email = userData.Email}); + var courseClient = CreateCourseServiceClient(userId); + var newCourseViewModel = GenerateCourseViewModel(); + // Act + var courseId = await courseClient.CreateCourse(newCourseViewModel, userId); + // Assert + var courseFromServer = await courseClient.GetCourseById(courseId, userId); + Assert.Equal(newCourseViewModel.Name, courseFromServer.Name); + Assert.Equal(newCourseViewModel.GroupName, courseFromServer.GroupName); + Assert.Contains(userId, courseFromServer.MentorIds); } } } \ No newline at end of file From 3a59184c993092bec5a16e52e82d465e5c4848ce Mon Sep 17 00:00:00 2001 From: Volodya Petrov <89377379140@mail.ru> Date: Thu, 28 Apr 2022 21:45:42 +0300 Subject: [PATCH 04/20] Added delete course test, fix bug with delete course (userId was not passed to the request) --- .../CourseServiceTests.cs | 20 +++++++++++++++++++ .../CoursesServiceClient.cs | 3 ++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/HwProj.CoursesService/CourseService.IntegrationTests/CourseServiceTests.cs b/HwProj.CoursesService/CourseService.IntegrationTests/CourseServiceTests.cs index 1caf390ee..b8963391a 100644 --- a/HwProj.CoursesService/CourseService.IntegrationTests/CourseServiceTests.cs +++ b/HwProj.CoursesService/CourseService.IntegrationTests/CourseServiceTests.cs @@ -1,4 +1,5 @@ using System; +using System.Linq; using System.Net; using System.Net.Http; using System.Security.Claims; @@ -77,5 +78,24 @@ public async void TestCreateCourse() Assert.Equal(newCourseViewModel.GroupName, courseFromServer.GroupName); Assert.Contains(userId, courseFromServer.MentorIds); } + + [Fact] + public async void TestDeleteCourse() + { + // Arrange + var authClient = CreateAuthServiceClient(); + var userData = GenerateRegisterViewModel(); + await authClient.Register(userData); + var userId = await authClient.FindByEmailAsync(userData.Email); + await authClient.InviteNewLecturer(new InviteLecturerViewModel() {Email = userData.Email}); + var courseClient = CreateCourseServiceClient(userId); + var newCourseViewModel = GenerateCourseViewModel(); + // Act + var courseId = await courseClient.CreateCourse(newCourseViewModel, userId); + await courseClient.DeleteCourse(courseId); + // Assert + var coursesFromServer = await courseClient.GetAllCourses(); + Assert.True(coursesFromServer.FirstOrDefault(c => c.Id == courseId) == null); + } } } \ No newline at end of file diff --git a/HwProj.CoursesService/HwProj.CoursesService.Client/CoursesServiceClient.cs b/HwProj.CoursesService/HwProj.CoursesService.Client/CoursesServiceClient.cs index ce6765747..6619b54fa 100644 --- a/HwProj.CoursesService/HwProj.CoursesService.Client/CoursesServiceClient.cs +++ b/HwProj.CoursesService/HwProj.CoursesService.Client/CoursesServiceClient.cs @@ -56,7 +56,8 @@ public async Task DeleteCourse(long courseId) using var httpRequest = new HttpRequestMessage( HttpMethod.Delete, _coursesServiceUri + $"api/Courses/{courseId}"); - + + httpRequest.AddUserId(_httpContextAccessor); await _httpClient.SendAsync(httpRequest); } From 9385cd9549fba51404fa3afa91446133f2be2570 Mon Sep 17 00:00:00 2001 From: Volodya Petrov <89377379140@mail.ru> Date: Thu, 28 Apr 2022 23:03:47 +0300 Subject: [PATCH 05/20] added update course test --- .../CourseServiceTests.cs | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/HwProj.CoursesService/CourseService.IntegrationTests/CourseServiceTests.cs b/HwProj.CoursesService/CourseService.IntegrationTests/CourseServiceTests.cs index b8963391a..bc54a4583 100644 --- a/HwProj.CoursesService/CourseService.IntegrationTests/CourseServiceTests.cs +++ b/HwProj.CoursesService/CourseService.IntegrationTests/CourseServiceTests.cs @@ -37,6 +37,13 @@ private CreateCourseViewModel GenerateCourseViewModel() .With(cvm => cvm.IsOpen, true); return fixture.Create(); } + + private UpdateCourseViewModel GenerateUpdateCourseViewModel() + { + var fixture = new Fixture().Build() + .With(cvm => cvm.IsOpen, true); + return fixture.Create(); + } private CoursesServiceClient CreateCourseServiceClient(string userId) { @@ -97,5 +104,28 @@ public async void TestDeleteCourse() var coursesFromServer = await courseClient.GetAllCourses(); Assert.True(coursesFromServer.FirstOrDefault(c => c.Id == courseId) == null); } + + [Fact] + public async void TestUpdateCourse() + { + // Arrange + var authClient = CreateAuthServiceClient(); + var userData = GenerateRegisterViewModel(); + await authClient.Register(userData); + var userId = await authClient.FindByEmailAsync(userData.Email); + await authClient.InviteNewLecturer(new InviteLecturerViewModel() {Email = userData.Email}); + var courseClient = CreateCourseServiceClient(userId); + var newCourseViewModel = GenerateCourseViewModel(); + // Act + var courseId = await courseClient.CreateCourse(newCourseViewModel, userId); + var updateCourse = GenerateUpdateCourseViewModel(); + await courseClient.UpdateCourse(updateCourse, courseId); + // Assert + var courseFromServer = await courseClient.GetCourseById(courseId, userId); + Assert.Equal(updateCourse.Name, courseFromServer.Name); + Assert.Equal(updateCourse.GroupName, courseFromServer.GroupName); + Assert.Equal(updateCourse.IsComplete, courseFromServer.IsCompleted); + Assert.Equal(updateCourse.IsOpen, courseFromServer.IsOpen); + } } } \ No newline at end of file From 64e1eaac26fac640530bfd2e383754e440e9c81e Mon Sep 17 00:00:00 2001 From: Volodya Petrov <89377379140@mail.ru> Date: Thu, 28 Apr 2022 23:05:07 +0300 Subject: [PATCH 06/20] remove TestingWebAppFactory.cs --- .../TestingWebAppFactory.cs | 54 ------------------- 1 file changed, 54 deletions(-) delete mode 100644 HwProj.CoursesService/CourseService.IntegrationTests/TestingWebAppFactory.cs diff --git a/HwProj.CoursesService/CourseService.IntegrationTests/TestingWebAppFactory.cs b/HwProj.CoursesService/CourseService.IntegrationTests/TestingWebAppFactory.cs deleted file mode 100644 index 4fcef6dba..000000000 --- a/HwProj.CoursesService/CourseService.IntegrationTests/TestingWebAppFactory.cs +++ /dev/null @@ -1,54 +0,0 @@ -using System; -using System.Linq; -using HwProj.CoursesService.API; -using HwProj.CoursesService.API.Models; -using HwProj.CoursesService.Client; -using Microsoft.AspNetCore.Hosting; -using Microsoft.AspNetCore.Mvc.Testing; -using Microsoft.EntityFrameworkCore; -using Microsoft.Extensions.DependencyInjection; - -namespace CourseService.IntegrationTests -{ - public class TestingWebAppFactory : WebApplicationFactory - { - protected override void ConfigureWebHost(IWebHostBuilder builder) - { - builder.ConfigureServices(services => - { - var descriptor = services.SingleOrDefault( - d => d.ServiceType == - typeof(DbContextOptions)); - - if (descriptor != null) - { - services.Remove(descriptor); - } - - var serviceProvider = new ServiceCollection() - .AddEntityFrameworkInMemoryDatabase() - .BuildServiceProvider(); - - services.AddDbContext(options => - { - options.UseInMemoryDatabase("CourseServiceTestDb"); - options.UseInternalServiceProvider(serviceProvider); - }); - - var sp = services.BuildServiceProvider(); - - using (var scope = sp.CreateScope()) - { - using (var appContext = scope.ServiceProvider.GetRequiredService()) - { - appContext.Database.EnsureCreated(); - } - } - - services.AddHttpClient(); - services.AddHttpContextAccessor(); - services.AddCoursesServiceClient(); - }); - } - } -} \ No newline at end of file From 069f3d90dd9d1cd2bb51aabcc6facf70d19ddc27 Mon Sep 17 00:00:00 2001 From: Volodya Petrov <89377379140@mail.ru> Date: Fri, 29 Apr 2022 00:54:14 +0300 Subject: [PATCH 07/20] added sign in, accept, reject student in course --- .../CourseServiceTests.cs | 94 ++++++++++++++----- 1 file changed, 73 insertions(+), 21 deletions(-) diff --git a/HwProj.CoursesService/CourseService.IntegrationTests/CourseServiceTests.cs b/HwProj.CoursesService/CourseService.IntegrationTests/CourseServiceTests.cs index bc54a4583..0806b2b07 100644 --- a/HwProj.CoursesService/CourseService.IntegrationTests/CourseServiceTests.cs +++ b/HwProj.CoursesService/CourseService.IntegrationTests/CourseServiceTests.cs @@ -1,8 +1,10 @@ using System; +using System.ComponentModel.DataAnnotations; using System.Linq; using System.Net; using System.Net.Http; using System.Security.Claims; +using System.Threading.Tasks; using AutoFixture; using HwProj.AuthService.Client; using HwProj.CoursesService.API; @@ -44,7 +46,7 @@ private UpdateCourseViewModel GenerateUpdateCourseViewModel() .With(cvm => cvm.IsOpen, true); return fixture.Create(); } - + private CoursesServiceClient CreateCourseServiceClient(string userId) { var mockIConfiguration = new Mock(); @@ -53,7 +55,8 @@ private CoursesServiceClient CreateCourseServiceClient(string userId) mockClientFactory.Setup(x => x.CreateClient(Options.DefaultName)).Returns(new HttpClient()); var mockHttpContextAccessor = new Mock(); mockHttpContextAccessor.Setup(x => x.HttpContext.User.FindFirst("_id")).Returns(new Claim("", userId)); - return new CoursesServiceClient(mockClientFactory.Object, mockHttpContextAccessor.Object, mockIConfiguration.Object); + return new CoursesServiceClient(mockClientFactory.Object, mockHttpContextAccessor.Object, + mockIConfiguration.Object); } private AuthServiceClient CreateAuthServiceClient() @@ -64,19 +67,32 @@ private AuthServiceClient CreateAuthServiceClient() mockClientFactory.Setup(x => x.CreateClient(Options.DefaultName)).Returns(new HttpClient()); return new AuthServiceClient(mockClientFactory.Object, mockIConfiguration.Object); } - - - [Fact] - public async void TestCreateCourse() + + private async Task<(string, string)> CreateAndRegisterUser() { - // Arrange var authClient = CreateAuthServiceClient(); var userData = GenerateRegisterViewModel(); await authClient.Register(userData); var userId = await authClient.FindByEmailAsync(userData.Email); - await authClient.InviteNewLecturer(new InviteLecturerViewModel() {Email = userData.Email}); + return (userId, userData.Email); + } + + private async Task<(string, string)> CreateAndRegisterLecture() + { + var (userId, mail) = await CreateAndRegisterUser(); + var authClient = CreateAuthServiceClient(); + await authClient.InviteNewLecturer(new InviteLecturerViewModel() {Email = mail}); + return (userId, mail); + } + + + [Fact] + public async void TestCreateCourse() + { + // Arrange + var (userId, mail) = await CreateAndRegisterLecture(); var courseClient = CreateCourseServiceClient(userId); - var newCourseViewModel = GenerateCourseViewModel(); + var newCourseViewModel = GenerateCourseViewModel(); // Act var courseId = await courseClient.CreateCourse(newCourseViewModel, userId); // Assert @@ -90,13 +106,9 @@ public async void TestCreateCourse() public async void TestDeleteCourse() { // Arrange - var authClient = CreateAuthServiceClient(); - var userData = GenerateRegisterViewModel(); - await authClient.Register(userData); - var userId = await authClient.FindByEmailAsync(userData.Email); - await authClient.InviteNewLecturer(new InviteLecturerViewModel() {Email = userData.Email}); + var (userId, mail) = await CreateAndRegisterLecture(); var courseClient = CreateCourseServiceClient(userId); - var newCourseViewModel = GenerateCourseViewModel(); + var newCourseViewModel = GenerateCourseViewModel(); // Act var courseId = await courseClient.CreateCourse(newCourseViewModel, userId); await courseClient.DeleteCourse(courseId); @@ -109,13 +121,9 @@ public async void TestDeleteCourse() public async void TestUpdateCourse() { // Arrange - var authClient = CreateAuthServiceClient(); - var userData = GenerateRegisterViewModel(); - await authClient.Register(userData); - var userId = await authClient.FindByEmailAsync(userData.Email); - await authClient.InviteNewLecturer(new InviteLecturerViewModel() {Email = userData.Email}); + var (userId, mail) = await CreateAndRegisterLecture(); var courseClient = CreateCourseServiceClient(userId); - var newCourseViewModel = GenerateCourseViewModel(); + var newCourseViewModel = GenerateCourseViewModel(); // Act var courseId = await courseClient.CreateCourse(newCourseViewModel, userId); var updateCourse = GenerateUpdateCourseViewModel(); @@ -127,5 +135,49 @@ public async void TestUpdateCourse() Assert.Equal(updateCourse.IsComplete, courseFromServer.IsCompleted); Assert.Equal(updateCourse.IsOpen, courseFromServer.IsOpen); } + + [Fact] + public async void TestSignInAndAcceptStudent() + { + // Arrange + var (lectureId, lectureMail) = await CreateAndRegisterLecture(); + var (studentId, studentMail) = await CreateAndRegisterUser(); + var lectureCourseClient = CreateCourseServiceClient(lectureId); + var studentCourseClient = CreateCourseServiceClient(studentId); + var newCourseViewModel = GenerateCourseViewModel(); + // Act + var courseId = await lectureCourseClient.CreateCourse(newCourseViewModel, lectureId); + await studentCourseClient.SignInCourse(courseId, studentId); + var courseBeforeAcceptStudent = await lectureCourseClient.GetCourseById(courseId, lectureId); + await lectureCourseClient.AcceptStudent(courseId, studentId); + var courseAfterAcceptStudent = await lectureCourseClient.GetCourseById(courseId, lectureId); + // Assert + var mateBeforeAccept = courseBeforeAcceptStudent.CourseMates.FirstOrDefault(m => m.StudentId == studentId); + var mateAfterAccept = courseAfterAcceptStudent.CourseMates.FirstOrDefault(m => m.StudentId == studentId); + Assert.False(mateBeforeAccept.IsAccepted); + Assert.True(mateAfterAccept.IsAccepted); + } + + [Fact] + public async void TestSignInAndRejectStudent() + { + // Arrange + var (lectureId, lectureMail) = await CreateAndRegisterLecture(); + var (studentId, studentMail) = await CreateAndRegisterUser(); + var lectureCourseClient = CreateCourseServiceClient(lectureId); + var studentCourseClient = CreateCourseServiceClient(studentId); + var newCourseViewModel = GenerateCourseViewModel(); + // Act + var courseId = await lectureCourseClient.CreateCourse(newCourseViewModel, lectureId); + await studentCourseClient.SignInCourse(courseId, studentId); + var courseBeforeAcceptStudent = await lectureCourseClient.GetCourseById(courseId, lectureId); + await lectureCourseClient.RejectStudent(courseId, studentId); + var courseAfterAcceptStudent = await lectureCourseClient.GetCourseById(courseId, lectureId); + // Assert + var mateBeforeAccept = courseBeforeAcceptStudent.CourseMates.FirstOrDefault(m => m.StudentId == studentId); + var mateAfterAccept = courseAfterAcceptStudent.CourseMates.FirstOrDefault(m => m.StudentId == studentId); + Assert.False(mateBeforeAccept.IsAccepted); + Assert.Null(mateAfterAccept); + } } } \ No newline at end of file From 38ed8ada46346852fc402cc5db51cca5d6e09f72 Mon Sep 17 00:00:00 2001 From: Volodya Petrov <89377379140@mail.ru> Date: Fri, 29 Apr 2022 21:19:07 +0300 Subject: [PATCH 08/20] Change xUnit to nUnit --- .../CourseService.IntegrationTests.csproj | 13 +++++++------ .../appsettings.json | 0 HwProj.sln | 12 ++++++------ 3 files changed, 13 insertions(+), 12 deletions(-) rename HwProj.CoursesService/{CourseService.IntegrationTests => CourseService.IntegrationTestss}/appsettings.json (100%) diff --git a/HwProj.CoursesService/CourseService.IntegrationTests/CourseService.IntegrationTests.csproj b/HwProj.CoursesService/CourseService.IntegrationTests/CourseService.IntegrationTests.csproj index 93fb6245c..e77fb7360 100644 --- a/HwProj.CoursesService/CourseService.IntegrationTests/CourseService.IntegrationTests.csproj +++ b/HwProj.CoursesService/CourseService.IntegrationTests/CourseService.IntegrationTests.csproj @@ -8,16 +8,17 @@ - - - - - + + + - + + + + diff --git a/HwProj.CoursesService/CourseService.IntegrationTests/appsettings.json b/HwProj.CoursesService/CourseService.IntegrationTestss/appsettings.json similarity index 100% rename from HwProj.CoursesService/CourseService.IntegrationTests/appsettings.json rename to HwProj.CoursesService/CourseService.IntegrationTestss/appsettings.json diff --git a/HwProj.sln b/HwProj.sln index b58c85d5f..5b1dea225 100644 --- a/HwProj.sln +++ b/HwProj.sln @@ -69,7 +69,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HwProj.SolutionsService.Cli EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HwProj.Exceptions", "HwProj.Common\HwProj.Exceptions\HwProj.Exceptions.csproj", "{51463655-7668-4C7D-9FDE-D4D7CDAA82B8}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CourseService.IntegrationTests", "HwProj.CoursesService\CourseService.IntegrationTests\CourseService.IntegrationTests.csproj", "{EC8823C4-A2E6-458D-8F49-08B3EB4543FA}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CourseService.IntegrationTests", "HwProj.CoursesService\CourseService.IntegrationTests\CourseService.IntegrationTests.csproj", "{F09D809A-39FB-4746-9D1F-7B2D051643EE}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -161,10 +161,10 @@ Global {51463655-7668-4C7D-9FDE-D4D7CDAA82B8}.Debug|Any CPU.Build.0 = Debug|Any CPU {51463655-7668-4C7D-9FDE-D4D7CDAA82B8}.Release|Any CPU.ActiveCfg = Release|Any CPU {51463655-7668-4C7D-9FDE-D4D7CDAA82B8}.Release|Any CPU.Build.0 = Release|Any CPU - {EC8823C4-A2E6-458D-8F49-08B3EB4543FA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {EC8823C4-A2E6-458D-8F49-08B3EB4543FA}.Debug|Any CPU.Build.0 = Debug|Any CPU - {EC8823C4-A2E6-458D-8F49-08B3EB4543FA}.Release|Any CPU.ActiveCfg = Release|Any CPU - {EC8823C4-A2E6-458D-8F49-08B3EB4543FA}.Release|Any CPU.Build.0 = Release|Any CPU + {F09D809A-39FB-4746-9D1F-7B2D051643EE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F09D809A-39FB-4746-9D1F-7B2D051643EE}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F09D809A-39FB-4746-9D1F-7B2D051643EE}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F09D809A-39FB-4746-9D1F-7B2D051643EE}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -191,7 +191,7 @@ Global {0CBD72C5-1CCF-4C13-8046-732398816160} = {1EAEB779-E7C8-4EF9-B9A9-22CB8E3C246D} {C1ACAB32-4100-4C19-AE08-57FA9BA75DF2} = {A85A3030-2878-4923-B450-9683832CDAC1} {51463655-7668-4C7D-9FDE-D4D7CDAA82B8} = {77D857A8-45C6-4432-B4BF-A2F2C9ECA7FE} - {EC8823C4-A2E6-458D-8F49-08B3EB4543FA} = {CB37F9AC-88CB-425C-8200-1B40F372F38D} + {F09D809A-39FB-4746-9D1F-7B2D051643EE} = {CB37F9AC-88CB-425C-8200-1B40F372F38D} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {C03BF138-4A5B-4261-9495-6D3AC6CE9779} From f4bff156f164f69e40ae54171a5d0c24c6cbe0a1 Mon Sep 17 00:00:00 2001 From: Volodya Petrov <89377379140@mail.ru> Date: Fri, 29 Apr 2022 21:25:48 +0300 Subject: [PATCH 09/20] wip --- .../CourseServiceTests.cs | 55 +++++++++---------- .../appsettings.json | 5 -- 2 files changed, 25 insertions(+), 35 deletions(-) delete mode 100644 HwProj.CoursesService/CourseService.IntegrationTestss/appsettings.json diff --git a/HwProj.CoursesService/CourseService.IntegrationTests/CourseServiceTests.cs b/HwProj.CoursesService/CourseService.IntegrationTests/CourseServiceTests.cs index 0806b2b07..44cb51f35 100644 --- a/HwProj.CoursesService/CourseService.IntegrationTests/CourseServiceTests.cs +++ b/HwProj.CoursesService/CourseService.IntegrationTests/CourseServiceTests.cs @@ -1,26 +1,21 @@ -using System; -using System.ComponentModel.DataAnnotations; using System.Linq; -using System.Net; using System.Net.Http; using System.Security.Claims; using System.Threading.Tasks; using AutoFixture; using HwProj.AuthService.Client; -using HwProj.CoursesService.API; using HwProj.CoursesService.Client; using HwProj.Models.AuthService.ViewModels; using HwProj.Models.CoursesService.ViewModels; using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Options; using Moq; -using Xunit; +using NUnit.Framework; -namespace CourseService.IntegrationTests +namespace Tests { - public class CourseServiceTests + public class Tests { private RegisterViewModel GenerateRegisterViewModel() { @@ -86,8 +81,8 @@ private AuthServiceClient CreateAuthServiceClient() } - [Fact] - public async void TestCreateCourse() + [Test] + public async Task TestCreateCourse() { // Arrange var (userId, mail) = await CreateAndRegisterLecture(); @@ -97,13 +92,13 @@ public async void TestCreateCourse() var courseId = await courseClient.CreateCourse(newCourseViewModel, userId); // Assert var courseFromServer = await courseClient.GetCourseById(courseId, userId); - Assert.Equal(newCourseViewModel.Name, courseFromServer.Name); - Assert.Equal(newCourseViewModel.GroupName, courseFromServer.GroupName); - Assert.Contains(userId, courseFromServer.MentorIds); + Assert.AreEqual(newCourseViewModel.Name, courseFromServer.Name); + Assert.AreEqual(newCourseViewModel.GroupName, courseFromServer.GroupName); + Assert.IsTrue(courseFromServer.MentorIds.Contains(userId)); } - [Fact] - public async void TestDeleteCourse() + [Test] + public async Task TestDeleteCourse() { // Arrange var (userId, mail) = await CreateAndRegisterLecture(); @@ -114,11 +109,11 @@ public async void TestDeleteCourse() await courseClient.DeleteCourse(courseId); // Assert var coursesFromServer = await courseClient.GetAllCourses(); - Assert.True(coursesFromServer.FirstOrDefault(c => c.Id == courseId) == null); + Assert.IsTrue(coursesFromServer.FirstOrDefault(c => c.Id == courseId) == null); } - [Fact] - public async void TestUpdateCourse() + [Test] + public async Task TestUpdateCourse() { // Arrange var (userId, mail) = await CreateAndRegisterLecture(); @@ -130,14 +125,14 @@ public async void TestUpdateCourse() await courseClient.UpdateCourse(updateCourse, courseId); // Assert var courseFromServer = await courseClient.GetCourseById(courseId, userId); - Assert.Equal(updateCourse.Name, courseFromServer.Name); - Assert.Equal(updateCourse.GroupName, courseFromServer.GroupName); - Assert.Equal(updateCourse.IsComplete, courseFromServer.IsCompleted); - Assert.Equal(updateCourse.IsOpen, courseFromServer.IsOpen); + Assert.AreEqual(updateCourse.Name, courseFromServer.Name); + Assert.AreEqual(updateCourse.GroupName, courseFromServer.GroupName); + Assert.AreEqual(updateCourse.IsComplete, courseFromServer.IsCompleted); + Assert.AreEqual(updateCourse.IsOpen, courseFromServer.IsOpen); } - [Fact] - public async void TestSignInAndAcceptStudent() + [Test] + public async Task TestSignInAndAcceptStudent() { // Arrange var (lectureId, lectureMail) = await CreateAndRegisterLecture(); @@ -154,12 +149,12 @@ public async void TestSignInAndAcceptStudent() // Assert var mateBeforeAccept = courseBeforeAcceptStudent.CourseMates.FirstOrDefault(m => m.StudentId == studentId); var mateAfterAccept = courseAfterAcceptStudent.CourseMates.FirstOrDefault(m => m.StudentId == studentId); - Assert.False(mateBeforeAccept.IsAccepted); - Assert.True(mateAfterAccept.IsAccepted); + Assert.IsFalse(mateBeforeAccept.IsAccepted); + Assert.IsTrue(mateAfterAccept.IsAccepted); } - [Fact] - public async void TestSignInAndRejectStudent() + [Test] + public async Task TestSignInAndRejectStudent() { // Arrange var (lectureId, lectureMail) = await CreateAndRegisterLecture(); @@ -176,8 +171,8 @@ public async void TestSignInAndRejectStudent() // Assert var mateBeforeAccept = courseBeforeAcceptStudent.CourseMates.FirstOrDefault(m => m.StudentId == studentId); var mateAfterAccept = courseAfterAcceptStudent.CourseMates.FirstOrDefault(m => m.StudentId == studentId); - Assert.False(mateBeforeAccept.IsAccepted); - Assert.Null(mateAfterAccept); + Assert.IsFalse(mateBeforeAccept.IsAccepted); + Assert.IsNull(mateAfterAccept); } } } \ No newline at end of file diff --git a/HwProj.CoursesService/CourseService.IntegrationTestss/appsettings.json b/HwProj.CoursesService/CourseService.IntegrationTestss/appsettings.json deleted file mode 100644 index 2bed6354a..000000000 --- a/HwProj.CoursesService/CourseService.IntegrationTestss/appsettings.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "Services": { - "Courses": "http://localhost:5002" - } -} \ No newline at end of file From 51e6cb0a36dcd3261a79aad97aa31b97c46488af Mon Sep 17 00:00:00 2001 From: Volodya Petrov <89377379140@mail.ru> Date: Fri, 29 Apr 2022 22:43:56 +0300 Subject: [PATCH 10/20] Added FluentAssertions --- .../CourseService.IntegrationTests.csproj | 1 + .../CourseServiceTests.cs | 51 +++++++++---------- 2 files changed, 26 insertions(+), 26 deletions(-) diff --git a/HwProj.CoursesService/CourseService.IntegrationTests/CourseService.IntegrationTests.csproj b/HwProj.CoursesService/CourseService.IntegrationTests/CourseService.IntegrationTests.csproj index e77fb7360..03e4bdb3f 100644 --- a/HwProj.CoursesService/CourseService.IntegrationTests/CourseService.IntegrationTests.csproj +++ b/HwProj.CoursesService/CourseService.IntegrationTests/CourseService.IntegrationTests.csproj @@ -8,6 +8,7 @@ + diff --git a/HwProj.CoursesService/CourseService.IntegrationTests/CourseServiceTests.cs b/HwProj.CoursesService/CourseService.IntegrationTests/CourseServiceTests.cs index 44cb51f35..b5ac93030 100644 --- a/HwProj.CoursesService/CourseService.IntegrationTests/CourseServiceTests.cs +++ b/HwProj.CoursesService/CourseService.IntegrationTests/CourseServiceTests.cs @@ -1,8 +1,8 @@ -using System.Linq; using System.Net.Http; using System.Security.Claims; using System.Threading.Tasks; using AutoFixture; +using FluentAssertions; using HwProj.AuthService.Client; using HwProj.CoursesService.Client; using HwProj.Models.AuthService.ViewModels; @@ -85,23 +85,23 @@ private AuthServiceClient CreateAuthServiceClient() public async Task TestCreateCourse() { // Arrange - var (userId, mail) = await CreateAndRegisterLecture(); + var (userId, _) = await CreateAndRegisterLecture(); var courseClient = CreateCourseServiceClient(userId); var newCourseViewModel = GenerateCourseViewModel(); // Act var courseId = await courseClient.CreateCourse(newCourseViewModel, userId); // Assert var courseFromServer = await courseClient.GetCourseById(courseId, userId); - Assert.AreEqual(newCourseViewModel.Name, courseFromServer.Name); - Assert.AreEqual(newCourseViewModel.GroupName, courseFromServer.GroupName); - Assert.IsTrue(courseFromServer.MentorIds.Contains(userId)); + courseFromServer.Name.Should().Be(newCourseViewModel.Name); + courseFromServer.GroupName.Should().Be(newCourseViewModel.GroupName); + courseFromServer.MentorIds.Should().Contain(userId); } [Test] public async Task TestDeleteCourse() { // Arrange - var (userId, mail) = await CreateAndRegisterLecture(); + var (userId, _) = await CreateAndRegisterLecture(); var courseClient = CreateCourseServiceClient(userId); var newCourseViewModel = GenerateCourseViewModel(); // Act @@ -109,14 +109,14 @@ public async Task TestDeleteCourse() await courseClient.DeleteCourse(courseId); // Assert var coursesFromServer = await courseClient.GetAllCourses(); - Assert.IsTrue(coursesFromServer.FirstOrDefault(c => c.Id == courseId) == null); + coursesFromServer.Should().NotContain(c => c.Id == courseId); } [Test] public async Task TestUpdateCourse() { // Arrange - var (userId, mail) = await CreateAndRegisterLecture(); + var (userId, _) = await CreateAndRegisterLecture(); var courseClient = CreateCourseServiceClient(userId); var newCourseViewModel = GenerateCourseViewModel(); // Act @@ -125,18 +125,18 @@ public async Task TestUpdateCourse() await courseClient.UpdateCourse(updateCourse, courseId); // Assert var courseFromServer = await courseClient.GetCourseById(courseId, userId); - Assert.AreEqual(updateCourse.Name, courseFromServer.Name); - Assert.AreEqual(updateCourse.GroupName, courseFromServer.GroupName); - Assert.AreEqual(updateCourse.IsComplete, courseFromServer.IsCompleted); - Assert.AreEqual(updateCourse.IsOpen, courseFromServer.IsOpen); + courseFromServer.Name.Should().Be(updateCourse.Name); + courseFromServer.GroupName.Should().Be(updateCourse.GroupName); + courseFromServer.IsCompleted.Should().Be(updateCourse.IsComplete); + courseFromServer.IsOpen.Should().Be(updateCourse.IsOpen); } [Test] public async Task TestSignInAndAcceptStudent() { // Arrange - var (lectureId, lectureMail) = await CreateAndRegisterLecture(); - var (studentId, studentMail) = await CreateAndRegisterUser(); + var (lectureId, _) = await CreateAndRegisterLecture(); + var (studentId, _) = await CreateAndRegisterUser(); var lectureCourseClient = CreateCourseServiceClient(lectureId); var studentCourseClient = CreateCourseServiceClient(studentId); var newCourseViewModel = GenerateCourseViewModel(); @@ -147,32 +147,31 @@ public async Task TestSignInAndAcceptStudent() await lectureCourseClient.AcceptStudent(courseId, studentId); var courseAfterAcceptStudent = await lectureCourseClient.GetCourseById(courseId, lectureId); // Assert - var mateBeforeAccept = courseBeforeAcceptStudent.CourseMates.FirstOrDefault(m => m.StudentId == studentId); - var mateAfterAccept = courseAfterAcceptStudent.CourseMates.FirstOrDefault(m => m.StudentId == studentId); - Assert.IsFalse(mateBeforeAccept.IsAccepted); - Assert.IsTrue(mateAfterAccept.IsAccepted); + courseBeforeAcceptStudent.CourseMates.Should().Contain(s => s.StudentId == studentId).Which.IsAccepted + .Should().BeFalse(); + courseAfterAcceptStudent.CourseMates.Should().Contain(s => s.StudentId == studentId).Which.IsAccepted + .Should().BeTrue(); } [Test] public async Task TestSignInAndRejectStudent() { // Arrange - var (lectureId, lectureMail) = await CreateAndRegisterLecture(); - var (studentId, studentMail) = await CreateAndRegisterUser(); + var (lectureId, _) = await CreateAndRegisterLecture(); + var (studentId, _) = await CreateAndRegisterUser(); var lectureCourseClient = CreateCourseServiceClient(lectureId); var studentCourseClient = CreateCourseServiceClient(studentId); var newCourseViewModel = GenerateCourseViewModel(); // Act var courseId = await lectureCourseClient.CreateCourse(newCourseViewModel, lectureId); await studentCourseClient.SignInCourse(courseId, studentId); - var courseBeforeAcceptStudent = await lectureCourseClient.GetCourseById(courseId, lectureId); + var courseBeforeRejectStudent = await lectureCourseClient.GetCourseById(courseId, lectureId); await lectureCourseClient.RejectStudent(courseId, studentId); - var courseAfterAcceptStudent = await lectureCourseClient.GetCourseById(courseId, lectureId); + var courseAfterRejectStudent = await lectureCourseClient.GetCourseById(courseId, lectureId); // Assert - var mateBeforeAccept = courseBeforeAcceptStudent.CourseMates.FirstOrDefault(m => m.StudentId == studentId); - var mateAfterAccept = courseAfterAcceptStudent.CourseMates.FirstOrDefault(m => m.StudentId == studentId); - Assert.IsFalse(mateBeforeAccept.IsAccepted); - Assert.IsNull(mateAfterAccept); + courseBeforeRejectStudent.CourseMates.Should().Contain(s => s.StudentId == studentId).Which.IsAccepted + .Should().BeFalse(); + courseAfterRejectStudent.CourseMates.Should().NotContain(s => s.StudentId == studentId); } } } \ No newline at end of file From 797663ccb35b22580990de0b23380c0cc3cf56b4 Mon Sep 17 00:00:00 2001 From: Volodya Petrov <89377379140@mail.ru> Date: Mon, 2 May 2022 00:10:23 +0300 Subject: [PATCH 11/20] added addHomeWorkToCourse test --- .../CourseServiceTests.cs | 36 +++++++++++++++---- 1 file changed, 29 insertions(+), 7 deletions(-) diff --git a/HwProj.CoursesService/CourseService.IntegrationTests/CourseServiceTests.cs b/HwProj.CoursesService/CourseService.IntegrationTests/CourseServiceTests.cs index b5ac93030..f8fc34125 100644 --- a/HwProj.CoursesService/CourseService.IntegrationTests/CourseServiceTests.cs +++ b/HwProj.CoursesService/CourseService.IntegrationTests/CourseServiceTests.cs @@ -1,3 +1,4 @@ +using System.Collections.Generic; using System.Net.Http; using System.Security.Claims; using System.Threading.Tasks; @@ -42,6 +43,13 @@ private UpdateCourseViewModel GenerateUpdateCourseViewModel() return fixture.Create(); } + private CreateHomeworkViewModel GenerateCreateHomeworkViewModel() + { + var fixture = new Fixture().Build() + .With(hvm => hvm.Tasks, new List()); + return fixture.Create(); + } + private CoursesServiceClient CreateCourseServiceClient(string userId) { var mockIConfiguration = new Mock(); @@ -92,9 +100,7 @@ public async Task TestCreateCourse() var courseId = await courseClient.CreateCourse(newCourseViewModel, userId); // Assert var courseFromServer = await courseClient.GetCourseById(courseId, userId); - courseFromServer.Name.Should().Be(newCourseViewModel.Name); - courseFromServer.GroupName.Should().Be(newCourseViewModel.GroupName); - courseFromServer.MentorIds.Should().Contain(userId); + courseFromServer.Should().BeEquivalentTo(newCourseViewModel); } [Test] @@ -125,10 +131,7 @@ public async Task TestUpdateCourse() await courseClient.UpdateCourse(updateCourse, courseId); // Assert var courseFromServer = await courseClient.GetCourseById(courseId, userId); - courseFromServer.Name.Should().Be(updateCourse.Name); - courseFromServer.GroupName.Should().Be(updateCourse.GroupName); - courseFromServer.IsCompleted.Should().Be(updateCourse.IsComplete); - courseFromServer.IsOpen.Should().Be(updateCourse.IsOpen); + courseFromServer.Should().BeEquivalentTo(updateCourse); } [Test] @@ -173,5 +176,24 @@ public async Task TestSignInAndRejectStudent() .Should().BeFalse(); courseAfterRejectStudent.CourseMates.Should().NotContain(s => s.StudentId == studentId); } + + [Test] + public async Task TestAddHomeworkToCourse() + { + // Arrange + var (lectureId, _) = await CreateAndRegisterLecture(); + var courseClient = CreateCourseServiceClient(lectureId); + var newCourseViewModel = GenerateCourseViewModel(); + var newHomeworkViewModel = GenerateCreateHomeworkViewModel(); + // Act + var courseId = await courseClient.CreateCourse(newCourseViewModel, lectureId); + var homeworkId = await courseClient.AddHomeworkToCourse(newHomeworkViewModel, courseId); + var course = await courseClient.GetCourseById(courseId, lectureId); + var homework = await courseClient.GetHomework(homeworkId); + // Arrange + homework.Should().BeEquivalentTo(newHomeworkViewModel); + course.Homeworks.Should().Contain(h => h.Id == homeworkId).Which.Should() + .BeEquivalentTo(newHomeworkViewModel); + } } } \ No newline at end of file From 58969dd6fbf50030eaf9820d94aac74a120620f8 Mon Sep 17 00:00:00 2001 From: Volodya Petrov <89377379140@mail.ru> Date: Mon, 2 May 2022 00:30:44 +0300 Subject: [PATCH 12/20] wip --- .../HwProj.Models/CoursesService/ViewModels/CourseViewModels.cs | 2 +- .../HwProj.CoursesService.API/Controllers/CoursesController.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/HwProj.Common/HwProj.Models/CoursesService/ViewModels/CourseViewModels.cs b/HwProj.Common/HwProj.Models/CoursesService/ViewModels/CourseViewModels.cs index ff2b3ddad..e4cefde2a 100644 --- a/HwProj.Common/HwProj.Models/CoursesService/ViewModels/CourseViewModels.cs +++ b/HwProj.Common/HwProj.Models/CoursesService/ViewModels/CourseViewModels.cs @@ -26,7 +26,7 @@ public class UpdateCourseViewModel [Required] public bool IsOpen { get; set; } - public bool IsComplete { get; set; } + public bool IsCompleted { get; set; } } public class CourseViewModel diff --git a/HwProj.CoursesService/HwProj.CoursesService.API/Controllers/CoursesController.cs b/HwProj.CoursesService/HwProj.CoursesService.API/Controllers/CoursesController.cs index 224328c11..b7735d93e 100644 --- a/HwProj.CoursesService/HwProj.CoursesService.API/Controllers/CoursesController.cs +++ b/HwProj.CoursesService/HwProj.CoursesService.API/Controllers/CoursesController.cs @@ -79,7 +79,7 @@ public async Task UpdateCourse(long courseId, [FromBody] UpdateCo { Name = courseViewModel.Name, GroupName = courseViewModel.GroupName, - IsCompleted = courseViewModel.IsComplete, + IsCompleted = courseViewModel.IsCompleted, IsOpen = courseViewModel.IsOpen }); From 369c1fb34d005b03d1b508c2879847df339fe7b9 Mon Sep 17 00:00:00 2001 From: Volodya Petrov <89377379140@mail.ru> Date: Mon, 2 May 2022 13:08:10 +0300 Subject: [PATCH 13/20] added update and delete homework tests --- .../CourseServiceTests.cs | 53 ++++++++++++++++--- 1 file changed, 45 insertions(+), 8 deletions(-) diff --git a/HwProj.CoursesService/CourseService.IntegrationTests/CourseServiceTests.cs b/HwProj.CoursesService/CourseService.IntegrationTests/CourseServiceTests.cs index f8fc34125..d2386373e 100644 --- a/HwProj.CoursesService/CourseService.IntegrationTests/CourseServiceTests.cs +++ b/HwProj.CoursesService/CourseService.IntegrationTests/CourseServiceTests.cs @@ -29,7 +29,7 @@ private RegisterViewModel GenerateRegisterViewModel() return viewModel; } - private CreateCourseViewModel GenerateCourseViewModel() + private CreateCourseViewModel GenerateCreateCourseViewModel() { var fixture = new Fixture().Build() .With(cvm => cvm.IsOpen, true); @@ -49,7 +49,7 @@ private CreateHomeworkViewModel GenerateCreateHomeworkViewModel() .With(hvm => hvm.Tasks, new List()); return fixture.Create(); } - + private CoursesServiceClient CreateCourseServiceClient(string userId) { var mockIConfiguration = new Mock(); @@ -95,7 +95,7 @@ public async Task TestCreateCourse() // Arrange var (userId, _) = await CreateAndRegisterLecture(); var courseClient = CreateCourseServiceClient(userId); - var newCourseViewModel = GenerateCourseViewModel(); + var newCourseViewModel = GenerateCreateCourseViewModel(); // Act var courseId = await courseClient.CreateCourse(newCourseViewModel, userId); // Assert @@ -109,7 +109,7 @@ public async Task TestDeleteCourse() // Arrange var (userId, _) = await CreateAndRegisterLecture(); var courseClient = CreateCourseServiceClient(userId); - var newCourseViewModel = GenerateCourseViewModel(); + var newCourseViewModel = GenerateCreateCourseViewModel(); // Act var courseId = await courseClient.CreateCourse(newCourseViewModel, userId); await courseClient.DeleteCourse(courseId); @@ -124,7 +124,7 @@ public async Task TestUpdateCourse() // Arrange var (userId, _) = await CreateAndRegisterLecture(); var courseClient = CreateCourseServiceClient(userId); - var newCourseViewModel = GenerateCourseViewModel(); + var newCourseViewModel = GenerateCreateCourseViewModel(); // Act var courseId = await courseClient.CreateCourse(newCourseViewModel, userId); var updateCourse = GenerateUpdateCourseViewModel(); @@ -142,7 +142,7 @@ public async Task TestSignInAndAcceptStudent() var (studentId, _) = await CreateAndRegisterUser(); var lectureCourseClient = CreateCourseServiceClient(lectureId); var studentCourseClient = CreateCourseServiceClient(studentId); - var newCourseViewModel = GenerateCourseViewModel(); + var newCourseViewModel = GenerateCreateCourseViewModel(); // Act var courseId = await lectureCourseClient.CreateCourse(newCourseViewModel, lectureId); await studentCourseClient.SignInCourse(courseId, studentId); @@ -164,7 +164,7 @@ public async Task TestSignInAndRejectStudent() var (studentId, _) = await CreateAndRegisterUser(); var lectureCourseClient = CreateCourseServiceClient(lectureId); var studentCourseClient = CreateCourseServiceClient(studentId); - var newCourseViewModel = GenerateCourseViewModel(); + var newCourseViewModel = GenerateCreateCourseViewModel(); // Act var courseId = await lectureCourseClient.CreateCourse(newCourseViewModel, lectureId); await studentCourseClient.SignInCourse(courseId, studentId); @@ -183,7 +183,7 @@ public async Task TestAddHomeworkToCourse() // Arrange var (lectureId, _) = await CreateAndRegisterLecture(); var courseClient = CreateCourseServiceClient(lectureId); - var newCourseViewModel = GenerateCourseViewModel(); + var newCourseViewModel = GenerateCreateCourseViewModel(); var newHomeworkViewModel = GenerateCreateHomeworkViewModel(); // Act var courseId = await courseClient.CreateCourse(newCourseViewModel, lectureId); @@ -195,5 +195,42 @@ public async Task TestAddHomeworkToCourse() course.Homeworks.Should().Contain(h => h.Id == homeworkId).Which.Should() .BeEquivalentTo(newHomeworkViewModel); } + + [Test] + public async Task TestUpdateHomework() + { + // Arrange + var (lectureId, _) = await CreateAndRegisterLecture(); + var courseClient = CreateCourseServiceClient(lectureId); + var newCourseViewModel = GenerateCreateCourseViewModel(); + var newHomeworkViewModel = GenerateCreateHomeworkViewModel(); + var courseId = await courseClient.CreateCourse(newCourseViewModel, lectureId); + var homeworkId = await courseClient.AddHomeworkToCourse(newHomeworkViewModel, courseId); + var updateHomeworkViewModel = GenerateCreateHomeworkViewModel(); + // Act + await courseClient.UpdateHomework(updateHomeworkViewModel, homeworkId); + var course = await courseClient.GetCourseById(courseId, lectureId); + var homework = await courseClient.GetHomework(homeworkId); + // Arrange + homework.Should().BeEquivalentTo(updateHomeworkViewModel); + course.Homeworks.Should().Contain(h => h.Id == homeworkId).Which.Should() + .BeEquivalentTo(updateHomeworkViewModel); + } + + [Test] + public async Task DeleteHomework() + { + var (lectureId, _) = await CreateAndRegisterLecture(); + var courseClient = CreateCourseServiceClient(lectureId); + var newCourseViewModel = GenerateCreateCourseViewModel(); + var newHomeworkViewModel = GenerateCreateHomeworkViewModel(); + // Act + var courseId = await courseClient.CreateCourse(newCourseViewModel, lectureId); + var homeworkId = await courseClient.AddHomeworkToCourse(newHomeworkViewModel, courseId); + await courseClient.DeleteHomework(homeworkId); + var course = await courseClient.GetCourseById(courseId, lectureId); + // Arrange + course.Homeworks.Should().NotContain(h => h.Id == homeworkId); + } } } \ No newline at end of file From 5abc90e80763aa90539f47daf95e3949cc2ffaf4 Mon Sep 17 00:00:00 2001 From: Volodya Petrov <89377379140@mail.ru> Date: Mon, 2 May 2022 14:09:19 +0300 Subject: [PATCH 14/20] added AddTask test --- .../CourseServiceTests.cs | 34 +++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/HwProj.CoursesService/CourseService.IntegrationTests/CourseServiceTests.cs b/HwProj.CoursesService/CourseService.IntegrationTests/CourseServiceTests.cs index d2386373e..74a940f11 100644 --- a/HwProj.CoursesService/CourseService.IntegrationTests/CourseServiceTests.cs +++ b/HwProj.CoursesService/CourseService.IntegrationTests/CourseServiceTests.cs @@ -50,6 +50,11 @@ private CreateHomeworkViewModel GenerateCreateHomeworkViewModel() return fixture.Create(); } + private CreateTaskViewModel GenerateCreateTaskViewModel() + { + return new Fixture().Build().Create(); + } + private CoursesServiceClient CreateCourseServiceClient(string userId) { var mockIConfiguration = new Mock(); @@ -218,19 +223,44 @@ public async Task TestUpdateHomework() } [Test] - public async Task DeleteHomework() + public async Task TestDeleteHomework() { var (lectureId, _) = await CreateAndRegisterLecture(); var courseClient = CreateCourseServiceClient(lectureId); var newCourseViewModel = GenerateCreateCourseViewModel(); var newHomeworkViewModel = GenerateCreateHomeworkViewModel(); - // Act var courseId = await courseClient.CreateCourse(newCourseViewModel, lectureId); var homeworkId = await courseClient.AddHomeworkToCourse(newHomeworkViewModel, courseId); + // Act await courseClient.DeleteHomework(homeworkId); var course = await courseClient.GetCourseById(courseId, lectureId); // Arrange course.Homeworks.Should().NotContain(h => h.Id == homeworkId); } + + [Test] + public async Task TestAddTask() + { + var (lectureId, _) = await CreateAndRegisterLecture(); + var courseClient = CreateCourseServiceClient(lectureId); + var newCourseViewModel = GenerateCreateCourseViewModel(); + var newHomeworkViewModel = GenerateCreateHomeworkViewModel(); + var newTaskViewModel = GenerateCreateTaskViewModel(); + var courseId = await courseClient.CreateCourse(newCourseViewModel, lectureId); + var homeworkId = await courseClient.AddHomeworkToCourse(newHomeworkViewModel, courseId); + // Act + var taskId = await courseClient.AddTask(newTaskViewModel, homeworkId); + var course = await courseClient.GetCourseById(courseId, lectureId); + var homework = await courseClient.GetHomework(homeworkId); + var task = await courseClient.GetTask(taskId); + // Arrange + course.Homeworks.Should().Contain(h => h.Id == homeworkId) + .Which.Tasks.Should().Contain(t => t.Id == taskId) + .Which.Should().BeEquivalentTo(newTaskViewModel); + homework.Tasks.Should().Contain(t => t.Id == taskId) + .Which.Should().BeEquivalentTo(newTaskViewModel); + task.Should().BeEquivalentTo(newTaskViewModel); + task.HomeworkId.Should().Be(homeworkId); + } } } \ No newline at end of file From a769f1e6bf9e67ccad0631f3f8bda78f3d578858 Mon Sep 17 00:00:00 2001 From: Volodya Petrov <89377379140@mail.ru> Date: Mon, 2 May 2022 15:51:43 +0300 Subject: [PATCH 15/20] update and delete task added --- .../CourseServiceTests.cs | 58 +++++++++++++++++-- 1 file changed, 54 insertions(+), 4 deletions(-) diff --git a/HwProj.CoursesService/CourseService.IntegrationTests/CourseServiceTests.cs b/HwProj.CoursesService/CourseService.IntegrationTests/CourseServiceTests.cs index 74a940f11..7e52fc0aa 100644 --- a/HwProj.CoursesService/CourseService.IntegrationTests/CourseServiceTests.cs +++ b/HwProj.CoursesService/CourseService.IntegrationTests/CourseServiceTests.cs @@ -195,7 +195,7 @@ public async Task TestAddHomeworkToCourse() var homeworkId = await courseClient.AddHomeworkToCourse(newHomeworkViewModel, courseId); var course = await courseClient.GetCourseById(courseId, lectureId); var homework = await courseClient.GetHomework(homeworkId); - // Arrange + // Assert homework.Should().BeEquivalentTo(newHomeworkViewModel); course.Homeworks.Should().Contain(h => h.Id == homeworkId).Which.Should() .BeEquivalentTo(newHomeworkViewModel); @@ -216,7 +216,7 @@ public async Task TestUpdateHomework() await courseClient.UpdateHomework(updateHomeworkViewModel, homeworkId); var course = await courseClient.GetCourseById(courseId, lectureId); var homework = await courseClient.GetHomework(homeworkId); - // Arrange + // Assert homework.Should().BeEquivalentTo(updateHomeworkViewModel); course.Homeworks.Should().Contain(h => h.Id == homeworkId).Which.Should() .BeEquivalentTo(updateHomeworkViewModel); @@ -234,13 +234,14 @@ public async Task TestDeleteHomework() // Act await courseClient.DeleteHomework(homeworkId); var course = await courseClient.GetCourseById(courseId, lectureId); - // Arrange + // Assert course.Homeworks.Should().NotContain(h => h.Id == homeworkId); } [Test] public async Task TestAddTask() { + // Arrange var (lectureId, _) = await CreateAndRegisterLecture(); var courseClient = CreateCourseServiceClient(lectureId); var newCourseViewModel = GenerateCreateCourseViewModel(); @@ -253,7 +254,7 @@ public async Task TestAddTask() var course = await courseClient.GetCourseById(courseId, lectureId); var homework = await courseClient.GetHomework(homeworkId); var task = await courseClient.GetTask(taskId); - // Arrange + // Assert course.Homeworks.Should().Contain(h => h.Id == homeworkId) .Which.Tasks.Should().Contain(t => t.Id == taskId) .Which.Should().BeEquivalentTo(newTaskViewModel); @@ -262,5 +263,54 @@ public async Task TestAddTask() task.Should().BeEquivalentTo(newTaskViewModel); task.HomeworkId.Should().Be(homeworkId); } + + [Test] + public async Task TestUpdateTask() + { + // Arrange + var (lectureId, _) = await CreateAndRegisterLecture(); + var courseClient = CreateCourseServiceClient(lectureId); + var newCourseViewModel = GenerateCreateCourseViewModel(); + var newHomeworkViewModel = GenerateCreateHomeworkViewModel(); + var newTaskViewModel = GenerateCreateTaskViewModel(); + var updateTaskViewModel = GenerateCreateTaskViewModel(); + var courseId = await courseClient.CreateCourse(newCourseViewModel, lectureId); + var homeworkId = await courseClient.AddHomeworkToCourse(newHomeworkViewModel, courseId); + var taskId = await courseClient.AddTask(newTaskViewModel, homeworkId); + // Act + await courseClient.UpdateTask(updateTaskViewModel, taskId); + var course = await courseClient.GetCourseById(courseId, lectureId); + var homework = await courseClient.GetHomework(homeworkId); + var task = await courseClient.GetTask(taskId); + // Assert + course.Homeworks.Should().Contain(h => h.Id == homeworkId) + .Which.Tasks.Should().Contain(t => t.Id == taskId) + .Which.Should().BeEquivalentTo(updateTaskViewModel); + homework.Tasks.Should().Contain(t => t.Id == taskId) + .Which.Should().BeEquivalentTo(updateTaskViewModel); + task.Should().BeEquivalentTo(updateTaskViewModel); + } + + [Test] + public async Task TestDeleteTask() + { + // Arrange + var (lectureId, _) = await CreateAndRegisterLecture(); + var courseClient = CreateCourseServiceClient(lectureId); + var newCourseViewModel = GenerateCreateCourseViewModel(); + var newHomeworkViewModel = GenerateCreateHomeworkViewModel(); + var newTaskViewModel = GenerateCreateTaskViewModel(); + var courseId = await courseClient.CreateCourse(newCourseViewModel, lectureId); + var homeworkId = await courseClient.AddHomeworkToCourse(newHomeworkViewModel, courseId); + var taskId = await courseClient.AddTask(newTaskViewModel, homeworkId); + // Act + await courseClient.DeleteTask(taskId); + var course = await courseClient.GetCourseById(courseId, lectureId); + var homework = await courseClient.GetHomework(homeworkId); + // Assert + course.Homeworks.Should().Contain(h => h.Id == homeworkId) + .Which.Tasks.Should().NotContain(t => t.Id == taskId); + homework.Tasks.Should().NotContain(t => t.Id == taskId); + } } } \ No newline at end of file From 49881aa870381797b2f1569151bb78f4681c4041 Mon Sep 17 00:00:00 2001 From: Volodya Petrov <89377379140@mail.ru> Date: Sat, 7 May 2022 23:07:53 +0300 Subject: [PATCH 16/20] added test for publication dates --- .../CourseServiceTests.cs | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/HwProj.CoursesService/CourseService.IntegrationTests/CourseServiceTests.cs b/HwProj.CoursesService/CourseService.IntegrationTests/CourseServiceTests.cs index 7e52fc0aa..63e3f8753 100644 --- a/HwProj.CoursesService/CourseService.IntegrationTests/CourseServiceTests.cs +++ b/HwProj.CoursesService/CourseService.IntegrationTests/CourseServiceTests.cs @@ -1,4 +1,6 @@ +using System; using System.Collections.Generic; +using System.Linq; using System.Net.Http; using System.Security.Claims; using System.Threading.Tasks; @@ -312,5 +314,34 @@ public async Task TestDeleteTask() .Which.Tasks.Should().NotContain(t => t.Id == taskId); homework.Tasks.Should().NotContain(t => t.Id == taskId); } + + [Test] + public async Task TestPublicationDateForTask() + { + // Arrange + var (lectureId, _) = await CreateAndRegisterLecture(); + var (studentId, _) = await CreateAndRegisterUser(); + var lectureCourseClient = CreateCourseServiceClient(lectureId); + var studentCourseClient = CreateCourseServiceClient(studentId); + var newCourseViewModel = GenerateCreateCourseViewModel(); + var newHomeworkViewModel = GenerateCreateHomeworkViewModel(); + var firstTaskViewModel = GenerateCreateTaskViewModel(); + firstTaskViewModel.PublicationDate = DateTime.UtcNow.AddHours(3); + var secondTaskViewModel = GenerateCreateTaskViewModel(); + secondTaskViewModel.PublicationDate = DateTime.UtcNow.AddHours(4); + var courseId = await lectureCourseClient.CreateCourse(newCourseViewModel, lectureId); + var homeworkId = await lectureCourseClient.AddHomeworkToCourse(newHomeworkViewModel, courseId); + var task1Id = await lectureCourseClient.AddTask(firstTaskViewModel, homeworkId); + var task2Id = await lectureCourseClient.AddTask(secondTaskViewModel, homeworkId); + var courseFromStudent = await studentCourseClient.GetCourseById(courseId, studentId); + var courseFromLecture = await lectureCourseClient.GetCourseById(courseId, lectureId); + // Assert + var hwFromStudent = courseFromStudent.Homeworks.First(h => h.Id == homeworkId); + var hwFromLecture = courseFromLecture.Homeworks.First(h => h.Id == homeworkId); + hwFromStudent.Tasks.Should().Contain(t => t.Id == task1Id); + hwFromStudent.Tasks.Should().NotContain(t => t.Id == task2Id); + hwFromLecture.Tasks.Should().Contain(t => t.Id == task1Id); + hwFromLecture.Tasks.Should().Contain(t => t.Id == task2Id); + } } } \ No newline at end of file From ae837ba4c86f19f24b7a6b9dae0453d0af79b43b Mon Sep 17 00:00:00 2001 From: Volodya Petrov <89377379140@mail.ru> Date: Sun, 8 May 2022 21:44:00 +0300 Subject: [PATCH 17/20] CourseMentorOnlyAttribute tests (wip) --- .../CourseServiceTests.cs | 28 ++++++++++++++++++- .../CoursesServiceClient.cs | 1 - 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/HwProj.CoursesService/CourseService.IntegrationTests/CourseServiceTests.cs b/HwProj.CoursesService/CourseService.IntegrationTests/CourseServiceTests.cs index 63e3f8753..23fa89781 100644 --- a/HwProj.CoursesService/CourseService.IntegrationTests/CourseServiceTests.cs +++ b/HwProj.CoursesService/CourseService.IntegrationTests/CourseServiceTests.cs @@ -16,7 +16,7 @@ using Moq; using NUnit.Framework; -namespace Tests +namespace CourseService.IntegrationTests { public class Tests { @@ -343,5 +343,31 @@ public async Task TestPublicationDateForTask() hwFromLecture.Tasks.Should().Contain(t => t.Id == task1Id); hwFromLecture.Tasks.Should().Contain(t => t.Id == task2Id); } + + [Test] + public async Task TestAttributeMentorCourseOnly() + { + // Arrange + var (courseLectureId, _) = await CreateAndRegisterLecture(); + var (studentInCourseId, _) = await CreateAndRegisterUser(); + var (anotherLectureId, _) = await CreateAndRegisterLecture(); + var (anotherStudentId, _) = await CreateAndRegisterUser(); + var newCourseViewModel = GenerateCreateCourseViewModel(); + var newHomeworkViewModel = GenerateCreateHomeworkViewModel(); + var newTaskViewModel = GenerateCreateTaskViewModel(); + var courseLectureClient = CreateCourseServiceClient(courseLectureId); + var studentInCourseClient = CreateCourseServiceClient(studentInCourseId); + var anotherLectureClient = CreateCourseServiceClient(anotherLectureId); + var anotherStudentClient = CreateCourseServiceClient(anotherStudentId); + var courseId = await courseLectureClient.CreateCourse(newCourseViewModel, courseLectureId); + var homeworkId = await courseLectureClient.AddHomeworkToCourse(newHomeworkViewModel, courseId); + var taskId = await courseLectureClient.AddTask(newTaskViewModel, homeworkId); + await studentInCourseClient.SignInCourse(courseId, studentInCourseId); + await courseLectureClient.AcceptStudent(courseId, studentInCourseId); + // Act and Assert UpdateCourse + var updateCourseViewModel = GenerateUpdateCourseViewModel(); + await studentInCourseClient.UpdateCourse(updateCourseViewModel, courseId); + + } } } \ No newline at end of file diff --git a/HwProj.CoursesService/HwProj.CoursesService.Client/CoursesServiceClient.cs b/HwProj.CoursesService/HwProj.CoursesService.Client/CoursesServiceClient.cs index c2e491666..fe53f88d3 100644 --- a/HwProj.CoursesService/HwProj.CoursesService.Client/CoursesServiceClient.cs +++ b/HwProj.CoursesService/HwProj.CoursesService.Client/CoursesServiceClient.cs @@ -124,7 +124,6 @@ public async Task RejectStudent(long courseId, string studentId) _coursesServiceUri + $"api/Courses/rejectStudent/{courseId}?studentId={studentId}"); httpRequest.AddUserId(_httpContextAccessor); - await _httpClient.SendAsync(httpRequest); } From 283d0fb741daea4461abaf1b5ff63f78546097ca Mon Sep 17 00:00:00 2001 From: Volodya Petrov <89377379140@mail.ru> Date: Fri, 20 May 2022 00:28:25 +0300 Subject: [PATCH 18/20] added tests for courseMentorOnly --- .../CourseServiceTests.cs | 268 ++++++++++++++++-- 1 file changed, 249 insertions(+), 19 deletions(-) diff --git a/HwProj.CoursesService/CourseService.IntegrationTests/CourseServiceTests.cs b/HwProj.CoursesService/CourseService.IntegrationTests/CourseServiceTests.cs index 23fa89781..cecf80ded 100644 --- a/HwProj.CoursesService/CourseService.IntegrationTests/CourseServiceTests.cs +++ b/HwProj.CoursesService/CourseService.IntegrationTests/CourseServiceTests.cs @@ -194,7 +194,7 @@ public async Task TestAddHomeworkToCourse() var newHomeworkViewModel = GenerateCreateHomeworkViewModel(); // Act var courseId = await courseClient.CreateCourse(newCourseViewModel, lectureId); - var homeworkId = await courseClient.AddHomeworkToCourse(newHomeworkViewModel, courseId); + var homeworkId = (await courseClient.AddHomeworkToCourse(newHomeworkViewModel, courseId)).Value; var course = await courseClient.GetCourseById(courseId, lectureId); var homework = await courseClient.GetHomework(homeworkId); // Assert @@ -212,7 +212,7 @@ public async Task TestUpdateHomework() var newCourseViewModel = GenerateCreateCourseViewModel(); var newHomeworkViewModel = GenerateCreateHomeworkViewModel(); var courseId = await courseClient.CreateCourse(newCourseViewModel, lectureId); - var homeworkId = await courseClient.AddHomeworkToCourse(newHomeworkViewModel, courseId); + var homeworkId = (await courseClient.AddHomeworkToCourse(newHomeworkViewModel, courseId)).Value; var updateHomeworkViewModel = GenerateCreateHomeworkViewModel(); // Act await courseClient.UpdateHomework(updateHomeworkViewModel, homeworkId); @@ -232,7 +232,7 @@ public async Task TestDeleteHomework() var newCourseViewModel = GenerateCreateCourseViewModel(); var newHomeworkViewModel = GenerateCreateHomeworkViewModel(); var courseId = await courseClient.CreateCourse(newCourseViewModel, lectureId); - var homeworkId = await courseClient.AddHomeworkToCourse(newHomeworkViewModel, courseId); + var homeworkId = (await courseClient.AddHomeworkToCourse(newHomeworkViewModel, courseId)).Value; // Act await courseClient.DeleteHomework(homeworkId); var course = await courseClient.GetCourseById(courseId, lectureId); @@ -250,9 +250,9 @@ public async Task TestAddTask() var newHomeworkViewModel = GenerateCreateHomeworkViewModel(); var newTaskViewModel = GenerateCreateTaskViewModel(); var courseId = await courseClient.CreateCourse(newCourseViewModel, lectureId); - var homeworkId = await courseClient.AddHomeworkToCourse(newHomeworkViewModel, courseId); + var homeworkId = (await courseClient.AddHomeworkToCourse(newHomeworkViewModel, courseId)).Value; // Act - var taskId = await courseClient.AddTask(newTaskViewModel, homeworkId); + var taskId = (await courseClient.AddTask(newTaskViewModel, homeworkId)).Value; var course = await courseClient.GetCourseById(courseId, lectureId); var homework = await courseClient.GetHomework(homeworkId); var task = await courseClient.GetTask(taskId); @@ -277,8 +277,8 @@ public async Task TestUpdateTask() var newTaskViewModel = GenerateCreateTaskViewModel(); var updateTaskViewModel = GenerateCreateTaskViewModel(); var courseId = await courseClient.CreateCourse(newCourseViewModel, lectureId); - var homeworkId = await courseClient.AddHomeworkToCourse(newHomeworkViewModel, courseId); - var taskId = await courseClient.AddTask(newTaskViewModel, homeworkId); + var homeworkId = (await courseClient.AddHomeworkToCourse(newHomeworkViewModel, courseId)).Value; + var taskId = (await courseClient.AddTask(newTaskViewModel, homeworkId)).Value; // Act await courseClient.UpdateTask(updateTaskViewModel, taskId); var course = await courseClient.GetCourseById(courseId, lectureId); @@ -303,8 +303,8 @@ public async Task TestDeleteTask() var newHomeworkViewModel = GenerateCreateHomeworkViewModel(); var newTaskViewModel = GenerateCreateTaskViewModel(); var courseId = await courseClient.CreateCourse(newCourseViewModel, lectureId); - var homeworkId = await courseClient.AddHomeworkToCourse(newHomeworkViewModel, courseId); - var taskId = await courseClient.AddTask(newTaskViewModel, homeworkId); + var homeworkId = (await courseClient.AddHomeworkToCourse(newHomeworkViewModel, courseId)).Value; + var taskId = (await courseClient.AddTask(newTaskViewModel, homeworkId)).Value; // Act await courseClient.DeleteTask(taskId); var course = await courseClient.GetCourseById(courseId, lectureId); @@ -330,9 +330,9 @@ public async Task TestPublicationDateForTask() var secondTaskViewModel = GenerateCreateTaskViewModel(); secondTaskViewModel.PublicationDate = DateTime.UtcNow.AddHours(4); var courseId = await lectureCourseClient.CreateCourse(newCourseViewModel, lectureId); - var homeworkId = await lectureCourseClient.AddHomeworkToCourse(newHomeworkViewModel, courseId); - var task1Id = await lectureCourseClient.AddTask(firstTaskViewModel, homeworkId); - var task2Id = await lectureCourseClient.AddTask(secondTaskViewModel, homeworkId); + var homeworkId = (await lectureCourseClient.AddHomeworkToCourse(newHomeworkViewModel, courseId)).Value; + var task1Id = (await lectureCourseClient.AddTask(firstTaskViewModel, homeworkId)).Value; + var task2Id = (await lectureCourseClient.AddTask(secondTaskViewModel, homeworkId)).Value; var courseFromStudent = await studentCourseClient.GetCourseById(courseId, studentId); var courseFromLecture = await lectureCourseClient.GetCourseById(courseId, lectureId); // Assert @@ -343,9 +343,148 @@ public async Task TestPublicationDateForTask() hwFromLecture.Tasks.Should().Contain(t => t.Id == task1Id); hwFromLecture.Tasks.Should().Contain(t => t.Id == task2Id); } + + [Test] + public async Task TestUpdateCourseOnlyForCourseMentor() + { + // Arrange + var (courseLectureId, _) = await CreateAndRegisterLecture(); + var (studentInCourseId, _) = await CreateAndRegisterUser(); + var (anotherLectureId, _) = await CreateAndRegisterLecture(); + var (anotherStudentId, _) = await CreateAndRegisterUser(); + var newCourseViewModel = GenerateCreateCourseViewModel(); + var updateViewModel = GenerateUpdateCourseViewModel(); + var courseLectureClient = CreateCourseServiceClient(courseLectureId); + var studentInCourseClient = CreateCourseServiceClient(studentInCourseId); + var anotherLectureClient = CreateCourseServiceClient(anotherLectureId); + var anotherStudentClient = CreateCourseServiceClient(anotherStudentId); + var courseId = await courseLectureClient.CreateCourse(newCourseViewModel, courseLectureId); + await studentInCourseClient.SignInCourse(courseId, studentInCourseId); + await courseLectureClient.AcceptStudent(courseId, studentInCourseId); + // Act + var responseForStudentInCourse = await studentInCourseClient.UpdateCourse(updateViewModel, courseId); + var responseForAnotherStudent = await anotherStudentClient.UpdateCourse(updateViewModel, courseId); + var responseForAnotherLecture = await anotherLectureClient.UpdateCourse(updateViewModel, courseId); + // Assert + responseForAnotherLecture.Succeeded.Should().BeFalse(); + responseForAnotherStudent.Succeeded.Should().BeFalse(); + responseForStudentInCourse.Succeeded.Should().BeFalse(); + } + + [Test] + public async Task TestDeleteCourseOnlyForCourseMentor() + { + // Arrange + var (courseLectureId, _) = await CreateAndRegisterLecture(); + var (studentInCourseId, _) = await CreateAndRegisterUser(); + var (anotherLectureId, _) = await CreateAndRegisterLecture(); + var (anotherStudentId, _) = await CreateAndRegisterUser(); + var newCourseViewModel = GenerateCreateCourseViewModel(); + var courseLectureClient = CreateCourseServiceClient(courseLectureId); + var studentInCourseClient = CreateCourseServiceClient(studentInCourseId); + var anotherLectureClient = CreateCourseServiceClient(anotherLectureId); + var anotherStudentClient = CreateCourseServiceClient(anotherStudentId); + var courseId = await courseLectureClient.CreateCourse(newCourseViewModel, courseLectureId); + await studentInCourseClient.SignInCourse(courseId, studentInCourseId); + await courseLectureClient.AcceptStudent(courseId, studentInCourseId); + // Act + var responseForStudentInCourse = await studentInCourseClient.DeleteCourse(courseId); + var responseForAnotherStudent = await anotherStudentClient.DeleteCourse(courseId); + var responseForAnotherLecture = await anotherLectureClient.DeleteCourse(courseId); + // Assert + responseForAnotherLecture.Succeeded.Should().BeFalse(); + responseForAnotherStudent.Succeeded.Should().BeFalse(); + responseForStudentInCourse.Succeeded.Should().BeFalse(); + } + + [Test] + public async Task TestAddHomeworkOnlyForCourseMentor() + { + // Arrange + var (courseLectureId, _) = await CreateAndRegisterLecture(); + var (studentInCourseId, _) = await CreateAndRegisterUser(); + var (anotherLectureId, _) = await CreateAndRegisterLecture(); + var (anotherStudentId, _) = await CreateAndRegisterUser(); + var newCourseViewModel = GenerateCreateCourseViewModel(); + var newHomeworkViewModel = GenerateCreateHomeworkViewModel(); + var courseLectureClient = CreateCourseServiceClient(courseLectureId); + var studentInCourseClient = CreateCourseServiceClient(studentInCourseId); + var anotherLectureClient = CreateCourseServiceClient(anotherLectureId); + var anotherStudentClient = CreateCourseServiceClient(anotherStudentId); + var courseId = await courseLectureClient.CreateCourse(newCourseViewModel, courseLectureId); + await studentInCourseClient.SignInCourse(courseId, studentInCourseId); + await courseLectureClient.AcceptStudent(courseId, studentInCourseId); + // Act + var responseForStudentInCourse = await studentInCourseClient.AddHomeworkToCourse(newHomeworkViewModel, courseId); + var responseForAnotherStudent = + await anotherStudentClient.AddHomeworkToCourse(newHomeworkViewModel, courseId); + var responseForAnotherLecture = await anotherLectureClient.AddHomeworkToCourse(newHomeworkViewModel, courseId); + //Assert + responseForAnotherLecture.Succeeded.Should().BeFalse(); + responseForAnotherStudent.Succeeded.Should().BeFalse(); + responseForStudentInCourse.Succeeded.Should().BeFalse(); + } [Test] - public async Task TestAttributeMentorCourseOnly() + public async Task TestUpdateHomeworkOnlyForCourseMentor() + { + var (courseLectureId, _) = await CreateAndRegisterLecture(); + var (studentInCourseId, _) = await CreateAndRegisterUser(); + var (anotherLectureId, _) = await CreateAndRegisterLecture(); + var (anotherStudentId, _) = await CreateAndRegisterUser(); + var newCourseViewModel = GenerateCreateCourseViewModel(); + var newHomeworkViewModel = GenerateCreateHomeworkViewModel(); + var updateHomeworkViewModel = GenerateCreateHomeworkViewModel(); + var courseLectureClient = CreateCourseServiceClient(courseLectureId); + var studentInCourseClient = CreateCourseServiceClient(studentInCourseId); + var anotherLectureClient = CreateCourseServiceClient(anotherLectureId); + var anotherStudentClient = CreateCourseServiceClient(anotherStudentId); + var courseId = await courseLectureClient.CreateCourse(newCourseViewModel, courseLectureId); + await studentInCourseClient.SignInCourse(courseId, studentInCourseId); + await courseLectureClient.AcceptStudent(courseId, studentInCourseId); + var homeworkId = (await courseLectureClient.AddHomeworkToCourse(newHomeworkViewModel, courseId)).Value; + // Act + var responseForStudentInCourse = await studentInCourseClient.UpdateHomework(updateHomeworkViewModel, homeworkId); + var responseForAnotherStudent = + await anotherStudentClient.UpdateHomework(updateHomeworkViewModel, homeworkId); + var responseForAnotherLecture = await anotherLectureClient.UpdateHomework(updateHomeworkViewModel, homeworkId); + //Assert + responseForAnotherLecture.Succeeded.Should().BeFalse(); + responseForAnotherStudent.Succeeded.Should().BeFalse(); + responseForStudentInCourse.Succeeded.Should().BeFalse(); + } + + [Test] + public async Task TestDeleteHomeworkOnlyForCourseMentor() + { + // Arrange + var (courseLectureId, _) = await CreateAndRegisterLecture(); + var (studentInCourseId, _) = await CreateAndRegisterUser(); + var (anotherLectureId, _) = await CreateAndRegisterLecture(); + var (anotherStudentId, _) = await CreateAndRegisterUser(); + var newCourseViewModel = GenerateCreateCourseViewModel(); + var newHomeworkViewModel = GenerateCreateHomeworkViewModel(); + var courseLectureClient = CreateCourseServiceClient(courseLectureId); + var studentInCourseClient = CreateCourseServiceClient(studentInCourseId); + var anotherLectureClient = CreateCourseServiceClient(anotherLectureId); + var anotherStudentClient = CreateCourseServiceClient(anotherStudentId); + var courseId = await courseLectureClient.CreateCourse(newCourseViewModel, courseLectureId); + await studentInCourseClient.SignInCourse(courseId, studentInCourseId); + await courseLectureClient.AcceptStudent(courseId, studentInCourseId); + var homeworkId = (await courseLectureClient.AddHomeworkToCourse(newHomeworkViewModel, courseId)).Value; + // Act + var responseForStudentInCourse = await studentInCourseClient.DeleteHomework(homeworkId); + var responseForAnotherStudent = + await anotherStudentClient.DeleteHomework(homeworkId); + var responseForAnotherLecture = await anotherLectureClient.DeleteHomework(homeworkId); + //Assert + responseForAnotherLecture.Succeeded.Should().BeFalse(); + responseForAnotherStudent.Succeeded.Should().BeFalse(); + responseForStudentInCourse.Succeeded.Should().BeFalse(); + } + + [Test] + public async Task TestAddTaskForCourseMentorOnly() { // Arrange var (courseLectureId, _) = await CreateAndRegisterLecture(); @@ -360,14 +499,105 @@ public async Task TestAttributeMentorCourseOnly() var anotherLectureClient = CreateCourseServiceClient(anotherLectureId); var anotherStudentClient = CreateCourseServiceClient(anotherStudentId); var courseId = await courseLectureClient.CreateCourse(newCourseViewModel, courseLectureId); - var homeworkId = await courseLectureClient.AddHomeworkToCourse(newHomeworkViewModel, courseId); - var taskId = await courseLectureClient.AddTask(newTaskViewModel, homeworkId); await studentInCourseClient.SignInCourse(courseId, studentInCourseId); await courseLectureClient.AcceptStudent(courseId, studentInCourseId); - // Act and Assert UpdateCourse - var updateCourseViewModel = GenerateUpdateCourseViewModel(); - await studentInCourseClient.UpdateCourse(updateCourseViewModel, courseId); - + var homeworkId = (await courseLectureClient.AddHomeworkToCourse(newHomeworkViewModel, courseId)).Value; + // Act + var responseForStudentInCourse = await studentInCourseClient.AddTask(newTaskViewModel, homeworkId); + var responseForAnotherStudent = await anotherStudentClient.AddTask(newTaskViewModel, homeworkId); + var responseForAnotherLecture = await anotherLectureClient.AddTask(newTaskViewModel, homeworkId); + //Assert + responseForAnotherLecture.Succeeded.Should().BeFalse(); + responseForAnotherStudent.Succeeded.Should().BeFalse(); + responseForStudentInCourse.Succeeded.Should().BeFalse(); + } + + [Test] + public async Task TestUpdateTaskForCourseMentorOnly() + { + // Arrange + var (courseLectureId, _) = await CreateAndRegisterLecture(); + var (studentInCourseId, _) = await CreateAndRegisterUser(); + var (anotherLectureId, _) = await CreateAndRegisterLecture(); + var (anotherStudentId, _) = await CreateAndRegisterUser(); + var newCourseViewModel = GenerateCreateCourseViewModel(); + var newHomeworkViewModel = GenerateCreateHomeworkViewModel(); + var newTaskViewModel = GenerateCreateTaskViewModel(); + var updateTaskViewModel = GenerateCreateTaskViewModel(); + var courseLectureClient = CreateCourseServiceClient(courseLectureId); + var studentInCourseClient = CreateCourseServiceClient(studentInCourseId); + var anotherLectureClient = CreateCourseServiceClient(anotherLectureId); + var anotherStudentClient = CreateCourseServiceClient(anotherStudentId); + var courseId = await courseLectureClient.CreateCourse(newCourseViewModel, courseLectureId); + await studentInCourseClient.SignInCourse(courseId, studentInCourseId); + await courseLectureClient.AcceptStudent(courseId, studentInCourseId); + var homeworkId = (await courseLectureClient.AddHomeworkToCourse(newHomeworkViewModel, courseId)).Value; + var taskId = (await courseLectureClient.AddTask(newTaskViewModel, homeworkId)).Value; + // Act + var responseForStudentInCourse = await studentInCourseClient.UpdateTask(updateTaskViewModel, taskId); + var responseForAnotherStudent = await anotherStudentClient.UpdateTask(updateTaskViewModel, taskId); + var responseForAnotherLecture = await anotherLectureClient.UpdateTask(updateTaskViewModel, taskId); + //Assert + responseForAnotherLecture.Succeeded.Should().BeFalse(); + responseForAnotherStudent.Succeeded.Should().BeFalse(); + responseForStudentInCourse.Succeeded.Should().BeFalse(); + } + + [Test] + public async Task TestDeleteTaskForCourseMentorOnly() + { + // Arrange + var (courseLectureId, _) = await CreateAndRegisterLecture(); + var (studentInCourseId, _) = await CreateAndRegisterUser(); + var (anotherLectureId, _) = await CreateAndRegisterLecture(); + var (anotherStudentId, _) = await CreateAndRegisterUser(); + var newCourseViewModel = GenerateCreateCourseViewModel(); + var newHomeworkViewModel = GenerateCreateHomeworkViewModel(); + var newTaskViewModel = GenerateCreateTaskViewModel(); + var courseLectureClient = CreateCourseServiceClient(courseLectureId); + var studentInCourseClient = CreateCourseServiceClient(studentInCourseId); + var anotherLectureClient = CreateCourseServiceClient(anotherLectureId); + var anotherStudentClient = CreateCourseServiceClient(anotherStudentId); + var courseId = await courseLectureClient.CreateCourse(newCourseViewModel, courseLectureId); + await studentInCourseClient.SignInCourse(courseId, studentInCourseId); + await courseLectureClient.AcceptStudent(courseId, studentInCourseId); + var homeworkId = (await courseLectureClient.AddHomeworkToCourse(newHomeworkViewModel, courseId)).Value; + var taskId = (await courseLectureClient.AddTask(newTaskViewModel, homeworkId)).Value; + // Act + var responseForStudentInCourse = await studentInCourseClient.DeleteTask(taskId); + var responseForAnotherStudent = await anotherStudentClient.DeleteTask(taskId); + var responseForAnotherLecture = await anotherLectureClient.DeleteTask(taskId); + //Assert + responseForAnotherLecture.Succeeded.Should().BeFalse(); + responseForAnotherStudent.Succeeded.Should().BeFalse(); + responseForStudentInCourse.Succeeded.Should().BeFalse(); + } + + [Test] + public async Task TestAcceptStudentForCourseMentorOnly() + { + // Assert + var (courseLectureId, _) = await CreateAndRegisterLecture(); + var (studentInCourseId, _) = await CreateAndRegisterUser(); + var (anotherLectureId, _) = await CreateAndRegisterLecture(); + var (anotherStudentId, _) = await CreateAndRegisterUser(); + var newCourseViewModel = GenerateCreateCourseViewModel(); + var courseLectureClient = CreateCourseServiceClient(courseLectureId); + var studentInCourseClient = CreateCourseServiceClient(studentInCourseId); + var anotherLectureClient = CreateCourseServiceClient(anotherLectureId); + var anotherStudentClient = CreateCourseServiceClient(anotherStudentId); + var courseId = await courseLectureClient.CreateCourse(newCourseViewModel, courseLectureId); + await studentInCourseClient.SignInCourse(courseId, studentInCourseId); + await courseLectureClient.AcceptStudent(courseId, studentInCourseId); + // Act + await anotherStudentClient.SignInCourse(courseId, anotherStudentId); + var responseForStudentInCourse = await studentInCourseClient.AcceptStudent(courseId, anotherStudentId); + var responseForAnotherStudent = await anotherStudentClient.AcceptStudent(courseId, anotherStudentId); + var responseForAnotherLecture = await anotherLectureClient.AcceptStudent(courseId, anotherStudentId); + //Assert + responseForAnotherLecture.Succeeded.Should().BeFalse(); + responseForAnotherStudent.Succeeded.Should().BeFalse(); + responseForStudentInCourse.Succeeded.Should().BeFalse(); } } } \ No newline at end of file From 920e8eb3069ff9b4e9ae0dca670f68c2600edde2 Mon Sep 17 00:00:00 2001 From: Volodya Petrov <89377379140@mail.ru> Date: Fri, 20 May 2022 01:24:12 +0300 Subject: [PATCH 19/20] tests with accept lecture --- .../CourseServiceTests.cs | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/HwProj.CoursesService/CourseService.IntegrationTests/CourseServiceTests.cs b/HwProj.CoursesService/CourseService.IntegrationTests/CourseServiceTests.cs index cecf80ded..8c4fc8ad2 100644 --- a/HwProj.CoursesService/CourseService.IntegrationTests/CourseServiceTests.cs +++ b/HwProj.CoursesService/CourseService.IntegrationTests/CourseServiceTests.cs @@ -314,6 +314,56 @@ public async Task TestDeleteTask() .Which.Tasks.Should().NotContain(t => t.Id == taskId); homework.Tasks.Should().NotContain(t => t.Id == taskId); } + + [Test] + public async Task TestAcceptLecture() + { + // Arrange + var (lectureId, _) = await CreateAndRegisterLecture(); + var (anotherLectureId, anotherLectureMail) = await CreateAndRegisterLecture(); + var lectureClient = CreateCourseServiceClient(lectureId); + var newCourseViewModel = GenerateCreateCourseViewModel(); + var courseId = await lectureClient.CreateCourse(newCourseViewModel, lectureId); + // Act + await lectureClient.AcceptLecturer(courseId, anotherLectureMail); + var course = await lectureClient.GetCourseById(courseId, lectureId); + // Assert + course.MentorIds.Should().Contain(anotherLectureId); + } + + [Test] + public async Task TestStudentCannotBeAcceptedAsLecture() + { + var (lectureId, _) = await CreateAndRegisterLecture(); + var (studentId, studentEmail) = await CreateAndRegisterUser(); + var lectureClient = CreateCourseServiceClient(lectureId); + var newCourseViewModel = GenerateCreateCourseViewModel(); + var courseId = await lectureClient.CreateCourse(newCourseViewModel, lectureId); + // Act + await lectureClient.AcceptLecturer(courseId, studentEmail); + var course = await lectureClient.GetCourseById(courseId, lectureId); + // Assert + course.MentorIds.Should().NotContain(studentId); + } + + [Test] + public async Task TestLectureWhenWasAcceptedShouldNotBeContainedInCourseMates() + { + // Arrange + var (lectureId, _) = await CreateAndRegisterLecture(); + var (anotherLectureId, anotherLectureMail) = await CreateAndRegisterLecture(); + var lectureClient = CreateCourseServiceClient(lectureId); + var anotherLectureClient = CreateCourseServiceClient(anotherLectureId); + var newCourseViewModel = GenerateCreateCourseViewModel(); + var courseId = await lectureClient.CreateCourse(newCourseViewModel, lectureId); + // Act + await anotherLectureClient.SignInCourse(courseId, anotherLectureId); + await lectureClient.AcceptLecturer(courseId, anotherLectureMail); + var course = await lectureClient.GetCourseById(courseId, lectureId); + // Assert + course.MentorIds.Should().Contain(anotherLectureId); + course.CourseMates.Should().NotContain(m => m.StudentId == anotherLectureId); + } [Test] public async Task TestPublicationDateForTask() From 7739b6928debdea0613cec48e531dff61ff664db Mon Sep 17 00:00:00 2001 From: Volodya Petrov <89377379140@mail.ru> Date: Fri, 20 May 2022 01:51:16 +0300 Subject: [PATCH 20/20] added lecture in course for tests courseMentorOnly. Added test for acceptStudent acceptMentor, rejectStudent for courseMentorOnly --- .../CourseServiceTests.cs | 110 +++++++++++++++++- 1 file changed, 109 insertions(+), 1 deletion(-) diff --git a/HwProj.CoursesService/CourseService.IntegrationTests/CourseServiceTests.cs b/HwProj.CoursesService/CourseService.IntegrationTests/CourseServiceTests.cs index 8c4fc8ad2..fa55cc675 100644 --- a/HwProj.CoursesService/CourseService.IntegrationTests/CourseServiceTests.cs +++ b/HwProj.CoursesService/CourseService.IntegrationTests/CourseServiceTests.cs @@ -402,23 +402,28 @@ public async Task TestUpdateCourseOnlyForCourseMentor() var (studentInCourseId, _) = await CreateAndRegisterUser(); var (anotherLectureId, _) = await CreateAndRegisterLecture(); var (anotherStudentId, _) = await CreateAndRegisterUser(); + var (anotherLectureInCourseId, anotherLectureInCourseEmail) = await CreateAndRegisterLecture(); var newCourseViewModel = GenerateCreateCourseViewModel(); var updateViewModel = GenerateUpdateCourseViewModel(); var courseLectureClient = CreateCourseServiceClient(courseLectureId); var studentInCourseClient = CreateCourseServiceClient(studentInCourseId); var anotherLectureClient = CreateCourseServiceClient(anotherLectureId); var anotherStudentClient = CreateCourseServiceClient(anotherStudentId); + var anotherLectureInCourseClient = CreateCourseServiceClient(anotherLectureInCourseId); var courseId = await courseLectureClient.CreateCourse(newCourseViewModel, courseLectureId); await studentInCourseClient.SignInCourse(courseId, studentInCourseId); await courseLectureClient.AcceptStudent(courseId, studentInCourseId); + await courseLectureClient.AcceptLecturer(courseId, anotherLectureInCourseEmail); // Act var responseForStudentInCourse = await studentInCourseClient.UpdateCourse(updateViewModel, courseId); var responseForAnotherStudent = await anotherStudentClient.UpdateCourse(updateViewModel, courseId); var responseForAnotherLecture = await anotherLectureClient.UpdateCourse(updateViewModel, courseId); + var responseForAnotherLectureInCourse = await anotherLectureInCourseClient.UpdateCourse(updateViewModel, courseId); // Assert responseForAnotherLecture.Succeeded.Should().BeFalse(); responseForAnotherStudent.Succeeded.Should().BeFalse(); responseForStudentInCourse.Succeeded.Should().BeFalse(); + responseForAnotherLectureInCourse.Succeeded.Should().BeTrue(); } [Test] @@ -429,22 +434,27 @@ public async Task TestDeleteCourseOnlyForCourseMentor() var (studentInCourseId, _) = await CreateAndRegisterUser(); var (anotherLectureId, _) = await CreateAndRegisterLecture(); var (anotherStudentId, _) = await CreateAndRegisterUser(); + var (anotherLectureInCourseId, anotherLectureInCourseEmail) = await CreateAndRegisterLecture(); var newCourseViewModel = GenerateCreateCourseViewModel(); var courseLectureClient = CreateCourseServiceClient(courseLectureId); var studentInCourseClient = CreateCourseServiceClient(studentInCourseId); var anotherLectureClient = CreateCourseServiceClient(anotherLectureId); var anotherStudentClient = CreateCourseServiceClient(anotherStudentId); + var anotherLectureInCourseClient = CreateCourseServiceClient(anotherLectureInCourseId); var courseId = await courseLectureClient.CreateCourse(newCourseViewModel, courseLectureId); await studentInCourseClient.SignInCourse(courseId, studentInCourseId); await courseLectureClient.AcceptStudent(courseId, studentInCourseId); + await courseLectureClient.AcceptLecturer(courseId, anotherLectureInCourseEmail); // Act var responseForStudentInCourse = await studentInCourseClient.DeleteCourse(courseId); var responseForAnotherStudent = await anotherStudentClient.DeleteCourse(courseId); var responseForAnotherLecture = await anotherLectureClient.DeleteCourse(courseId); + var responseForAnotherLectureInCourse = await anotherLectureInCourseClient.DeleteCourse(courseId); // Assert responseForAnotherLecture.Succeeded.Should().BeFalse(); responseForAnotherStudent.Succeeded.Should().BeFalse(); responseForStudentInCourse.Succeeded.Should().BeFalse(); + responseForAnotherLectureInCourse.Succeeded.Should().BeTrue(); } [Test] @@ -455,24 +465,29 @@ public async Task TestAddHomeworkOnlyForCourseMentor() var (studentInCourseId, _) = await CreateAndRegisterUser(); var (anotherLectureId, _) = await CreateAndRegisterLecture(); var (anotherStudentId, _) = await CreateAndRegisterUser(); + var (anotherLectureInCourseId, anotherLectureInCourseEmail) = await CreateAndRegisterLecture(); var newCourseViewModel = GenerateCreateCourseViewModel(); var newHomeworkViewModel = GenerateCreateHomeworkViewModel(); var courseLectureClient = CreateCourseServiceClient(courseLectureId); var studentInCourseClient = CreateCourseServiceClient(studentInCourseId); var anotherLectureClient = CreateCourseServiceClient(anotherLectureId); var anotherStudentClient = CreateCourseServiceClient(anotherStudentId); + var anotherLectureInCourseClient = CreateCourseServiceClient(anotherLectureInCourseId); var courseId = await courseLectureClient.CreateCourse(newCourseViewModel, courseLectureId); await studentInCourseClient.SignInCourse(courseId, studentInCourseId); await courseLectureClient.AcceptStudent(courseId, studentInCourseId); + await courseLectureClient.AcceptLecturer(courseId, anotherLectureInCourseEmail); // Act var responseForStudentInCourse = await studentInCourseClient.AddHomeworkToCourse(newHomeworkViewModel, courseId); var responseForAnotherStudent = await anotherStudentClient.AddHomeworkToCourse(newHomeworkViewModel, courseId); var responseForAnotherLecture = await anotherLectureClient.AddHomeworkToCourse(newHomeworkViewModel, courseId); + var responseForAnotherLectureInCourse = await anotherLectureInCourseClient.AddHomeworkToCourse(newHomeworkViewModel, courseId); //Assert responseForAnotherLecture.Succeeded.Should().BeFalse(); responseForAnotherStudent.Succeeded.Should().BeFalse(); responseForStudentInCourse.Succeeded.Should().BeFalse(); + responseForAnotherLectureInCourse.Succeeded.Should().BeTrue(); } [Test] @@ -482,6 +497,7 @@ public async Task TestUpdateHomeworkOnlyForCourseMentor() var (studentInCourseId, _) = await CreateAndRegisterUser(); var (anotherLectureId, _) = await CreateAndRegisterLecture(); var (anotherStudentId, _) = await CreateAndRegisterUser(); + var (anotherLectureInCourseId, anotherLectureInCourseEmail) = await CreateAndRegisterLecture(); var newCourseViewModel = GenerateCreateCourseViewModel(); var newHomeworkViewModel = GenerateCreateHomeworkViewModel(); var updateHomeworkViewModel = GenerateCreateHomeworkViewModel(); @@ -489,19 +505,23 @@ public async Task TestUpdateHomeworkOnlyForCourseMentor() var studentInCourseClient = CreateCourseServiceClient(studentInCourseId); var anotherLectureClient = CreateCourseServiceClient(anotherLectureId); var anotherStudentClient = CreateCourseServiceClient(anotherStudentId); + var anotherLectureInCourseClient = CreateCourseServiceClient(anotherLectureInCourseId); var courseId = await courseLectureClient.CreateCourse(newCourseViewModel, courseLectureId); await studentInCourseClient.SignInCourse(courseId, studentInCourseId); await courseLectureClient.AcceptStudent(courseId, studentInCourseId); + await courseLectureClient.AcceptLecturer(courseId, anotherLectureInCourseEmail); var homeworkId = (await courseLectureClient.AddHomeworkToCourse(newHomeworkViewModel, courseId)).Value; // Act var responseForStudentInCourse = await studentInCourseClient.UpdateHomework(updateHomeworkViewModel, homeworkId); var responseForAnotherStudent = await anotherStudentClient.UpdateHomework(updateHomeworkViewModel, homeworkId); var responseForAnotherLecture = await anotherLectureClient.UpdateHomework(updateHomeworkViewModel, homeworkId); + var responseForAnotherLectureInCourse = await anotherLectureInCourseClient.UpdateHomework(updateHomeworkViewModel, homeworkId); //Assert responseForAnotherLecture.Succeeded.Should().BeFalse(); responseForAnotherStudent.Succeeded.Should().BeFalse(); responseForStudentInCourse.Succeeded.Should().BeFalse(); + responseForAnotherLectureInCourse.Succeeded.Should().BeTrue(); } [Test] @@ -512,25 +532,30 @@ public async Task TestDeleteHomeworkOnlyForCourseMentor() var (studentInCourseId, _) = await CreateAndRegisterUser(); var (anotherLectureId, _) = await CreateAndRegisterLecture(); var (anotherStudentId, _) = await CreateAndRegisterUser(); + var (anotherLectureInCourseId, anotherLectureInCourseEmail) = await CreateAndRegisterLecture(); var newCourseViewModel = GenerateCreateCourseViewModel(); var newHomeworkViewModel = GenerateCreateHomeworkViewModel(); var courseLectureClient = CreateCourseServiceClient(courseLectureId); var studentInCourseClient = CreateCourseServiceClient(studentInCourseId); var anotherLectureClient = CreateCourseServiceClient(anotherLectureId); var anotherStudentClient = CreateCourseServiceClient(anotherStudentId); + var anotherLectureInCourseClient = CreateCourseServiceClient(anotherLectureInCourseId); var courseId = await courseLectureClient.CreateCourse(newCourseViewModel, courseLectureId); await studentInCourseClient.SignInCourse(courseId, studentInCourseId); await courseLectureClient.AcceptStudent(courseId, studentInCourseId); + await courseLectureClient.AcceptLecturer(courseId, anotherLectureInCourseEmail); var homeworkId = (await courseLectureClient.AddHomeworkToCourse(newHomeworkViewModel, courseId)).Value; // Act var responseForStudentInCourse = await studentInCourseClient.DeleteHomework(homeworkId); var responseForAnotherStudent = await anotherStudentClient.DeleteHomework(homeworkId); var responseForAnotherLecture = await anotherLectureClient.DeleteHomework(homeworkId); + var responseForAnotherLectureInCourse = await anotherLectureInCourseClient.DeleteHomework(homeworkId); //Assert responseForAnotherLecture.Succeeded.Should().BeFalse(); responseForAnotherStudent.Succeeded.Should().BeFalse(); responseForStudentInCourse.Succeeded.Should().BeFalse(); + responseForAnotherLectureInCourse.Succeeded.Should().BeTrue(); } [Test] @@ -541,6 +566,7 @@ public async Task TestAddTaskForCourseMentorOnly() var (studentInCourseId, _) = await CreateAndRegisterUser(); var (anotherLectureId, _) = await CreateAndRegisterLecture(); var (anotherStudentId, _) = await CreateAndRegisterUser(); + var (anotherLectureInCourseId, anotherLectureInCourseEmail) = await CreateAndRegisterLecture(); var newCourseViewModel = GenerateCreateCourseViewModel(); var newHomeworkViewModel = GenerateCreateHomeworkViewModel(); var newTaskViewModel = GenerateCreateTaskViewModel(); @@ -548,18 +574,22 @@ public async Task TestAddTaskForCourseMentorOnly() var studentInCourseClient = CreateCourseServiceClient(studentInCourseId); var anotherLectureClient = CreateCourseServiceClient(anotherLectureId); var anotherStudentClient = CreateCourseServiceClient(anotherStudentId); + var anotherLectureInCourseClient = CreateCourseServiceClient(anotherLectureInCourseId); var courseId = await courseLectureClient.CreateCourse(newCourseViewModel, courseLectureId); await studentInCourseClient.SignInCourse(courseId, studentInCourseId); await courseLectureClient.AcceptStudent(courseId, studentInCourseId); + await courseLectureClient.AcceptLecturer(courseId, anotherLectureInCourseEmail); var homeworkId = (await courseLectureClient.AddHomeworkToCourse(newHomeworkViewModel, courseId)).Value; // Act var responseForStudentInCourse = await studentInCourseClient.AddTask(newTaskViewModel, homeworkId); var responseForAnotherStudent = await anotherStudentClient.AddTask(newTaskViewModel, homeworkId); var responseForAnotherLecture = await anotherLectureClient.AddTask(newTaskViewModel, homeworkId); + var responseForAnotherLectureInCourse = await anotherLectureInCourseClient.AddTask(newTaskViewModel, homeworkId); //Assert responseForAnotherLecture.Succeeded.Should().BeFalse(); responseForAnotherStudent.Succeeded.Should().BeFalse(); responseForStudentInCourse.Succeeded.Should().BeFalse(); + responseForAnotherLectureInCourse.Succeeded.Should().BeTrue(); } [Test] @@ -570,6 +600,7 @@ public async Task TestUpdateTaskForCourseMentorOnly() var (studentInCourseId, _) = await CreateAndRegisterUser(); var (anotherLectureId, _) = await CreateAndRegisterLecture(); var (anotherStudentId, _) = await CreateAndRegisterUser(); + var (anotherLectureInCourseId, anotherLectureInCourseEmail) = await CreateAndRegisterLecture(); var newCourseViewModel = GenerateCreateCourseViewModel(); var newHomeworkViewModel = GenerateCreateHomeworkViewModel(); var newTaskViewModel = GenerateCreateTaskViewModel(); @@ -578,19 +609,23 @@ public async Task TestUpdateTaskForCourseMentorOnly() var studentInCourseClient = CreateCourseServiceClient(studentInCourseId); var anotherLectureClient = CreateCourseServiceClient(anotherLectureId); var anotherStudentClient = CreateCourseServiceClient(anotherStudentId); + var anotherLectureInCourseClient = CreateCourseServiceClient(anotherLectureInCourseId); var courseId = await courseLectureClient.CreateCourse(newCourseViewModel, courseLectureId); await studentInCourseClient.SignInCourse(courseId, studentInCourseId); await courseLectureClient.AcceptStudent(courseId, studentInCourseId); + await courseLectureClient.AcceptLecturer(courseId, anotherLectureInCourseEmail); var homeworkId = (await courseLectureClient.AddHomeworkToCourse(newHomeworkViewModel, courseId)).Value; var taskId = (await courseLectureClient.AddTask(newTaskViewModel, homeworkId)).Value; // Act var responseForStudentInCourse = await studentInCourseClient.UpdateTask(updateTaskViewModel, taskId); var responseForAnotherStudent = await anotherStudentClient.UpdateTask(updateTaskViewModel, taskId); var responseForAnotherLecture = await anotherLectureClient.UpdateTask(updateTaskViewModel, taskId); + var responseForAnotherLectureInCourse = await anotherLectureInCourseClient.UpdateTask(updateTaskViewModel, taskId); //Assert responseForAnotherLecture.Succeeded.Should().BeFalse(); responseForAnotherStudent.Succeeded.Should().BeFalse(); responseForStudentInCourse.Succeeded.Should().BeFalse(); + responseForAnotherLectureInCourse.Succeeded.Should().BeTrue(); } [Test] @@ -601,6 +636,7 @@ public async Task TestDeleteTaskForCourseMentorOnly() var (studentInCourseId, _) = await CreateAndRegisterUser(); var (anotherLectureId, _) = await CreateAndRegisterLecture(); var (anotherStudentId, _) = await CreateAndRegisterUser(); + var (anotherLectureInCourseId, anotherLectureInCourseEmail) = await CreateAndRegisterLecture(); var newCourseViewModel = GenerateCreateCourseViewModel(); var newHomeworkViewModel = GenerateCreateHomeworkViewModel(); var newTaskViewModel = GenerateCreateTaskViewModel(); @@ -608,46 +644,118 @@ public async Task TestDeleteTaskForCourseMentorOnly() var studentInCourseClient = CreateCourseServiceClient(studentInCourseId); var anotherLectureClient = CreateCourseServiceClient(anotherLectureId); var anotherStudentClient = CreateCourseServiceClient(anotherStudentId); + var anotherLectureInCourseClient = CreateCourseServiceClient(anotherLectureInCourseId); var courseId = await courseLectureClient.CreateCourse(newCourseViewModel, courseLectureId); await studentInCourseClient.SignInCourse(courseId, studentInCourseId); await courseLectureClient.AcceptStudent(courseId, studentInCourseId); + await courseLectureClient.AcceptLecturer(courseId, anotherLectureInCourseEmail); var homeworkId = (await courseLectureClient.AddHomeworkToCourse(newHomeworkViewModel, courseId)).Value; var taskId = (await courseLectureClient.AddTask(newTaskViewModel, homeworkId)).Value; // Act var responseForStudentInCourse = await studentInCourseClient.DeleteTask(taskId); var responseForAnotherStudent = await anotherStudentClient.DeleteTask(taskId); var responseForAnotherLecture = await anotherLectureClient.DeleteTask(taskId); + var responseForAnotherLectureInCourse = await anotherLectureInCourseClient.DeleteTask(taskId); //Assert responseForAnotherLecture.Succeeded.Should().BeFalse(); responseForAnotherStudent.Succeeded.Should().BeFalse(); responseForStudentInCourse.Succeeded.Should().BeFalse(); + responseForAnotherLectureInCourse.Succeeded.Should().BeTrue(); } [Test] public async Task TestAcceptStudentForCourseMentorOnly() { - // Assert + // Arrange var (courseLectureId, _) = await CreateAndRegisterLecture(); var (studentInCourseId, _) = await CreateAndRegisterUser(); var (anotherLectureId, _) = await CreateAndRegisterLecture(); var (anotherStudentId, _) = await CreateAndRegisterUser(); + var (anotherLectureInCourseId, anotherLectureInCourseEmail) = await CreateAndRegisterLecture(); var newCourseViewModel = GenerateCreateCourseViewModel(); var courseLectureClient = CreateCourseServiceClient(courseLectureId); var studentInCourseClient = CreateCourseServiceClient(studentInCourseId); var anotherLectureClient = CreateCourseServiceClient(anotherLectureId); var anotherStudentClient = CreateCourseServiceClient(anotherStudentId); + var anotherLectureInCourseClient = CreateCourseServiceClient(anotherLectureInCourseId); var courseId = await courseLectureClient.CreateCourse(newCourseViewModel, courseLectureId); await studentInCourseClient.SignInCourse(courseId, studentInCourseId); await courseLectureClient.AcceptStudent(courseId, studentInCourseId); + await courseLectureClient.AcceptLecturer(courseId, anotherLectureInCourseEmail); // Act await anotherStudentClient.SignInCourse(courseId, anotherStudentId); var responseForStudentInCourse = await studentInCourseClient.AcceptStudent(courseId, anotherStudentId); var responseForAnotherStudent = await anotherStudentClient.AcceptStudent(courseId, anotherStudentId); var responseForAnotherLecture = await anotherLectureClient.AcceptStudent(courseId, anotherStudentId); + var responseForAnotherLectureInCourse = await anotherLectureInCourseClient.AcceptStudent(courseId, anotherStudentId); + //Assert + responseForAnotherLecture.Succeeded.Should().BeFalse(); + responseForAnotherStudent.Succeeded.Should().BeFalse(); + responseForStudentInCourse.Succeeded.Should().BeFalse(); + responseForAnotherLectureInCourse.Succeeded.Should().BeTrue(); + } + + [Test] + public async Task TestRejectStudentForCourseMentorOnly() + { + // Arrange + var (courseLectureId, _) = await CreateAndRegisterLecture(); + var (studentInCourseId, _) = await CreateAndRegisterUser(); + var (anotherLectureId, _) = await CreateAndRegisterLecture(); + var (anotherStudentId, _) = await CreateAndRegisterUser(); + var (anotherLectureInCourseId, anotherLectureInCourseEmail) = await CreateAndRegisterLecture(); + var newCourseViewModel = GenerateCreateCourseViewModel(); + var courseLectureClient = CreateCourseServiceClient(courseLectureId); + var studentInCourseClient = CreateCourseServiceClient(studentInCourseId); + var anotherLectureClient = CreateCourseServiceClient(anotherLectureId); + var anotherStudentClient = CreateCourseServiceClient(anotherStudentId); + var anotherLectureInCourseClient = CreateCourseServiceClient(anotherLectureInCourseId); + var courseId = await courseLectureClient.CreateCourse(newCourseViewModel, courseLectureId); + await studentInCourseClient.SignInCourse(courseId, studentInCourseId); + await courseLectureClient.AcceptStudent(courseId, studentInCourseId); + await courseLectureClient.AcceptLecturer(courseId, anotherLectureInCourseEmail); + // Act + await anotherStudentClient.SignInCourse(courseId, anotherStudentId); + var responseForStudentInCourse = await studentInCourseClient.RejectStudent(courseId, anotherStudentId); + var responseForAnotherStudent = await anotherStudentClient.RejectStudent(courseId, anotherStudentId); + var responseForAnotherLecture = await anotherLectureClient.RejectStudent(courseId, anotherStudentId); + var responseForAnotherLectureInCourse = await anotherLectureInCourseClient.RejectStudent(courseId, anotherStudentId); + //Assert + responseForAnotherLecture.Succeeded.Should().BeFalse(); + responseForAnotherStudent.Succeeded.Should().BeFalse(); + responseForStudentInCourse.Succeeded.Should().BeFalse(); + responseForAnotherLectureInCourse.Succeeded.Should().BeTrue(); + } + + [Test] + public async Task TestAcceptLectureForCourseMentorOnly() + { + // Arrange + var (courseLectureId, _) = await CreateAndRegisterLecture(); + var (studentInCourseId, _) = await CreateAndRegisterUser(); + var (anotherLectureId, anotherLectureEmail) = await CreateAndRegisterLecture(); + var (anotherStudentId, _) = await CreateAndRegisterUser(); + var (anotherLectureInCourseId, anotherLectureInCourseEmail) = await CreateAndRegisterLecture(); + var newCourseViewModel = GenerateCreateCourseViewModel(); + var courseLectureClient = CreateCourseServiceClient(courseLectureId); + var studentInCourseClient = CreateCourseServiceClient(studentInCourseId); + var anotherLectureClient = CreateCourseServiceClient(anotherLectureId); + var anotherStudentClient = CreateCourseServiceClient(anotherStudentId); + var anotherLectureInCourseClient = CreateCourseServiceClient(anotherLectureInCourseId); + var courseId = await courseLectureClient.CreateCourse(newCourseViewModel, courseLectureId); + await studentInCourseClient.SignInCourse(courseId, studentInCourseId); + await courseLectureClient.AcceptStudent(courseId, studentInCourseId); + await courseLectureClient.AcceptLecturer(courseId, anotherLectureInCourseEmail); + // Act + var responseForStudentInCourse = await studentInCourseClient.AcceptLecturer(courseId, anotherLectureEmail); + var responseForAnotherStudent = await anotherStudentClient.AcceptLecturer(courseId, anotherLectureEmail); + var responseForAnotherLecture = await anotherLectureClient.AcceptLecturer(courseId, anotherLectureEmail); + var responseForAnotherLectureInCourse = await anotherLectureInCourseClient.AcceptLecturer(courseId, anotherLectureEmail); //Assert responseForAnotherLecture.Succeeded.Should().BeFalse(); responseForAnotherStudent.Succeeded.Should().BeFalse(); responseForStudentInCourse.Succeeded.Should().BeFalse(); + responseForAnotherLectureInCourse.Succeeded.Should().BeTrue(); } } } \ No newline at end of file