public async void GetExamsByTypeAndCategory_WhenExists_ReturnsResult()
        {
            using (var fixture = new ExamsFixture())
            {
                var exams = new List <Exam>
                {
                    new ExamBuilder("First Exam", ExamType.GeneralKnowledge, "Kardiologia").Build(),
                    new ExamBuilder("Second Exam", ExamType.GeneralKnowledge, "Interna").Build(),
                    new ExamBuilder("Third Exam", ExamType.Specialization, "Kardiologia").Build()
                };
                await fixture.AddMany(exams);

                var expected = new ExamsResult(new[] { fixture.Mapper.Map <ExamsResult.Exam>(exams[1]) });

                var query = new GetExamsByTypeAndCategoryQuery()
                {
                    Category = "Interna",
                    Type     = ExamType.GeneralKnowledge
                };
                var handler = new GetExamsByTypeAndCategoryQueryHandler(fixture.Repository, fixture.Mapper);
                var result  = await handler.HandleAsync(query);

                result.Content.Should().BeEquivalentTo(expected);
            }
        }
        public async void GetExamById_WhenExamsExists_ExamIsReturned()
        {
            using (var fixture = new ExamsFixture())
            {
                var exams = new List <Exam>
                {
                    new ExamBuilder("First Exam", ExamType.GeneralKnowledge, "Kardiologia")
                    .WithQuestion("e1q1", CorrectAnswer.A)
                    .WithQuestion("e1q2", CorrectAnswer.B)
                    .Build(),
                    new ExamBuilder("Second Exam", ExamType.GeneralKnowledge, "Interna")
                    .WithQuestion("e2q1", CorrectAnswer.C)
                    .WithQuestion("e2q2", CorrectAnswer.D)
                    .Build(),
                    new ExamBuilder("Third Exam", ExamType.Specialization, "Kardiologia")
                    .WithQuestion("e3q1", CorrectAnswer.B)
                    .WithQuestion("e3q2", CorrectAnswer.D)
                    .Build()
                };
                await fixture.AddMany(exams);

                var expected = fixture.Mapper.Map <ExamWithQuestionsResult>(exams[1]);

                var query = new GetExamByIdQuery {
                    Id = exams[1].Id
                };
                var handler = new GetExamByIdQueryHandler(fixture.Repository, fixture.Mapper);
                var result  = await handler.HandleAsync(query);

                result.Content.Should().BeEquivalentTo(expected);
            }
        }
        public async void GetCategoriesByType_WhenExists_ReturnsDistincted()
        {
            using (var fixture = new ExamsFixture())
            {
                var exams = new List <Exam>()
                {
                    new ExamBuilder("First Exam", ExamType.GeneralKnowledge, "Kardiologia").Build(),
                    new ExamBuilder("Second Exam", ExamType.GeneralKnowledge, "Interna").Build(),
                    new ExamBuilder("Third Exam", ExamType.Specialization, "Kardiologia").Build(),
                    new ExamBuilder("Fourth Exam", ExamType.GeneralKnowledge, "Kardiologia").Build(),
                    new ExamBuilder("Fifth Exam", ExamType.GeneralKnowledge, "Interna").Build(),
                    new ExamBuilder("Sixth Exam", ExamType.Specialization, "Urologia").Build(),
                    new ExamBuilder("Seventh Exam", ExamType.GeneralKnowledge, "Nefrologia").Build()
                };
                await fixture.AddMany(exams);

                var query = new GetCategoriesByTypeQuery {
                    Type = ExamType.GeneralKnowledge
                };
                var handler = new GetCategoriesByTypeQueryHandler(fixture.Repository);
                var result  = await handler.HandleAsync(query);

                result.Content.Should().BeEquivalentTo(new CategoriesResult(
                                                           new []
                {
                    new CategoriesResult.Category("Kardiologia"),
                    new CategoriesResult.Category("Interna"),
                    new CategoriesResult.Category("Nefrologia"),
                })
                                                       );
            }
        }
