コード例 #1
0
        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());
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        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));
        }
コード例 #4
0
        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());
        }
コード例 #5
0
        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);
            }
        }
コード例 #6
0
        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);
            }
        }
コード例 #7
0
        public void GetFinalCorrectRanking()
        {
            //Arrange
            var service = new TestResultService(testResultRepository, new CorrectAnswerPointsRule(), new BonusPointsRule(),
                                                new AnsweringTimePlaceRule(), GetTestSettings());
            var expectedResult = fixture.GetExpectedFinalResultModel();

            //Act
            service.CalculateFinalResults();
            var results = testResultRepository.GetFinalResults();

            //Assert
            var expectedResultItems = expectedResult.Select(x => GetFinalResult(x)).ToList();
            var resultItems         = results.Select(x => GetFinalResult(x)).ToList();

            Assert.Equal(expectedResultItems.Count, resultItems.Count);
            foreach (var item in expectedResultItems)
            {
                Assert.Contains(item, resultItems);
            }
        }