コード例 #1
0
        public async Task UpdateAnswerKeyForms()
        {
            var userId = RandomGen.Next(10000);

            using (var testServer = Create(userId))
            {
                var examId = await ExecuteExamCreatedConsumerAsync(testServer);

                var client = testServer.CreateClient();
                var list   = await GetListAsync <AnswerKeyOpticalForm>(client, examId);

                list.Should().NotBeEmpty();
                var studentForms = new List <StudentOpticalForm>()
                {
                    new StudentOpticalForm(list.First().Booklet)
                    {
                        SchoolId = userId,
                        UserId   = userId.ToString(),
                        ExamId   = examId,
                    },
                    new StudentOpticalForm(list.Last().Booklet)
                    {
                        SchoolId = userId,
                        UserId   = userId.ToString(),
                        ExamId   = examId,
                    },
                };
                studentForms.First().SetFromScanOutput(new ScanOutput("BABABABACADADADADACA", 0), list.First());
                studentForms.Last().SetFromScanOutput(new ScanOutput("ABCABDABCABDAC", 0), list.Last());
                await client.PostAsync(ApiPath, studentForms.ToJsonContent());

                var newAnswerKeyForms = GenerateAnswerKeyOpticalForms(4).ToList();
                var repository        = testServer.Host.Services.GetService(typeof(IOpticalFormRepository));
                var consumer          = new ExamUpdatedConsumer(repository as IOpticalFormRepository, null);
                var context           = Substitute.For <ConsumeContext <IExamUpdated> >();
                context.Message.ExamId.Returns(examId);
                context.Message.AnswerKeyOpticalForms.Returns(newAnswerKeyForms);
                await consumer.Consume(context);

                list = await GetListAsync <AnswerKeyOpticalForm>(client, examId);

                list.Should().HaveCount(newAnswerKeyForms.Count);
                studentForms = (await GetListAsync <StudentOpticalForm>(client, examId)).ToList();
                studentForms.Should().NotBeEmpty();
            }
        }
コード例 #2
0
        public async Task UpdateAnswerKeyForms(IFixture fixture, int userId)
        {
            var repo = _webApplicationFactory.Services.GetRequiredService <IAnswerKeyOpticalFormRepository>();

            var examId = await ExecuteExamCreatedConsumerAsync(repo, fixture);

            var client = _webApplicationFactory.CreateClientWithUserId(userId);
            var list   = await GetListAsync <AnswerKeyOpticalForm>(client, examId);

            list.Should().NotBeEmpty();
            var studentForms = new List <StudentOpticalForm>()
            {
                new StudentOpticalForm(list.First().Booklet)
                {
                    SchoolId = userId,
                    UserId   = userId.ToString(),
                    ExamId   = examId,
                },
                new StudentOpticalForm(list.Last().Booklet)
                {
                    SchoolId = userId,
                    UserId   = userId.ToString(),
                    ExamId   = examId,
                },
            };

            studentForms.First().SetFromScanOutput(new ScanOutput("BABABABACADADADADACA", 0, 0, 'A'), list.First());
            studentForms.Last().SetFromScanOutput(new ScanOutput("ABCABDABCABDAC", 0, 0, 'A'), list.Last());
            await client.PostAsync(ApiPath, studentForms.ToJsonContent());

            var newAnswerKeyForms = GenerateAnswerKeyOpticalForms(fixture, 4).ToList();
            var consumer          = new ExamUpdatedConsumer(repo, null);
            var context           = Substitute.For <ConsumeContext <IExamUpdated> >();

            context.Message.ExamId.Returns(examId);
            context.Message.AnswerKeyOpticalForms.Returns(newAnswerKeyForms);
            await consumer.Consume(context);

            list = await GetListAsync <AnswerKeyOpticalForm>(client, examId);

            list.Should().HaveCount(newAnswerKeyForms.Count);
            studentForms = (await GetListAsync <StudentOpticalForm>(client, examId)).ToList();
            studentForms.Should().NotBeEmpty();
        }