Beispiel #4
0
        public async void EditExamWithQuestions_WhenExamExists_CorrectlyModifyExamAndQuestions()
        {
            using (var fixture = new ExamsFixture())
            {
                await fixture.Repository.AddAsync(new ExamBuilder("Some-exam", ExamType.Specialization, "Some-category")
                                                  .WithQuestion("Q1", CorrectAnswer.A)
                                                  .WithQuestion("Q2", CorrectAnswer.B)
                                                  .WithQuestion("Q3", CorrectAnswer.C)
                                                  .Build()
                                                  );

                var original = fixture.GetAllExams().First();
                var modified = original.DeepClone();

                modified.SetName("Different name");
                modified.SetCategory("Interna");
                modified.ChangeType(ExamType.GeneralKnowledge);

                modified.RemoveQuestion(modified.Questions.Last().Id);
                modified.AddQuestion(3, "text", "a", "b", "c", "d", CorrectAnswer.D, "expl");
                modified.AddQuestion(4, "text-second", "e", "f", "g", "h", CorrectAnswer.A, "testing");
                modified.Questions.First().SetText("Changed text");

                var command = fixture.Mapper.Map <EditExamCommand>(modified);
                var handler = new EditExamCommandHandler(fixture.Repository, modified.Id);
                await handler.HandleAsync(command);

                var result = await fixture.Repository.GetByIdAsync(modified.Id);

                result.Should().NotBe(original);
                result.Questions.Count.Should().Be(4);
                result.Questions.Should().NotBeEquivalentTo(original.Questions);
            }
        }
Beispiel #5
0
        public async void AddExamWithQuestions_WhenCalled_CorrectlyCreatesObjects()
        {
            using (var fixture = new ExamsFixture())
            {
                var exam = new ExamBuilder("Some-exam", ExamType.Specialization, "Some-category")
                           .WithQuestion("Q1", CorrectAnswer.A)
                           .WithQuestion("Q2", CorrectAnswer.B)
                           .WithQuestion("Q3", CorrectAnswer.C)
                           .Build();

                var command = fixture.Mapper.Map <AddExamCommand>(exam);
                var handler = new AddExamCommandHandler(fixture.Repository, fixture.User);
                await handler.HandleAsync(command);

                var allExams = fixture.GetAllExams();

                allExams.Count.Should().Be(1);
                allExams.First().Should().BeEquivalentTo(
                    exam,
                    options => options
                    .Excluding(p => p.Id)
                    .Excluding(p => p.CreatedDate)
                    .Excluding(p => p.CreatedBy)
                    .Excluding(p => p.Questions)
                    );
                allExams.First().Questions.Should().BeEquivalentTo(
                    exam.Questions,
                    options => options
                    .Excluding(p => p.Id)
                    .Excluding(p => p.Exam)
                    );
            }
        }
        public async void GetExamById_WhenExamNotExists_EmptyValueIsReturned()
        {
            using (var fixture = new ExamsFixture())
            {
                var query = new GetExamByIdQuery {
                    Id = Guid.NewGuid()
                };
                var handler = new GetExamByIdQueryHandler(fixture.Repository, fixture.Mapper);
                var result  = await handler.HandleAsync(query);

                result.Content.Should().BeNull();
            }
        }
Beispiel #7
0
        public async void RemoveExamWithQuestions_WhenExamExists_DeleteExamsAndQuestions()
        {
            using (var fixture = new ExamsFixture())
            {
                await fixture.Repository.AddAsync(new ExamBuilder("Some-exam", ExamType.Specialization, "Some-category")
                                                  .WithQuestion("Q1", CorrectAnswer.B)
                                                  .WithQuestion("Q2", CorrectAnswer.D)
                                                  .Build()
                                                  );

                var allExams = fixture.GetAllExams();
                var examsCountBeforeDelete = allExams.Count;

                var command = new DeleteExamCommand();
                var handler = new DeleteExamCommandHandler(fixture.Repository, allExams.First().Id);
                await handler.HandleAsync(command);

                var result = await fixture.Repository.GetByIdAsync(allExams.First().Id);

                examsCountBeforeDelete.Should().Be(1);
                result.Should().BeNull();
                fixture.GetAllExams().Count.Should().Be(0);
            }
        }