public async Task <IActionResult> GetAllCoursesProgresses([FromQuery] string userId)
        {
            if (!User.IsInRole("Client") || string.IsNullOrEmpty(userId))
            {
                userId = User.GetId();
            }

            var result = await progressRepository.GetAllByUserAsync(userId);

            return(Ok(result));
        }
示例#2
0
        public void GetByLoginTest()
        {
            var user = new UserData {
                Login = "******", Id = "123"
            };

            var currentUserProgresses = new[]
            {
                new CourseProgressData {
                    Id = $"{user.Login}{123}", LessonProgresses = new List <LessonProgressData>()
                },
                new CourseProgressData {
                    Id = $"{user.Login}{124}", LessonProgresses = new List <LessonProgressData>()
                },
                new CourseProgressData {
                    Id = $"{user.Login}{125}", LessonProgresses = new List <LessonProgressData>()
                },
            };

            var otherProgresses = new[]
            {
                new CourseProgressData {
                    Id = "someid1", LessonProgresses = new List <LessonProgressData>()
                },
                new CourseProgressData {
                    Id = "someid2", LessonProgresses = new List <LessonProgressData>()
                },
                new CourseProgressData {
                    Id = "someid3", LessonProgresses = new List <LessonProgressData>()
                }
            };

            progressRepositoryDbContext.Collection.InsertMany(currentUserProgresses);
            progressRepositoryDbContext.Collection.InsertMany(otherProgresses);

            var result = progressRepository.GetAllByUserAsync(user.Id).Result.ToList();

            var compareLogic = new CompareLogic
            {
                Config =
                {
                    IgnoreCollectionOrder = true,
                    IgnoreObjectTypes     = true
                }
            };

            var compareResult = compareLogic.Compare(currentUserProgresses, result);

            Assert.IsTrue(compareResult.AreEqual);
        }