예제 #1
0
        public async Task GetCourseUserStatsQueryHandler_OneCourse_ReturnData()
        {
            using var context = TestHelper.CreateInMemoryContext("GetCourseUserStatsQueryHandler_OneCourse_ReturnData");
            var userGuid = Guid.NewGuid();

            context.UserCourseStats.Add(
                new UserCourseStats
            {
                UserId = userGuid,
                Course = CreateCourse(userGuid),
                NumberOfCorrectResponses   = 10,
                NumberOfIncorrectResponses = 11,
                Date = DateTime.Now
            });
            context.UserCourseStats.Add(
                new UserCourseStats
            {
                UserId   = userGuid,
                CourseId = 100,
                NumberOfCorrectResponses   = 40,
                NumberOfIncorrectResponses = 1,
                Date = DateTime.Now.AddDays(-1)
            });
            context.UserCourseStats.Add(
                new UserCourseStats
            {
                UserId   = userGuid,
                CourseId = 100,
                NumberOfCorrectResponses   = 10,
                NumberOfIncorrectResponses = 0,
                Date = new DateTime(2020, 10, 10)
            });
            context.SaveChanges();

            var handler = new GetCourseUserStatsQueryHandler(new UnitOfWork(context));
            var request = new GetCourseUserStatsRequestModel
            {
                UserId = userGuid
            };

            var response = await handler.Handle(request, CancellationToken.None);

            response.StatsForCourses.Should().ContainKey("Name");
            var stats = response.StatsForCourses["Name"];

            stats.FirstRepetitionDate.Should().Be("Saturday, 10 October 2020");
            stats.LastThreeDays.NumberOfCorrectResponses.Should().Be(50);
            stats.LastThreeDays.NumberOfIncorrectResponses.Should().Be(12);
            stats.MonthStats.Count.Should().Be(4);
            stats.RepetitionStats.Count.Should().Be(2);
            stats.RepetitionStats.Should().ContainKeys(10, 20);
            stats.RepetitionStats[10].Should().Be(2);
            stats.RepetitionStats[20].Should().Be(1);
            stats.NewWords.Should().Be(1);
        }
예제 #2
0
        public async Task GetCourseUserStatsQueryHandler_NoMyCourses_ReturnEmpty()
        {
            using var context = TestHelper.CreateInMemoryContext("GetCourseUserStatsQueryHandler_NoMyCourses_ReturnEmpty");

            var handler = new GetCourseUserStatsQueryHandler(new UnitOfWork(context));
            var request = new GetCourseUserStatsRequestModel
            {
                UserId = Guid.NewGuid()
            };

            var response = await handler.Handle(request, CancellationToken.None);

            response.StatsForCourses.Should().BeEmpty();
        }