public async Task Check_If_Votes_Incremented() { await LogInAsAdministrator(); var createQuestion = new CreateQuestion( questionText: "Some question?", answers: new[] { "First answer", "Second answer" }); var createQuestionResponse = await Mediator.Send(createQuestion); var createdQuestionId = AssertNotError.Of(createQuestionResponse); var getQuestion = new GetQuestion(createdQuestionId); var questionResponse = await Mediator.Send(getQuestion); var createdQuestion = AssertNotError.Of(questionResponse); await LogInAsVoter(); var voteFor = new VoteFor( questionId: createdQuestion.Id, answerId: createdQuestion.Answers[1].Id); var voteForResponse = await Mediator.Send(voteFor); var getQuestionResult = new GetQuestionResult(createdQuestion.Id); var questionResultResponse = await Mediator.Send(getQuestionResult); AssertNotError.Of(voteForResponse); var questionResult = AssertNotError.Of(questionResultResponse); Assert.Multiple(() => { Assert.That(questionResult.Answers[0].Votes, Is.EqualTo(0)); Assert.That(questionResult.Answers[1].Votes, Is.EqualTo(1)); }); }
public async Task Check_If_Query_Was_Added() { await LogInAsAdministrator(); var createQuestion = new CreateQuestion( questionText: "Some question?", answers: new[] { "First answer", "Second answer" }); var createQuestionResponse = await Mediator.Send(createQuestion); var getQuestions = new GetQuestions(); var questionsResponse = await Mediator.Send(getQuestions); var addedQuestionId = AssertNotError.Of(createQuestionResponse); var allQuestions = AssertNotError.Of(questionsResponse); var questionThatWasAdded = allQuestions.Questions.SingleOrDefault(q => q.Id == addedQuestionId); Assert.That(questionThatWasAdded, Is.Not.Null); Assert.Multiple(() => { Assert.That( questionThatWasAdded !.QuestionText, Is.EqualTo(createQuestion.QuestionText)); CollectionAssert.AreEqual( questionThatWasAdded.Answers.Select(a => a.Text), createQuestion.Answers); }); }
public async Task Should_Return_Error_On_Twice_Vote_On_Same_Question() { await LogInAsAdministrator(); var createQuestion = new CreateQuestion( questionText: "Some question?", answers: new[] { "First answer", "Second answer" }); var createQuestionResponse = await Mediator.Send(createQuestion); var createdQuestionId = AssertNotError.Of(createQuestionResponse); var getQuestion = new GetQuestion(createdQuestionId); var questionResponse = await Mediator.Send(getQuestion); var createdQuestion = AssertNotError.Of(questionResponse); await LogInAsVoter(); var voteFor = new VoteFor( questionId: createdQuestion.Id, answerId: createdQuestion.Answers[1].Id); var voteForResponse = await Mediator.Send(voteFor); var voteForDuplicate = new VoteFor( questionId: createdQuestion.Id, answerId: createdQuestion.Answers[0].Id); var voteForResponseDuplicate = await Mediator.Send(voteForDuplicate); AssertError <DomainError> .Of(voteForResponseDuplicate); }
public async Task Should_Return_Error_When_Not_Logged() { await LogInAsAdministrator(); var createQuestion = new CreateQuestion( questionText: "Some question?", answers: new[] { "First answer", "Second answer" }); var createQuestionResponse = await Mediator.Send(createQuestion); var createdQuestionId = AssertNotError.Of(createQuestionResponse); var getQuestion = new GetQuestion(createdQuestionId); var questionResponse = await Mediator.Send(getQuestion); var createdQuestion = AssertNotError.Of(questionResponse); LogOut(); var voteFor = new VoteFor( questionId: createdQuestion.Id, answerId: createdQuestion.Answers[1].Id); var voteForResponse = await Mediator.Send(voteFor); AssertError <AuthorizationError> .Of(voteForResponse); }
public async Task Create_3_Questions_And_Check_If_Added() { await LogInAsAdministrator(); var createFirstQuestion = new CreateQuestion( questionText: "Some question?", answers: new[] { "First answer", "Second answer" }); var createFirstQuestionResponse = await Mediator.Send(createFirstQuestion); var firstQuestionId = AssertNotError.Of(createFirstQuestionResponse); var createSecondQuestion = new CreateQuestion( questionText: "Another question?", answers: new[] { "Any answer", "Some answer" }); var createSecondQuestionResponse = await Mediator.Send(createSecondQuestion); var secondQuestionId = AssertNotError.Of(createSecondQuestionResponse); var createThirdQuestion = new CreateQuestion( questionText: "Third question?", answers: new[] { "Any answer", "Some answer", "I don't know answer" }); var createThirdQuestionResponse = await Mediator.Send(createThirdQuestion); var thirdQuestionId = AssertNotError.Of(createThirdQuestionResponse); await LogInAsVoter(); var expectedQuestions = new Dictionary <Guid, CreateQuestion> { [firstQuestionId] = createFirstQuestion, [secondQuestionId] = createSecondQuestion, [thirdQuestionId] = createThirdQuestion }; var getQuestions = new GetQuestions(); var getQuestionsResponse = await Mediator.Send(getQuestions); var questions = AssertNotError.Of(getQuestionsResponse); Assert.That(questions.Questions, Has.Count.EqualTo(3)); CollectionAssert.AreEquivalent( expectedQuestions.Select(q => q.Value.QuestionText), questions.Questions.Select(q => q.QuestionText)); foreach (var question in questions.Questions) { var expectedAnswers = expectedQuestions .Single(q => q.Key == question.Id) .Value .Answers; CollectionAssert.AreEqual( expectedAnswers, question.Answers.Select(a => a.Text)); } }
public async Task Check_If_Votes_Exists_In_My_Votes_After_Voting_2_Of_3_Questions() { await LogInAsAdministrator(); var createFirstQuestion = new CreateQuestion( questionText: "Some question?", answers: new[] { "First answer", "Second answer" }); var createFirstQuestionResponse = await Mediator.Send(createFirstQuestion); var firstQuestionId = AssertNotError.Of(createFirstQuestionResponse); var getFirstQuestion = new GetQuestion(firstQuestionId); var firstQuestionResponse = await Mediator.Send(getFirstQuestion); var firstQuestion = AssertNotError.Of(firstQuestionResponse); var createSecondQuestion = new CreateQuestion( questionText: "Another question?", answers: new[] { "Any answer", "Some answer" }); var createSecondQuestionResponse = await Mediator.Send(createSecondQuestion); _ = AssertNotError.Of(createSecondQuestionResponse); // I will not vote on this question var createThirdQuestion = new CreateQuestion( questionText: "Third question?", answers: new[] { "Any answer", "Some answer", "I don't know answer" }); var createThirdQuestionResponse = await Mediator.Send(createThirdQuestion); var thirdQuestionId = AssertNotError.Of(createThirdQuestionResponse); var getThirdQuestion = new GetQuestion(thirdQuestionId); var thirdQuestionResponse = await Mediator.Send(getThirdQuestion); var thirdQuestion = AssertNotError.Of(thirdQuestionResponse); await LogInAsVoter(); var voteForFirst = new VoteFor( questionId: firstQuestion.Id, answerId: firstQuestion.Answers[0].Id); await Mediator.Send(voteForFirst); var voteForThird = new VoteFor( questionId: thirdQuestion.Id, answerId: thirdQuestion.Answers[2].Id); await Mediator.Send(voteForThird); var getMyVotes = new GetMyVotes(); var getMyVotesResponse = await Mediator.Send(getMyVotes); var myVotes = AssertNotError.Of(getMyVotesResponse); CollectionAssert.AreEquivalent( new[] { firstQuestion.Id, thirdQuestion.Id }, myVotes.QuestionsId); }
public async Task Should_Return_Error_On_Duplicated_Voter() { const string voterPesel = "87062537594"; var createFirstVoter = new CreateVoter(voterPesel); var firstResponse = await Mediator.Send(createFirstVoter); var createSameAsPreviousVoter = new CreateVoter(voterPesel); var secondResponse = await Mediator.Send(createSameAsPreviousVoter); AssertNotError.Of(firstResponse); AssertError <ObjectAlreadyExistsError> .Of(secondResponse); }
public async Task First_Registered_Voter_Should_Be_Admin() { const string voterPesel = "87062537594"; var createVoter = new CreateVoter(voterPesel); var createVoterResponse = await Mediator.Send(createVoter); var logIn = new LogIn(voterPesel); var logInResponse = await Mediator.Send(logIn); AssertNotError.Of(createVoterResponse); var voterViewModel = AssertNotError.Of(logInResponse); Assert.That(voterViewModel.IsAdministrator, Is.True); }
public async Task Check_If_Voter_Was_Created() { const string voterPesel = "87062537594"; var createVoter = new CreateVoter(voterPesel); _ = await Mediator.Send(createVoter); var logIn = new LogIn(voterPesel); var voterResponse = await Mediator.Send(logIn); var voter = AssertNotError.Of(voterResponse); Assert.That(voter.Pesel, Is.EqualTo(voterPesel)); }
public async Task Should_Return_Error_When_Request_For_Result_Of_Not_Voted_Question() { await LogInAsAdministrator(); var createQuestion = new CreateQuestion( questionText: "Some question?", answers: new[] { "First answer", "Second answer" }); var createQuestionResponse = await Mediator.Send(createQuestion); var questionId = AssertNotError.Of(createQuestionResponse); await LogInAsVoter(); var getResult = new GetQuestionResult(questionId); var getResultResponse = await Mediator.Send(getResult); AssertError <AuthorizationError> .Of(getResultResponse); }
public async Task Second_Registered_Voter_Should_Not_Be_Admin() { const string firstVoterPesel = "87062537594"; const string secondVoterPesel = "92113059581"; var createFirstVoter = new CreateVoter(firstVoterPesel); _ = await Mediator.Send(createFirstVoter); var createSecondVoter = new CreateVoter(secondVoterPesel); var secondVoterResponse = await Mediator.Send(createSecondVoter); var logIn = new LogIn(secondVoterPesel); var logInResponse = await Mediator.Send(logIn); AssertNotError.Of(secondVoterResponse); var secondVoter = AssertNotError.Of(logInResponse); Assert.That(secondVoter.IsAdministrator, Is.False); }
public async Task Check_If_Question_Results_Are_Valid() { await LogInAsAdministrator(); var createFirstQuestion = new CreateQuestion( questionText: "Some question?", answers: new[] { "First answer", "Second answer" }); var createFirstQuestionResponse = await Mediator.Send(createFirstQuestion); var firstQuestionId = AssertNotError.Of(createFirstQuestionResponse); var getFirstQuestion = new GetQuestion(firstQuestionId); var firstQuestionResponse = await Mediator.Send(getFirstQuestion); var firstQuestion = AssertNotError.Of(firstQuestionResponse); var createSecondQuestion = new CreateQuestion( questionText: "Another question?", answers: new[] { "Any answer", "Some answer" }); var createSecondQuestionResponse = await Mediator.Send(createSecondQuestion); var secondQuestionId = AssertNotError.Of(createSecondQuestionResponse); var getSecondQuestion = new GetQuestion(secondQuestionId); var secondQuestionResponse = await Mediator.Send(getSecondQuestion); var secondQuestion = AssertNotError.Of(secondQuestionResponse); var firstVoteFor = new VoteFor(firstQuestion.Id, firstQuestion.Answers[0].Id); await Mediator.Send(firstVoteFor); var secondVoteFor = new VoteFor(secondQuestion.Id, secondQuestion.Answers[1].Id); await Mediator.Send(secondVoteFor); await LogInAsVoter(); var thirdVoteFor = new VoteFor(firstQuestion.Id, firstQuestion.Answers[0].Id); await Mediator.Send(thirdVoteFor); var fourthVoteFor = new VoteFor(secondQuestion.Id, secondQuestion.Answers[0].Id); await Mediator.Send(fourthVoteFor); var getFirstResult = new GetQuestionResult(firstQuestion.Id); var firstResultResponse = await Mediator.Send(getFirstResult); var firstResult = AssertNotError.Of(firstResultResponse); var getSecondResult = new GetQuestionResult(secondQuestion.Id); var secondResultResponse = await Mediator.Send(getSecondResult); var secondResult = AssertNotError.Of(secondResultResponse); Assert.Multiple(() => { Assert.That(firstResult.Answers[0].Votes, Is.EqualTo(2)); Assert.That(firstResult.Answers[1].Votes, Is.EqualTo(0)); Assert.That(secondResult.Answers[0].Votes, Is.EqualTo(1)); Assert.That(secondResult.Answers[1].Votes, Is.EqualTo(1)); }); }