public void Should_RepositoryGetAllExercises_BeCalled_WhenServiceGetAllExercisesCalled()
        {
            var exerciseRepo     = new Mock <IExerciseRepository>();
            var exerciseTypeRepo = new Mock <IExerciseTypeRepository>();
            var mapper           = new Mock <IMapper>();

            var objectUnderTest = new ExerciseService(exerciseRepo.Object, exerciseTypeRepo.Object, mapper.Object);

            var result = objectUnderTest.GetAllExercises(1, 1, string.Empty);

            exerciseRepo.Verify(r => r.GetAllExercises(), Times.Once);
        }
Esempio n. 2
0
        public async Task <IActionResult> ExercisesGetAll(
            [HttpTrigger(AuthorizationLevel.User, "get", Route = "exercises")] HttpRequest req,
            [SwaggerIgnore] ClaimsPrincipal userClaim)
        {
            // user must be admin
            if (!userClaim.IsInRole(UserType.Admin.ToString()))
            {
                return(ForbiddenObjectResult.Create(new ErrorResponse(ErrorCode.UNAUTHORIZED_ROLE_NO_PERMISSIONS)));
            }

            // get list of exercises
            List <ExerciseResponse> exercises = await exerciseService.GetAllExercises();

            return(new OkObjectResult(exercises));
        }
        public void Should_GetAllExercises_ReturnCorrectList_WhenRepoProvidesCorrectExercises()
        {
            var exercises = new List <Exercise>()
            {
                new Exercise()
                {
                    Id = 1, Name = "dummy 1", ExerciseTypeId = 1, ExerciseType = new ExerciseType()
                    {
                        Id = 1, Name = "dummy"
                    }
                },
                new Exercise()
                {
                    Id = 2, Name = "dummy 2", ExerciseTypeId = 1, ExerciseType = new ExerciseType()
                    {
                        Id = 1, Name = "dummy"
                    }
                },
                new Exercise()
                {
                    Id = 3, Name = "dummy 3", ExerciseTypeId = 1, ExerciseType = new ExerciseType()
                    {
                        Id = 2, Name = "dummy 2"
                    }
                },
                new Exercise()
                {
                    Id = 4, Name = "dummy 4", ExerciseTypeId = 1, ExerciseType = new ExerciseType()
                    {
                        Id = 2, Name = "dummy 2"
                    }
                }
            };

            var expectedExerciseList = new List <ExerciseForListVm>()
            {
                new ExerciseForListVm()
                {
                    Id = 1, Name = "dummy 1", ExerciseTypeName = "dummy"
                },
                new ExerciseForListVm()
                {
                    Id = 2, Name = "dummy 2", ExerciseTypeName = "dummy"
                },
                new ExerciseForListVm()
                {
                    Id = 3, Name = "dummy 3", ExerciseTypeName = "dummy 2"
                },
                new ExerciseForListVm()
                {
                    Id = 4, Name = "dummy 4", ExerciseTypeName = "dummy 2"
                }
            };

            var expectedResult = new ListForExerciseListVm()
            {
                ListExercisesForList = expectedExerciseList,
                Count        = 4,
                CurrentPage  = 1,
                PageSize     = 4,
                SearchString = ""
            };

            var exercisesQuery   = exercises.AsQueryable();
            var exerciseRepo     = new Mock <IExerciseRepository>();
            var exerciseTypeRepo = new Mock <IExerciseTypeRepository>();
            var mapper           = new Mock <IMapper>();

            exerciseRepo.Setup(r => r.GetAllExercises()).Returns(exercisesQuery);


            var objectUnderTest = new ExerciseService(exerciseRepo.Object, exerciseTypeRepo.Object, mapper.Object);

            var result = objectUnderTest.GetAllExercises(4, 1, string.Empty);

            Assert.True(AreListsForExerciseTypesEqual(result, expectedResult));
        }
Esempio n. 4
0
 public string GetExercises()
 {
     return(JsonSerializer.Serialize(service.GetAllExercises()));
 }
        public IHttpActionResult ReadEx()
        {
            var result = _exerciseService.GetAllExercises();

            return(ResponseMessage(CreateCustomResponseMessage(result)));
        }