Example #1
0
        public async Task RegisterUser_WhenEmailAlreadyExists_ShouldThrowAnException()
        {
            using (var sut = new SystemUnderTest(UsersFactory.CreateUser("*****@*****.**")))
            {
                var user = new User(Guid.NewGuid(), "*****@*****.**", true, Enumerable.Empty <Role>(), "zaq1@WSX-hash", "password-salt", DateTime.Now);
                await sut.CreateAsync(user);

                var command = new RegisterCommand
                {
                    Email           = "*****@*****.**",
                    Password        = "******",
                    ConfirmPassword = "******"
                };

                var url    = $"{Url}/register";
                var result = sut.HttpPost(url, command);

                result.IsSuccess.Should().BeFalse();
                result.Message.Should().BeEquivalentTo("Email already exists.");
            }
        }
        public async void EditExamWithQuestions_WhenExamExists_CorrectlyModifyExamAndQuestionsWithStatus202()
        {
            using (var sut = new SystemUnderTest(UsersFactory.CreateUser("*****@*****.**", Role.EditExam)))
            {
                await sut.CreateAsync(new ExamBuilder("Some-exam", ExamType.Specialization, "Some-category")
                                      .WithQuestion("Q1", CorrectAnswer.A)
                                      .WithQuestion("Q2", CorrectAnswer.B)
                                      .WithQuestion("Q3", CorrectAnswer.C)
                                      .Build()
                                      );

                var allExams = await sut.GetAllExamsAsync();

                var original = await sut.GetExamByIdAsync(allExams.First().Id);

                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 = sut.Mapper.Map <EditExamCommand>(modified);

                var commandResult = sut.HttpPut(Url, modified.Id, command);
                var result        = await sut.GetExamByIdAsync(modified.Id);

                commandResult.IsSuccess.Should().BeTrue();
                result.Should().NotBe(original);
                result.Questions.Count.Should().Be(4);
                result.Questions.Should().NotBeEquivalentTo(original.Questions);
            }
        }