Example #1
0
        public async Task DeleteStudentFormsOfClassrooms()
        {
            var classroomId = RandomGen.Next();
            var examId      = RandomGen.Next();
            var userId      = RandomGen.Next();

            using (var testServer = Create(userId))
            {
                var forms    = GenerateStudentForms(examId, userId, classroomId);
                var client   = testServer.CreateClient();
                var response = await client.PostAsync(ApiPath, forms.ToJsonContent());

                response.EnsureSuccessStatusCode();
                var studentOpticalForms = await GetListAsync <StudentOpticalForm>(client, examId);

                studentOpticalForms.Should()
                .HaveCount(2)
                .And
                .NotContain(s => s.ClassroomId != classroomId);
                var repository = testServer.Host.Services.GetService(typeof(IOpticalFormRepository));
                var consumer   = new ClassroomDeletedConsumer(repository as IOpticalFormRepository, null);
                var context    = Substitute.For <ConsumeContext <IClassroomDeleted> >();
                context.Message.ClassroomId.Returns(classroomId);
                await consumer.Consume(context);

                studentOpticalForms = await GetListAsync <StudentOpticalForm>(client, examId);

                studentOpticalForms.Should().BeEmpty();
            }
        }
Example #2
0
        public async Task DeleteStudentFormsOfClassrooms(IFixture fixture, int userId, int examId, int classroomId)
        {
            var forms    = GenerateStudentForms(fixture, examId, userId, classroomId);
            var client   = _webApplicationFactory.CreateClientWithUserId(userId);
            var response = await client.PostAsync(ApiPath, forms.ToJsonContent());

            response.EnsureSuccessStatusCode();
            var studentOpticalForms = await GetListAsync <StudentOpticalForm>(client, examId);

            studentOpticalForms.Should()
            .HaveCount(2)
            .And
            .NotContain(s => s.ClassroomId != classroomId);
            var repository = _webApplicationFactory.Services.GetRequiredService <IStudentOpticalFormRepository>();
            var consumer   = new ClassroomDeletedConsumer(repository, null);
            var context    = Substitute.For <ConsumeContext <IClassroomDeleted> >();

            context.Message.ClassroomId.Returns(classroomId);
            await consumer.Consume(context);

            studentOpticalForms = await GetListAsync <StudentOpticalForm>(client, examId);

            studentOpticalForms.Should().BeEmpty();
        }