public void TwoSolutionsFromSingleUserForSingleTask_NewerSolutionReturned() { var givenEarlierDate = new DateTime(1999, 5, 5); var givenLaterDate = new DateTime(1999, 5, 6); var givenEarlierSolution = new Solution { IdentityUser = GivenFirstUser, Task = GivenFirstTask, TimeStamp = givenEarlierDate }; var givenLaterSolution = new Solution { IdentityUser = GivenFirstUser, Task = GivenFirstTask, TimeStamp = givenLaterDate }; Context.Solutions.AddRange(givenEarlierSolution, givenLaterSolution); Context.SaveChanges(); var expectedSolutionIds = new[] { givenLaterSolution.Id }; var givenQuery = NewestSolutionsQuery.Create(GivenContest.Id); var result = Sut.HandleAsync(givenQuery).Result; var actualSolutionIds = result.SolutionIds; actualSolutionIds.Should().BeEquivalentTo(expectedSolutionIds); }
private async Task <IEnumerable <Solution> > GetSolutions(int contestId) { var newestSolutionsQuery = NewestSolutionsQuery.Create(contestId); var result = await _newestSolutionsQueryHandler.HandleAsync(newestSolutionsQuery); var solutionIds = result.SolutionIds; return(solutionIds.Select(id => _dbContext.Solutions.Find(id))); }
public void NoSolutionsInDatabase_NoSolutionsReturned() { var expectedSolutionIds = new List <int>(); var givenQuery = NewestSolutionsQuery.Create(GivenContest.Id); var result = Sut.HandleAsync(givenQuery).Result; var actualSolutionIds = result.SolutionIds; actualSolutionIds.Should().BeEquivalentTo(expectedSolutionIds); }
public async System.Threading.Tasks.Task HandleAsync(ContestEndCommand command) { var newestSolutionsQuery = NewestSolutionsQuery.Create(command.ContestId); var solutions = await _newestSolutionQueryHandler.HandleAsync(newestSolutionsQuery); foreach (var solutionId in solutions.SolutionIds) { var verifySolutionCommand = VerifySolutionCommand.Create(solutionId); await _verifySolutionCommandHandler.HandleAsync(verifySolutionCommand); var calculateScoreQuery = CalculateScoreQuery.Create(solutionId); var calculateScoreResult = await _calculateScoreQueryHandler.HandleAsync(calculateScoreQuery); var changeScoreCommand = ChangeScoreCommand.Create(solutionId, calculateScoreResult.Score); await _changeScoreCommandHandler.HandleAsync(changeScoreCommand); } }
public void TwoSolutionsForDifferentTasks_BothSolutionsReturned() { var givenFirstSolution = new Solution { IdentityUser = GivenFirstUser, Task = GivenFirstTask }; var givenSecondSolution = new Solution { IdentityUser = GivenFirstUser, Task = GivenSecondTask }; var givenSolutions = new[] { givenFirstSolution, givenSecondSolution }; Context.Solutions.AddRange(givenSolutions); Context.SaveChanges(); var expectedSolutionIds = givenSolutions.Select(s => s.Id); var givenQuery = NewestSolutionsQuery.Create(GivenContest.Id); var result = Sut.HandleAsync(givenQuery).Result; var actualSolutionIds = result.SolutionIds; actualSolutionIds.Should().BeEquivalentTo(expectedSolutionIds); }