public async Task UsersWithTheSamePointArePlacedByTimeOffset() { //Arrange TestResultServiceTestBase testBase = new TestResultServiceTestBase(); TestResultRepository testResultRepository = await testBase.GetTestResultRepositoryAsync(); var service = new TestResultService(testResultRepository, new CorrectAnswerPointsRule(), new BonusPointsRule(), new AnsweringTimePlaceRule()); //Act service.CalculateWeeklyResults(1); var results = testResultRepository.GetFinalResults(); //Assert Assert.Equal( results.Where(x => x.UserId == UserModel.userD.Id).Select(x => x.Week1Points).FirstOrDefault(), results.Where(x => x.UserId == UserModel.userC.Id).Select(x => x.Week1Points).FirstOrDefault()); Assert.Equal( 2, results.Where(x => x.UserId == UserModel.userC.Id).Select(x => x.Week1Place).FirstOrDefault()); Assert.Equal( 1, results.Where(x => x.UserId == UserModel.userD.Id).Select(x => x.Week1Place).FirstOrDefault()); }
public async Task UserWithCorrectAnswerAfterRankingPerionShouldHaveZeroPoints() { //Arrange TestResultServiceTestBase testBase = new TestResultServiceTestBase(); TestResultRepository testResultRepository = await testBase.GetTestResultRepositoryAsync(); var service = new TestResultService(testResultRepository, new CorrectAnswerPointsRule(), new BonusPointsRule(), new AnsweringTimePlaceRule()); //Act service.CalculateWeeklyResults(1); var results = testResultRepository.GetFinalResults(); //Assert Assert.Equal( 0, results.FirstOrDefault(x => x.UserId == UserModel.userI.Id).Week1Points.Value); }
public async Task UsersWithAllCorrectAnswersAndNoWrongAnswersHaveMaximumPoints() { //Arrange TestResultServiceTestBase testBase = new TestResultServiceTestBase(); TestResultRepository testResultRepository = await testBase.GetTestResultRepositoryAsync(); var service = new TestResultService(testResultRepository, new CorrectAnswerPointsRule(), new BonusPointsRule(), new AnsweringTimePlaceRule()); //Act service.CalculateWeeklyResults(1); var results = testResultRepository.GetFinalResults(); //Assert Assert.Equal( results.Where(x => x.UserId == UserModel.userD.Id).Select(x => x.Week1Points).FirstOrDefault(), 2 * (100 + 30)); Assert.Equal( results.Where(x => x.UserId == UserModel.userC.Id).Select(x => x.Week1Points).FirstOrDefault(), 2 * (100 + 30)); }
public async Task UsersWithTheSameCorrectAnswersAndTheSameBonusHaveTheSamePoints() { //Arrange TestResultServiceTestBase testBase = new TestResultServiceTestBase(); TestResultRepository testResultRepository = await testBase.GetTestResultRepositoryAsync(); var service = new TestResultService(testResultRepository, new CorrectAnswerPointsRule(), new BonusPointsRule(), new AnsweringTimePlaceRule()); var expectedResult = testBase.GetExpectedWeek1ResultModel(); //Act service.CalculateWeeklyResults(1); var results = testResultRepository.GetFinalResults(); //Assert Assert.Equal( results.Where(x => x.UserId == UserModel.userA.Id).Select(x => x.Week1Points).FirstOrDefault(), results.Where(x => x.UserId == UserModel.userB.Id).Select(x => x.Week1Points).FirstOrDefault()); Assert.Equal( expectedResult.Where(x => x.UserId == UserModel.userA.Id).Select(x => x.Week1Points).FirstOrDefault(), results.Where(x => x.UserId == UserModel.userA.Id).Select(x => x.Week1Points).FirstOrDefault()); }
public async Task UsersWithNoCorrectAnswersHaveZeroPoints() { //Arrange TestResultServiceTestBase testBase = new TestResultServiceTestBase(); TestResultRepository testResultRepository = await testBase.GetTestResultRepositoryAsync(); var service = new TestResultService(testResultRepository, new CorrectAnswerPointsRule(), new BonusPointsRule(), new AnsweringTimePlaceRule()); var expectedResult = testBase.GetExpectedWeek1ResultModel(); //Act service.CalculateWeeklyResults(1); var results = testResultRepository.GetFinalResults(); //Assert var expectedResultItems = expectedResult.Where(x => x.Week1Points == 0).Select(x => x.UserId).ToList(); var resultItems = results.Where(x => x.Week1Points == 0).Select(x => x.UserId).ToList(); Assert.Equal(expectedResultItems.Count, resultItems.Count); foreach (var item in expectedResultItems) { Assert.Contains(item, resultItems); } }
public async Task GetWeek2CorrectRanking() { //Arrange TestResultServiceTestBase testBase = new TestResultServiceTestBase(); TestResultRepository testResultRepository = await testBase.GetTestResultRepositoryAsync(); var service = new TestResultService(testResultRepository, new CorrectAnswerPointsRule(), new BonusPointsRule(), new AnsweringTimePlaceRule()); var expectedResult = testBase.GetExpectedWeek2ResultModel(); //Act service.CalculateWeeklyResults(2); var results = testResultRepository.GetFinalResults(); //Assert var expectedResultItems = expectedResult.Select(x => GetWeek2Result(x)).ToList(); var resultItems = results.Select(x => GetWeek2Result(x)).ToList(); Assert.Equal(expectedResultItems.Count, resultItems.Count); foreach (var item in expectedResultItems) { Assert.Contains(item, resultItems); } }