From 58facce433092cc0b4e39496b309ff379cd9b82d Mon Sep 17 00:00:00 2001 From: MikePuzanov Date: Fri, 13 May 2022 17:55:19 +0300 Subject: [PATCH 1/8] init and add tests --- ...tificationsService.IntegrationTests.csproj | 25 ++++ .../NotificationsServiceTests.cs | 129 ++++++++++++++++++ .../HwProj.NotificationsService.Tests.csproj | 16 --- .../NotificationsServiceTests.cs | 14 -- HwProj.sln | 2 +- 5 files changed, 155 insertions(+), 31 deletions(-) create mode 100644 HwProj.NotificationsService/HwProj.NotificationsService.IntegrationTests/HwProj.NotificationsService.IntegrationTests.csproj create mode 100644 HwProj.NotificationsService/HwProj.NotificationsService.IntegrationTests/NotificationsServiceTests.cs delete mode 100644 HwProj.NotificationsService/HwProj.NotificationsService.Tests/HwProj.NotificationsService.Tests.csproj delete mode 100644 HwProj.NotificationsService/HwProj.NotificationsService.Tests/NotificationsServiceTests.cs diff --git a/HwProj.NotificationsService/HwProj.NotificationsService.IntegrationTests/HwProj.NotificationsService.IntegrationTests.csproj b/HwProj.NotificationsService/HwProj.NotificationsService.IntegrationTests/HwProj.NotificationsService.IntegrationTests.csproj new file mode 100644 index 000000000..be9d49654 --- /dev/null +++ b/HwProj.NotificationsService/HwProj.NotificationsService.IntegrationTests/HwProj.NotificationsService.IntegrationTests.csproj @@ -0,0 +1,25 @@ + + + + netcoreapp2.2 + + false + + + + + + + + + + + + + + + + + + + diff --git a/HwProj.NotificationsService/HwProj.NotificationsService.IntegrationTests/NotificationsServiceTests.cs b/HwProj.NotificationsService/HwProj.NotificationsService.IntegrationTests/NotificationsServiceTests.cs new file mode 100644 index 000000000..c92d3d70b --- /dev/null +++ b/HwProj.NotificationsService/HwProj.NotificationsService.IntegrationTests/NotificationsServiceTests.cs @@ -0,0 +1,129 @@ +using System; +using System.Net.Http; +using System.Security.Claims; +using System.Threading.Tasks; +using HwProj.AuthService.Client; +using HwProj.Models.AuthService.ViewModels; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Options; +using Moq; +using NUnit.Framework; +using AutoFixture; +using FluentAssertions; +using HwProj.CoursesService.Client; +using HwProj.Models.CoursesService.ViewModels; +using HwProj.Models.NotificationsService; +using HwProj.NotificationsService.Client; +using Microsoft.AspNetCore.Http; + +namespace HwProj.NotificationsService.IntegrationTests +{ + [TestFixture] + public class Tests + { + private AuthServiceClient CreateAuthServiceClient() + { + 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); + } + + private NotificationsServiceClient CreateNotificationsServiceClient() + { + var mockIConfiguration = new Mock(); + mockIConfiguration + .Setup(x => x.GetSection("Services")["Notifications"]) + .Returns("http://localhost:5006"); + var mockClientFactory = new Mock(); + mockClientFactory + .Setup(x => x.CreateClient(Options.DefaultName)) + .Returns(new HttpClient()); + return new NotificationsServiceClient(mockClientFactory.Object, mockIConfiguration.Object); + } + + 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 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 GenerateCreateCourseViewModel() + => new Fixture().Build() + .With(c => c.IsOpen, true).Create(); + + private async Task<(string, string)> CreateAndRegisterUser() + { + var authClient = CreateAuthServiceClient(); + var userData = GenerateRegisterViewModel(); + await authClient.Register(userData); + var userId = await authClient.FindByEmailAsync(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); + } + + + [Test] + public async Task GetNotificationTest() + { + var notificationClient = CreateNotificationsServiceClient(); + + var (studentId, _) = await CreateAndRegisterUser(); + var notification1 = await notificationClient.Get(studentId, new NotificationFilter()); + + notification1.Should().HaveCount(1); + notification1[0].Sender.Should().BeEquivalentTo("AuthService"); + } + + [Test] + public async Task CheckMarkAsSeenTest() + { + var notificationClient = CreateNotificationsServiceClient(); + + var (userId, _) = await CreateAndRegisterUser(); + var notificationBefore = await notificationClient.Get(userId, new NotificationFilter()); + var notificationId = new long[1]{notificationBefore[0].Id}; + await notificationClient.MarkAsSeen(userId, notificationId); + var notificationAfter = await notificationClient.Get(userId, new NotificationFilter()); + + notificationBefore.Should().HaveCount(1); + notificationBefore[0].HasSeen.Should().BeFalse(); + notificationAfter.Should().HaveCount(1); + notificationAfter[0].HasSeen.Should().BeTrue(); + } + } +} \ No newline at end of file diff --git a/HwProj.NotificationsService/HwProj.NotificationsService.Tests/HwProj.NotificationsService.Tests.csproj b/HwProj.NotificationsService/HwProj.NotificationsService.Tests/HwProj.NotificationsService.Tests.csproj deleted file mode 100644 index 6c79a5038..000000000 --- a/HwProj.NotificationsService/HwProj.NotificationsService.Tests/HwProj.NotificationsService.Tests.csproj +++ /dev/null @@ -1,16 +0,0 @@ - - - - netcoreapp2.2 - - false - - - - - - - - - - diff --git a/HwProj.NotificationsService/HwProj.NotificationsService.Tests/NotificationsServiceTests.cs b/HwProj.NotificationsService/HwProj.NotificationsService.Tests/NotificationsServiceTests.cs deleted file mode 100644 index 4f8f579fb..000000000 --- a/HwProj.NotificationsService/HwProj.NotificationsService.Tests/NotificationsServiceTests.cs +++ /dev/null @@ -1,14 +0,0 @@ -using NUnit.Framework; - -namespace HwProj.NotificationsService.Tests -{ - [TestFixture] - public class SolutionsServiceTests - { - [Test] - public void SimpleTest() - { - Assert.AreEqual(1, 1); - } - } -} \ No newline at end of file diff --git a/HwProj.sln b/HwProj.sln index 3961fc3c1..aa48a1438 100644 --- a/HwProj.sln +++ b/HwProj.sln @@ -24,7 +24,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "HwProj.Common", "HwProj.Com EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HwProj.Utils", "HwProj.Common\HwProj.Utils\HwProj.Utils.csproj", "{F584B68E-B6A8-46F1-A692-CB87DE9996BE}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HwProj.NotificationsService.Tests", "HwProj.NotificationsService\HwProj.NotificationsService.Tests\HwProj.NotificationsService.Tests.csproj", "{2B4D695D-1BAA-4BCC-AE5A-C1CDD4ACCCCA}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HwProj.NotificationsService.IntegrationTests", "HwProj.NotificationsService\HwProj.NotificationsService.IntegrationTests\HwProj.NotificationsService.IntegrationTests.csproj", "{2B4D695D-1BAA-4BCC-AE5A-C1CDD4ACCCCA}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "HwProj.AuthService", "HwProj.AuthService", "{D7F8BC73-A6CB-4E07-984D-2D65B740BC69}" EndProject From a005f3883b2980f77a1a58aa7ce340c0825b3fa0 Mon Sep 17 00:00:00 2001 From: MikePuzanov Date: Fri, 13 May 2022 18:23:11 +0300 Subject: [PATCH 2/8] wip --- .../NotificationsServiceTests.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/HwProj.NotificationsService/HwProj.NotificationsService.IntegrationTests/NotificationsServiceTests.cs b/HwProj.NotificationsService/HwProj.NotificationsService.IntegrationTests/NotificationsServiceTests.cs index c92d3d70b..902186c99 100644 --- a/HwProj.NotificationsService/HwProj.NotificationsService.IntegrationTests/NotificationsServiceTests.cs +++ b/HwProj.NotificationsService/HwProj.NotificationsService.IntegrationTests/NotificationsServiceTests.cs @@ -96,7 +96,6 @@ private CreateCourseViewModel GenerateCreateCourseViewModel() return (userId, mail); } - [Test] public async Task GetNotificationTest() { From 4304ffd5d15a8c587604dcdf2fe8ecf5c6b482f3 Mon Sep 17 00:00:00 2001 From: MikePuzanov Date: Fri, 13 May 2022 19:33:46 +0300 Subject: [PATCH 3/8] wip --- .../NotificationsServiceTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/HwProj.NotificationsService/HwProj.NotificationsService.IntegrationTests/NotificationsServiceTests.cs b/HwProj.NotificationsService/HwProj.NotificationsService.IntegrationTests/NotificationsServiceTests.cs index 902186c99..b277f42d3 100644 --- a/HwProj.NotificationsService/HwProj.NotificationsService.IntegrationTests/NotificationsServiceTests.cs +++ b/HwProj.NotificationsService/HwProj.NotificationsService.IntegrationTests/NotificationsServiceTests.cs @@ -102,7 +102,7 @@ public async Task GetNotificationTest() var notificationClient = CreateNotificationsServiceClient(); var (studentId, _) = await CreateAndRegisterUser(); - var notification1 = await notificationClient.Get(studentId, new NotificationFilter()); + var notification1 = await notificationClient.Get(studentId, new NotificationFilter()).Wait(); notification1.Should().HaveCount(1); notification1[0].Sender.Should().BeEquivalentTo("AuthService"); From ada5a21f5fc10652535ed2cf5f4df2c00fbc889c Mon Sep 17 00:00:00 2001 From: MikePuzanov Date: Fri, 13 May 2022 20:55:17 +0300 Subject: [PATCH 4/8] not find waitUntil --- .../NotificationsServiceTests.cs | 29 +++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/HwProj.NotificationsService/HwProj.NotificationsService.IntegrationTests/NotificationsServiceTests.cs b/HwProj.NotificationsService/HwProj.NotificationsService.IntegrationTests/NotificationsServiceTests.cs index b277f42d3..98dff30b9 100644 --- a/HwProj.NotificationsService/HwProj.NotificationsService.IntegrationTests/NotificationsServiceTests.cs +++ b/HwProj.NotificationsService/HwProj.NotificationsService.IntegrationTests/NotificationsServiceTests.cs @@ -102,12 +102,37 @@ public async Task GetNotificationTest() var notificationClient = CreateNotificationsServiceClient(); var (studentId, _) = await CreateAndRegisterUser(); - var notification1 = await notificationClient.Get(studentId, new NotificationFilter()).Wait(); - + var notification1 = await notificationClient.Get(studentId, new NotificationFilter()); + notification1.Should().HaveCount(1); notification1[0].Sender.Should().BeEquivalentTo("AuthService"); } + [Test] + public async Task GetMoreThanOneNotificationsTest() + { + var notificationClient = CreateNotificationsServiceClient(); + + var (studentId, _) = await CreateAndRegisterUser(); + var (lectureId, _) = await CreateAndRegisterLecture(); + var notificationAfterAcceptUser = await notificationClient.Get(studentId, new NotificationFilter()); + var studentCourseClient = CreateCourseServiceClient(studentId); + var lectureCourseClient = CreateCourseServiceClient(lectureId); + var course = GenerateCreateCourseViewModel(); + var courseId = await lectureCourseClient.CreateCourse(course, lectureId); + await studentCourseClient.SignInCourse(courseId, studentId); + await lectureCourseClient.AcceptStudent(courseId, studentId); + + var notificationBeforeAcceptUser = await notificationClient.Get(studentId, new NotificationFilter()); + while (notificationBeforeAcceptUser.Length != 2) + { + notificationBeforeAcceptUser = await notificationClient.Get(studentId, new NotificationFilter()); + } + + notificationAfterAcceptUser.Should().HaveCount(1); + notificationBeforeAcceptUser.Should().HaveCount(2); + } + [Test] public async Task CheckMarkAsSeenTest() { From 206b6bf0746fcf3e0307c182a0f14634a6571f81 Mon Sep 17 00:00:00 2001 From: MikePuzanov Date: Thu, 19 May 2022 01:42:57 +0300 Subject: [PATCH 5/8] add tests --- ...tificationsService.IntegrationTests.csproj | 1 + .../NotificationsServiceTests.cs | 250 +++++++++++++++++- 2 files changed, 249 insertions(+), 2 deletions(-) diff --git a/HwProj.NotificationsService/HwProj.NotificationsService.IntegrationTests/HwProj.NotificationsService.IntegrationTests.csproj b/HwProj.NotificationsService/HwProj.NotificationsService.IntegrationTests/HwProj.NotificationsService.IntegrationTests.csproj index be9d49654..ba4539226 100644 --- a/HwProj.NotificationsService/HwProj.NotificationsService.IntegrationTests/HwProj.NotificationsService.IntegrationTests.csproj +++ b/HwProj.NotificationsService/HwProj.NotificationsService.IntegrationTests/HwProj.NotificationsService.IntegrationTests.csproj @@ -19,6 +19,7 @@ + diff --git a/HwProj.NotificationsService/HwProj.NotificationsService.IntegrationTests/NotificationsServiceTests.cs b/HwProj.NotificationsService/HwProj.NotificationsService.IntegrationTests/NotificationsServiceTests.cs index 98dff30b9..e3edf1ca8 100644 --- a/HwProj.NotificationsService/HwProj.NotificationsService.IntegrationTests/NotificationsServiceTests.cs +++ b/HwProj.NotificationsService/HwProj.NotificationsService.IntegrationTests/NotificationsServiceTests.cs @@ -1,6 +1,8 @@ using System; +using System.Collections.Generic; using System.Net.Http; using System.Security.Claims; +using System.Threading; using System.Threading.Tasks; using HwProj.AuthService.Client; using HwProj.Models.AuthService.ViewModels; @@ -13,7 +15,9 @@ using HwProj.CoursesService.Client; using HwProj.Models.CoursesService.ViewModels; using HwProj.Models.NotificationsService; +using HwProj.Models.SolutionsService; using HwProj.NotificationsService.Client; +using HwProj.SolutionsService.Client; using Microsoft.AspNetCore.Http; namespace HwProj.NotificationsService.IntegrationTests @@ -65,6 +69,19 @@ private CoursesServiceClient CreateCourseServiceClient(string userId) mockIConfiguration.Object); } + private SolutionsServiceClient CreateSolutionsServiceClient() + { + var mockIConfiguration = new Mock(); + mockIConfiguration + .Setup(x => x.GetSection("Services")["Solutions"]) + .Returns("http://localhost:5007"); + var mockClientFactory = new Mock(); + mockClientFactory + .Setup(x => x.CreateClient(Options.DefaultName)) + .Returns(new HttpClient()); + return new SolutionsServiceClient(mockClientFactory.Object, mockIConfiguration.Object); + } + private RegisterViewModel GenerateRegisterViewModel() { var password = new Fixture().Create(); @@ -79,6 +96,22 @@ private RegisterViewModel GenerateRegisterViewModel() private CreateCourseViewModel GenerateCreateCourseViewModel() => new Fixture().Build() .With(c => c.IsOpen, true).Create(); + + private CreateHomeworkViewModel GenerateCreateHomeworkViewModel() + => new Fixture().Build() + .With(h => h.Tasks, new List()) + .Create(); + + private CreateTaskViewModel GenerateCreateTaskViewModel() + => new Fixture().Build() + .With(t => t.HasDeadline, false) + .With(t => t.IsDeadlineStrict, false) + .Create(); + + private SolutionViewModel GenerateSolutionViewModel(string studentId) + => new Fixture().Build() + .With(s => s.StudentId, studentId) + .Create(); private async Task<(string, string)> CreateAndRegisterUser() { @@ -88,7 +121,7 @@ private CreateCourseViewModel GenerateCreateCourseViewModel() var userId = await authClient.FindByEmailAsync(userData.Email); return (userId, userData.Email); } - private async Task<(string, string)> CreateAndRegisterLecture() + private async Task<(string, string)> CreateAndRegisterLecture() { var (userId, mail) = await CreateAndRegisterUser(); var authClient = CreateAuthServiceClient(); @@ -97,7 +130,7 @@ private CreateCourseViewModel GenerateCreateCourseViewModel() } [Test] - public async Task GetNotificationTest() + public async Task NotificationRegisterTest() { var notificationClient = CreateNotificationsServiceClient(); @@ -132,7 +165,220 @@ public async Task GetMoreThanOneNotificationsTest() notificationAfterAcceptUser.Should().HaveCount(1); notificationBeforeAcceptUser.Should().HaveCount(2); } + + [Test] + public async Task NotificationAcceptLectureTest() + { + var (lectureId1, _) = await CreateAndRegisterLecture(); + var (lectureId2, lectureEmail2) = await CreateAndRegisterLecture(); + var lecture1CourseClient = CreateCourseServiceClient(lectureId1); + var course = GenerateCreateCourseViewModel(); + var courseId = await lecture1CourseClient.CreateCourse(course, lectureId1); + await lecture1CourseClient.AcceptLecturer(courseId, lectureEmail2); + + Thread.Sleep(5000); + var notificationClient = CreateNotificationsServiceClient(); + var notification = await notificationClient.Get(lectureId2, new NotificationFilter()); + + notification.Should().Contain(n => n.Sender == "AuthService"); + } + + [Test] + public async Task NotificationLectureAcceptOrRejectStudentTest() + { + var (lectureId1, _) = await CreateAndRegisterLecture(); + var (lectureId2, lectureEmail2) = await CreateAndRegisterLecture(); + var lecture1CourseClient = CreateCourseServiceClient(lectureId1); + var course = GenerateCreateCourseViewModel(); + var courseId = await lecture1CourseClient.CreateCourse(course, lectureId1); + await lecture1CourseClient.AcceptLecturer(courseId, lectureEmail2); + + Thread.Sleep(5000); + var notificationClient = CreateNotificationsServiceClient(); + var notification = await notificationClient.Get(lectureId2, new NotificationFilter()); + + notification.Should().Contain(n => n.Sender == "AuthService"); + } + + [Test] + public async Task NotificationNewCourseMateTest() + { + var (studentId, _) = await CreateAndRegisterUser(); + var (lectureId, _) = await CreateAndRegisterLecture(); + var (lectureId2, lectureEmail2) = await CreateAndRegisterLecture(); + var lectureCourseClient = CreateCourseServiceClient(lectureId); + var studentCourseClient = CreateCourseServiceClient(studentId); + var course = GenerateCreateCourseViewModel(); + var courseId = await lectureCourseClient.CreateCourse(course, lectureId); + await lectureCourseClient.AcceptLecturer(courseId, lectureEmail2); + await studentCourseClient.SignInCourse(courseId, studentId); + + Thread.Sleep(5000); + var notificationClient = CreateNotificationsServiceClient(); + var notificationLecture = await notificationClient.Get(lectureId, new NotificationFilter()); + var notificationLecture2 = await notificationClient.Get(lectureId2, new NotificationFilter()); + + notificationLecture.Should().Contain(n => n.Sender == "CourseService"); + notificationLecture2.Should().Contain(n => n.Sender == "CourseService"); + } + + [Test] + public async Task NotificationNewHomeworkTest() + { + var (studentId, _) = await CreateAndRegisterUser(); + var (studentId1, _) = await CreateAndRegisterUser(); + var (lectureId, _) = await CreateAndRegisterLecture(); + var lectureCourseClient = CreateCourseServiceClient(lectureId); + var studentCourseClient = CreateCourseServiceClient(studentId); + var student1CourseClient = CreateCourseServiceClient(studentId1); + var course = GenerateCreateCourseViewModel(); + var courseId = await lectureCourseClient.CreateCourse(course, lectureId); + await studentCourseClient.SignInCourse(courseId, studentId); + await lectureCourseClient.AcceptStudent(courseId, studentId); + await student1CourseClient.SignInCourse(courseId, studentId1); + await lectureCourseClient.AcceptStudent(courseId, studentId1); + var hwCreateViewModel = GenerateCreateHomeworkViewModel(); + var taskCreateViewModel = GenerateCreateTaskViewModel(); + var homeworkId = await lectureCourseClient.AddHomeworkToCourse(hwCreateViewModel, courseId); + var taskId = await lectureCourseClient.AddTask(taskCreateViewModel, homeworkId); + + Thread.Sleep(5000); + var notificationClient = CreateNotificationsServiceClient(); + var notificationStudent = await notificationClient.Get(studentId, new NotificationFilter()); + var notificationStudent1 = await notificationClient.Get(studentId1, new NotificationFilter()); + + notificationStudent.Should().Contain(n => n.Sender == "CourseService"); + notificationStudent1.Should().Contain(n => n.Sender == "CourseService"); + } + + [Test] + public async Task NotificationUpdateHomeworkTest() + { + var (studentId, _) = await CreateAndRegisterUser(); + var (studentId1, _) = await CreateAndRegisterUser(); + var (lectureId, _) = await CreateAndRegisterLecture(); + var lectureCourseClient = CreateCourseServiceClient(lectureId); + var studentCourseClient = CreateCourseServiceClient(studentId); + var student1CourseClient = CreateCourseServiceClient(studentId1); + var course = GenerateCreateCourseViewModel(); + var courseId = await lectureCourseClient.CreateCourse(course, lectureId); + await studentCourseClient.SignInCourse(courseId, studentId); + await lectureCourseClient.AcceptStudent(courseId, studentId); + await student1CourseClient.SignInCourse(courseId, studentId1); + await lectureCourseClient.AcceptStudent(courseId, studentId1); + + var hwCreateViewModel = GenerateCreateHomeworkViewModel(); + var taskCreateViewModel = GenerateCreateTaskViewModel(); + var homeworkId = await lectureCourseClient.AddHomeworkToCourse(hwCreateViewModel, courseId); + hwCreateViewModel.Description = "Update"; + await lectureCourseClient.UpdateHomework(hwCreateViewModel, homeworkId); + var taskId = await lectureCourseClient.AddTask(taskCreateViewModel, homeworkId); + + Thread.Sleep(5000); + var notificationClient = CreateNotificationsServiceClient(); + var notificationStudent = await notificationClient.Get(studentId, new NotificationFilter()); + var notificationStudent1 = await notificationClient.Get(studentId1, new NotificationFilter()); + + var notificationBody = $"В курсе {course.Name} домашнее задание {hwCreateViewModel.Title} обновлено."; + + notificationStudent.Should().Contain(n => n.Body == notificationBody); + notificationStudent1.Should().Contain(n => n.Body == notificationBody); + } + + [Test] + public async Task NotificationUpdateTaskMaxRatingTest() + { + var (studentId, _) = await CreateAndRegisterUser(); + var (studentId1, _) = await CreateAndRegisterUser(); + var (lectureId, _) = await CreateAndRegisterLecture(); + var lectureCourseClient = CreateCourseServiceClient(lectureId); + var studentCourseClient = CreateCourseServiceClient(studentId); + var student1CourseClient = CreateCourseServiceClient(studentId1); + var course = GenerateCreateCourseViewModel(); + var courseId = await lectureCourseClient.CreateCourse(course, lectureId); + await studentCourseClient.SignInCourse(courseId, studentId); + await lectureCourseClient.AcceptStudent(courseId, studentId); + await student1CourseClient.SignInCourse(courseId, studentId1); + await lectureCourseClient.AcceptStudent(courseId, studentId1); + + var hwCreateViewModel = GenerateCreateHomeworkViewModel(); + var taskCreateViewModel = GenerateCreateTaskViewModel(); + var homeworkId = await lectureCourseClient.AddHomeworkToCourse(hwCreateViewModel, courseId); + var taskId = await lectureCourseClient.AddTask(taskCreateViewModel, homeworkId); + taskCreateViewModel.Description = "Update"; + await lectureCourseClient.UpdateTask(taskCreateViewModel, taskId); + + Thread.Sleep(5000); + var notificationClient = CreateNotificationsServiceClient(); + var notificationStudent = await notificationClient.Get(studentId, new NotificationFilter()); + var notificationStudent1 = await notificationClient.Get(studentId1, new NotificationFilter()); + + var notificationBody = $"Задача обновлена."; + + notificationStudent.Should().Contain(n => n.Body == notificationBody); + notificationStudent1.Should().Contain(n => n.Body == notificationBody); + } + + [Test] + public async Task NotificationStudentPassTaskTest() + { + var (studentId, _) = await CreateAndRegisterUser(); + var (lectureId, _) = await CreateAndRegisterLecture(); + var (lectureId2, lectureEmail2) = await CreateAndRegisterLecture(); + var lectureCourseClient = CreateCourseServiceClient(lectureId); + var studentCourseClient = CreateCourseServiceClient(studentId); + var course = GenerateCreateCourseViewModel(); + var courseId = await lectureCourseClient.CreateCourse(course, lectureId); + await lectureCourseClient.AcceptLecturer(courseId, lectureEmail2); + await studentCourseClient.SignInCourse(courseId, studentId); + await lectureCourseClient.AcceptStudent(courseId, studentId); + + var hwCreateViewModel = GenerateCreateHomeworkViewModel(); + var taskCreateViewModel = GenerateCreateTaskViewModel(); + var homeworkId = await lectureCourseClient.AddHomeworkToCourse(hwCreateViewModel, courseId); + var taskId = await lectureCourseClient.AddTask(taskCreateViewModel, homeworkId); + var solutionViewModel = GenerateSolutionViewModel(studentId); + var solutionServiceClient = CreateSolutionsServiceClient(); + var solutionId = await solutionServiceClient.PostSolution(solutionViewModel, taskId); + + Thread.Sleep(5000); + var notificationClient = CreateNotificationsServiceClient(); + var notificationLecture = await notificationClient.Get(lectureId, new NotificationFilter()); + var notificationLecture2 = await notificationClient.Get(lectureId2, new NotificationFilter()); + + notificationLecture.Should().Contain(n => n.Sender == "SolutionService"); + notificationLecture2.Should().Contain(n => n.Sender == "SolutionService"); + } + + [Test] + public async Task NotificationRateTest() + { + var (studentId, _) = await CreateAndRegisterUser(); + var (lectureId, _) = await CreateAndRegisterLecture(); + var lectureCourseClient = CreateCourseServiceClient(lectureId); + var studentCourseClient = CreateCourseServiceClient(studentId); + var course = GenerateCreateCourseViewModel(); + var courseId = await lectureCourseClient.CreateCourse(course, lectureId); + await studentCourseClient.SignInCourse(courseId, studentId); + await lectureCourseClient.AcceptStudent(courseId, studentId); + + var hwCreateViewModel = GenerateCreateHomeworkViewModel(); + var taskCreateViewModel = GenerateCreateTaskViewModel(); + var homeworkId = await lectureCourseClient.AddHomeworkToCourse(hwCreateViewModel, courseId); + var taskId = await lectureCourseClient.AddTask(taskCreateViewModel, homeworkId); + var solutionViewModel = GenerateSolutionViewModel(studentId); + var solutionServiceClient = CreateSolutionsServiceClient(); + var solutionId = await solutionServiceClient.PostSolution(solutionViewModel, taskId); + await solutionServiceClient.RateSolution(solutionId, 3, "", lectureId); + + Thread.Sleep(5000); + var notificationClient = CreateNotificationsServiceClient(); + var notificationLecture = await notificationClient.Get(studentId, new NotificationFilter()); + + notificationLecture.Should().Contain(n => n.Sender == "SolutionService"); + } + [Test] public async Task CheckMarkAsSeenTest() { From 31ffa387f69fa9f9d209093d74909b9ecc71e5ad Mon Sep 17 00:00:00 2001 From: MikePuzanov Date: Sun, 5 Jun 2022 20:23:01 +0300 Subject: [PATCH 6/8] fix conflict --- ...NotificationsService.IntegrationTests.csproj | 15 +++++++++------ ...=> NotificationsService.IntegrationTests.cs} | 17 +++++++++-------- .../NotificationsServiceTests.cs | 14 ++++++++++++++ HwProj.sln | 9 ++++++++- 4 files changed, 40 insertions(+), 15 deletions(-) rename HwProj.NotificationsService/HwProj.NotificationsService.IntegrationTests/{NotificationsServiceTests.cs => NotificationsService.IntegrationTests.cs} (99%) create mode 100644 HwProj.NotificationsService/HwProj.NotificationsService.Tests/NotificationsServiceTests.cs diff --git a/HwProj.NotificationsService/HwProj.NotificationsService.IntegrationTests/HwProj.NotificationsService.IntegrationTests.csproj b/HwProj.NotificationsService/HwProj.NotificationsService.IntegrationTests/HwProj.NotificationsService.IntegrationTests.csproj index ba4539226..9f742092a 100644 --- a/HwProj.NotificationsService/HwProj.NotificationsService.IntegrationTests/HwProj.NotificationsService.IntegrationTests.csproj +++ b/HwProj.NotificationsService/HwProj.NotificationsService.IntegrationTests/HwProj.NotificationsService.IntegrationTests.csproj @@ -1,25 +1,28 @@ - + netcoreapp2.2 + enable false + + latest - - + + - - - + + + diff --git a/HwProj.NotificationsService/HwProj.NotificationsService.IntegrationTests/NotificationsServiceTests.cs b/HwProj.NotificationsService/HwProj.NotificationsService.IntegrationTests/NotificationsService.IntegrationTests.cs similarity index 99% rename from HwProj.NotificationsService/HwProj.NotificationsService.IntegrationTests/NotificationsServiceTests.cs rename to HwProj.NotificationsService/HwProj.NotificationsService.IntegrationTests/NotificationsService.IntegrationTests.cs index e3edf1ca8..696a5211d 100644 --- a/HwProj.NotificationsService/HwProj.NotificationsService.IntegrationTests/NotificationsServiceTests.cs +++ b/HwProj.NotificationsService/HwProj.NotificationsService.IntegrationTests/NotificationsService.IntegrationTests.cs @@ -4,26 +4,27 @@ using System.Security.Claims; using System.Threading; using System.Threading.Tasks; -using HwProj.AuthService.Client; -using HwProj.Models.AuthService.ViewModels; -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.Options; -using Moq; -using NUnit.Framework; using AutoFixture; using FluentAssertions; +using HwProj.AuthService.Client; using HwProj.CoursesService.Client; +using HwProj.Models.AuthService.ViewModels; using HwProj.Models.CoursesService.ViewModels; using HwProj.Models.NotificationsService; using HwProj.Models.SolutionsService; using HwProj.NotificationsService.Client; using HwProj.SolutionsService.Client; using Microsoft.AspNetCore.Http; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Options; +using Moq; +using NUnit.Framework; + namespace HwProj.NotificationsService.IntegrationTests { [TestFixture] - public class Tests + public class NotificationsServiceTests { private AuthServiceClient CreateAuthServiceClient() { @@ -241,7 +242,7 @@ public async Task NotificationNewHomeworkTest() var hwCreateViewModel = GenerateCreateHomeworkViewModel(); var taskCreateViewModel = GenerateCreateTaskViewModel(); var homeworkId = await lectureCourseClient.AddHomeworkToCourse(hwCreateViewModel, courseId); - var taskId = await lectureCourseClient.AddTask(taskCreateViewModel, homeworkId); + await lectureCourseClient.AddTask(taskCreateViewModel, homeworkId); Thread.Sleep(5000); var notificationClient = CreateNotificationsServiceClient(); diff --git a/HwProj.NotificationsService/HwProj.NotificationsService.Tests/NotificationsServiceTests.cs b/HwProj.NotificationsService/HwProj.NotificationsService.Tests/NotificationsServiceTests.cs new file mode 100644 index 000000000..4f8f579fb --- /dev/null +++ b/HwProj.NotificationsService/HwProj.NotificationsService.Tests/NotificationsServiceTests.cs @@ -0,0 +1,14 @@ +using NUnit.Framework; + +namespace HwProj.NotificationsService.Tests +{ + [TestFixture] + public class SolutionsServiceTests + { + [Test] + public void SimpleTest() + { + Assert.AreEqual(1, 1); + } + } +} \ No newline at end of file diff --git a/HwProj.sln b/HwProj.sln index aa48a1438..1b0ee48c2 100644 --- a/HwProj.sln +++ b/HwProj.sln @@ -24,7 +24,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "HwProj.Common", "HwProj.Com EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HwProj.Utils", "HwProj.Common\HwProj.Utils\HwProj.Utils.csproj", "{F584B68E-B6A8-46F1-A692-CB87DE9996BE}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HwProj.NotificationsService.IntegrationTests", "HwProj.NotificationsService\HwProj.NotificationsService.IntegrationTests\HwProj.NotificationsService.IntegrationTests.csproj", "{2B4D695D-1BAA-4BCC-AE5A-C1CDD4ACCCCA}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HwProj.NotificationsService.Tests", "HwProj.NotificationsService\HwProj.NotificationsService.Tests\HwProj.NotificationsService.Tests.csproj", "{2B4D695D-1BAA-4BCC-AE5A-C1CDD4ACCCCA}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "HwProj.AuthService", "HwProj.AuthService", "{D7F8BC73-A6CB-4E07-984D-2D65B740BC69}" EndProject @@ -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}") = "HwProj.NotificationsService.IntegrationTests", "HwProj.NotificationsService\HwProj.NotificationsService.IntegrationTests\HwProj.NotificationsService.IntegrationTests.csproj", "{E6370DC6-B123-4233-B95F-2C505EA47BF5}" +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 + {E6370DC6-B123-4233-B95F-2C505EA47BF5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {E6370DC6-B123-4233-B95F-2C505EA47BF5}.Debug|Any CPU.Build.0 = Debug|Any CPU + {E6370DC6-B123-4233-B95F-2C505EA47BF5}.Release|Any CPU.ActiveCfg = Release|Any CPU + {E6370DC6-B123-4233-B95F-2C505EA47BF5}.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} + {E6370DC6-B123-4233-B95F-2C505EA47BF5} = {1EAEB779-E7C8-4EF9-B9A9-22CB8E3C246D} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {C03BF138-4A5B-4261-9495-6D3AC6CE9779} From cb6fe63d5f2ff6297c284c670fcfa3c92e0b6f4c Mon Sep 17 00:00:00 2001 From: MikePuzanov Date: Sun, 5 Jun 2022 20:24:08 +0300 Subject: [PATCH 7/8] fix --- .../HwProj.NotificationsService.Tests.csproj | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 HwProj.NotificationsService/HwProj.NotificationsService.Tests/HwProj.NotificationsService.Tests.csproj diff --git a/HwProj.NotificationsService/HwProj.NotificationsService.Tests/HwProj.NotificationsService.Tests.csproj b/HwProj.NotificationsService/HwProj.NotificationsService.Tests/HwProj.NotificationsService.Tests.csproj new file mode 100644 index 000000000..ea42cd949 --- /dev/null +++ b/HwProj.NotificationsService/HwProj.NotificationsService.Tests/HwProj.NotificationsService.Tests.csproj @@ -0,0 +1,24 @@ + + + + netcoreapp2.2 + + false + + + + + + + + + + + + + + + + + + From b185525f2ad9d12079f8650685c974d0e2d5bee4 Mon Sep 17 00:00:00 2001 From: MikePuzanov Date: Sun, 5 Jun 2022 21:33:06 +0300 Subject: [PATCH 8/8] fix conflict --- .../NotificationsService.IntegrationTests.cs | 20 +++++++++---------- HwProj.sln | 8 ++++++-- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/HwProj.NotificationsService/HwProj.NotificationsService.IntegrationTests/NotificationsService.IntegrationTests.cs b/HwProj.NotificationsService/HwProj.NotificationsService.IntegrationTests/NotificationsService.IntegrationTests.cs index 696a5211d..86c0a448c 100644 --- a/HwProj.NotificationsService/HwProj.NotificationsService.IntegrationTests/NotificationsService.IntegrationTests.cs +++ b/HwProj.NotificationsService/HwProj.NotificationsService.IntegrationTests/NotificationsService.IntegrationTests.cs @@ -242,7 +242,7 @@ public async Task NotificationNewHomeworkTest() var hwCreateViewModel = GenerateCreateHomeworkViewModel(); var taskCreateViewModel = GenerateCreateTaskViewModel(); var homeworkId = await lectureCourseClient.AddHomeworkToCourse(hwCreateViewModel, courseId); - await lectureCourseClient.AddTask(taskCreateViewModel, homeworkId); + await lectureCourseClient.AddTask(taskCreateViewModel, homeworkId.Value); Thread.Sleep(5000); var notificationClient = CreateNotificationsServiceClient(); @@ -273,8 +273,8 @@ public async Task NotificationUpdateHomeworkTest() var taskCreateViewModel = GenerateCreateTaskViewModel(); var homeworkId = await lectureCourseClient.AddHomeworkToCourse(hwCreateViewModel, courseId); hwCreateViewModel.Description = "Update"; - await lectureCourseClient.UpdateHomework(hwCreateViewModel, homeworkId); - var taskId = await lectureCourseClient.AddTask(taskCreateViewModel, homeworkId); + await lectureCourseClient.UpdateHomework(hwCreateViewModel, homeworkId.Value); + var taskId = await lectureCourseClient.AddTask(taskCreateViewModel, homeworkId.Value); Thread.Sleep(5000); var notificationClient = CreateNotificationsServiceClient(); @@ -306,16 +306,16 @@ public async Task NotificationUpdateTaskMaxRatingTest() var hwCreateViewModel = GenerateCreateHomeworkViewModel(); var taskCreateViewModel = GenerateCreateTaskViewModel(); var homeworkId = await lectureCourseClient.AddHomeworkToCourse(hwCreateViewModel, courseId); - var taskId = await lectureCourseClient.AddTask(taskCreateViewModel, homeworkId); + var taskId = await lectureCourseClient.AddTask(taskCreateViewModel, homeworkId.Value); taskCreateViewModel.Description = "Update"; - await lectureCourseClient.UpdateTask(taskCreateViewModel, taskId); + await lectureCourseClient.UpdateTask(taskCreateViewModel, taskId.Value); Thread.Sleep(5000); var notificationClient = CreateNotificationsServiceClient(); var notificationStudent = await notificationClient.Get(studentId, new NotificationFilter()); var notificationStudent1 = await notificationClient.Get(studentId1, new NotificationFilter()); - var notificationBody = $"Задача обновлена."; + var notificationBody = $"Задача обновлена."; notificationStudent.Should().Contain(n => n.Body == notificationBody); notificationStudent1.Should().Contain(n => n.Body == notificationBody); @@ -338,10 +338,10 @@ public async Task NotificationStudentPassTaskTest() var hwCreateViewModel = GenerateCreateHomeworkViewModel(); var taskCreateViewModel = GenerateCreateTaskViewModel(); var homeworkId = await lectureCourseClient.AddHomeworkToCourse(hwCreateViewModel, courseId); - var taskId = await lectureCourseClient.AddTask(taskCreateViewModel, homeworkId); + var taskId = await lectureCourseClient.AddTask(taskCreateViewModel, homeworkId.Value); var solutionViewModel = GenerateSolutionViewModel(studentId); var solutionServiceClient = CreateSolutionsServiceClient(); - var solutionId = await solutionServiceClient.PostSolution(solutionViewModel, taskId); + var solutionId = await solutionServiceClient.PostSolution(solutionViewModel, taskId.Value); Thread.Sleep(5000); var notificationClient = CreateNotificationsServiceClient(); @@ -367,10 +367,10 @@ public async Task NotificationRateTest() var hwCreateViewModel = GenerateCreateHomeworkViewModel(); var taskCreateViewModel = GenerateCreateTaskViewModel(); var homeworkId = await lectureCourseClient.AddHomeworkToCourse(hwCreateViewModel, courseId); - var taskId = await lectureCourseClient.AddTask(taskCreateViewModel, homeworkId); + var taskId = await lectureCourseClient.AddTask(taskCreateViewModel, homeworkId.Value); var solutionViewModel = GenerateSolutionViewModel(studentId); var solutionServiceClient = CreateSolutionsServiceClient(); - var solutionId = await solutionServiceClient.PostSolution(solutionViewModel, taskId); + var solutionId = await solutionServiceClient.PostSolution(solutionViewModel, taskId.Value); await solutionServiceClient.RateSolution(solutionId, 3, "", lectureId); Thread.Sleep(5000); diff --git a/HwProj.sln b/HwProj.sln index 59c703fb0..b793a711c 100644 --- a/HwProj.sln +++ b/HwProj.sln @@ -119,8 +119,6 @@ Global {1407B364-9938-42C3-B061-30BE3F96FE02}.Debug|Any CPU.Build.0 = Debug|Any CPU {1407B364-9938-42C3-B061-30BE3F96FE02}.Release|Any CPU.ActiveCfg = Release|Any CPU {1407B364-9938-42C3-B061-30BE3F96FE02}.Release|Any CPU.Build.0 = Release|Any CPU - {34A014AB-BC00-4AFF-B08F-D8280734C869}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {34A014AB-BC00-4AFF-B08F-D8280734C869}.Debug|Any CPU.Build.0 = Debug|Any CPU {34A014AB-BC00-4AFF-B08F-D8280734C869}.Release|Any CPU.ActiveCfg = Release|Any CPU {34A014AB-BC00-4AFF-B08F-D8280734C869}.Release|Any CPU.Build.0 = Release|Any CPU {ECFA80DA-E0F5-4613-A15E-55FC8B9C8401}.Debug|Any CPU.ActiveCfg = Debug|Any CPU @@ -163,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 + {EA822D2F-88C2-4B82-AA20-DD07FF0A9A1E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {EA822D2F-88C2-4B82-AA20-DD07FF0A9A1E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {E6370DC6-B123-4233-B95F-2C505EA47BF5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {E6370DC6-B123-4233-B95F-2C505EA47BF5}.Debug|Any CPU.Build.0 = Debug|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -189,6 +191,8 @@ 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} + {EA822D2F-88C2-4B82-AA20-DD07FF0A9A1E} = {D7F8BC73-A6CB-4E07-984D-2D65B740BC69} + {E6370DC6-B123-4233-B95F-2C505EA47BF5} = {1EAEB779-E7C8-4EF9-B9A9-22CB8E3C246D} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {C03BF138-4A5B-4261-9495-6D3AC6CE9779}