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 SampleVerification_ExpectedScoreChangeInDataBase() { var givenContest = new Contest { Name = "", Status = Contest.ContestState.InProgress }; Context.Contests.Add(givenContest); var givenTask = new Task { Contest = givenContest, Description = "", Name = "", }; Context.Tasks.Add(givenTask); var givenTest = new Test { ExpectedOutput = "expected-output", Input = "given-input", Task = givenTask }; Context.Tests.Add(givenTest); var givenSolution = new Solution { SourceCode = "given-source-code", Language = "java", Task = givenTask }; Context.Solutions.Add(givenSolution); Context.SaveChanges(); ICommandHandler <ChangeScoreCommand> sut = new ChangeScoreCommandHandler(Context); int newScore = 2; var command = ChangeScoreCommand.Create(givenSolution.Id, newScore); sut.HandleAsync(command).Wait(); var solution = Context.Solutions.Find(givenSolution.Id); solution.PointCount.Should().Be(newScore); }