public async void GetAllEventsTest()
        {
            //Create 1 location using the locationFactory
            Location locationTest = await this.locationRepository.CreateAsync(LocationFactory.CreateLocation(1));

            //Create 2 Events using the eventFactory
            Event event1 = await this.eventRepository.CreateAsync(EventFactory.CreateEvent(1, 1, 1));

            Event event2 = await this.eventRepository.CreateAsync(EventFactory.CreateEvent(2, 1, 1));

            var test = await this.eventRepository.ListAsync();

            HttpRequest request = HttpRequestFactory.CreateGetRequest();

            ObjectResult result = (ObjectResult)await eventController.LocationGetEvents(request, locationTest.Id);

            List <EventResponse> events = (List <EventResponse>)result.Value;

            // Status code should return 200 OK
            Assert.Equal(200, result.StatusCode);
            // Count of events should equal 2
            Assert.Equal(2, events.Count);

            //Check if organisorId is the same for both
            Assert.Equal(1, event1.OrganisorId);
            Assert.Equal(1, event2.OrganisorId);
        }
        public async void GetAllComponentsByLocationIdTest()
        {
            Location location1 = await this.locationRepository.CreateAsync(LocationFactory.CreateLocation(1));

            Location location2 = await this.locationRepository.CreateAsync(LocationFactory.CreateLocation(2));

            // create components for location 1
            await this.componentRepository.CreateAsync(ComponentFactory.CreateComponent(1, location1));

            await this.componentRepository.CreateAsync(ComponentFactory.CreateComponent(2, location1));

            await this.componentRepository.CreateAsync(ComponentFactory.CreateComponent(3, location1));

            //create components for location 2
            await this.componentRepository.CreateAsync(ComponentFactory.CreateComponent(4, location2));

            await this.componentRepository.CreateAsync(ComponentFactory.CreateComponent(5, location2));

            HttpRequest request = HttpRequestFactory.CreateGetRequest();

            //get all components location 1
            ObjectResult result = (ObjectResult)await this.componentController.ComponentsGetAll(request, 1);

            List <Component> components = (List <Component>)result.Value;

            // status code should be 200 OK
            Assert.Equal(200, result.StatusCode);
            // amount of found locations should be 3 for location 1
            Assert.Equal(3, components.Count);
        }
예제 #3
0
        public async void GetOneUserAsAdminNotFoundTest()
        {
            HttpRequest request = HttpRequestFactory.CreateGetRequest();

            ObjectResult result = (ObjectResult)await this.userController.UsersGet(request, 1000, this.adminClaim);

            ErrorResponse errorResponse = (ErrorResponse)result.Value;

            // status code should be 200 OK
            Assert.Equal(404, result.StatusCode);
            // check if error response is user not found
            Assert.Equal(ErrorCode.USER_NOT_FOUND, errorResponse.ErrorCodeEnum);
        }
예제 #4
0
        public async void GetSpecificLocationNotFoundTest()
        {
            await this.locationRepository.CreateAsync(LocationFactory.CreateLocation(10));

            HttpRequest request = HttpRequestFactory.CreateGetRequest();

            ObjectResult result = (ObjectResult)await this.locationController.LocationGet(request, 5);

            ErrorResponse errorResponse = (ErrorResponse)result.Value;

            // status code should be 404 not found
            Assert.Equal(404, result.StatusCode);
            Assert.Equal(ErrorCode.LOCATION_NOT_FOUND, errorResponse.ErrorCodeEnum);
        }
예제 #5
0
        public async void GetSpecificLocationTest()
        {
            await this.locationRepository.CreateAsync(LocationFactory.CreateLocation(10));

            HttpRequest request = HttpRequestFactory.CreateGetRequest();

            ObjectResult result = (ObjectResult)await this.locationController.LocationGet(request, 10);

            Location location = (Location)result.Value;

            // status code should be 200 OK
            Assert.Equal(200, result.StatusCode);
            // check if the right location was found
            Assert.Equal(10, location.Id);
        }
예제 #6
0
        public async void GetOneUserAsAdminTest()
        {
            // add user to database
            await this.userRepository.CreateAsync(UserFactory.CreateNormalUser(1000));

            HttpRequest request = HttpRequestFactory.CreateGetRequest();

            ObjectResult result = (ObjectResult)await this.userController.UsersGet(request, 1000, this.adminClaim);

            UserResponse user = (UserResponse)result.Value;

            // status code should be 200 OK
            Assert.Equal(200, result.StatusCode);
            // check if the right user was found
            Assert.Equal(1000, user.Id);
        }
        public async void GetSpecificComponentNotFoundTest()
        {
            Location location1 = await this.locationRepository.CreateAsync(LocationFactory.CreateLocation(1));

            await this.componentRepository.CreateAsync(ComponentFactory.CreateComponent(1, location1));

            HttpRequest request = HttpRequestFactory.CreateGetRequest();

            ObjectResult result = (ObjectResult)await this.componentController.ComponentsGetById(request, 1, 5);

            ErrorResponse errorResponse = (ErrorResponse)result.Value;

            // status code should be 200 OK
            Assert.Equal(404, result.StatusCode);
            // should return component not found errorresponse
            Assert.Equal(ErrorCode.COMPONENT_NOT_FOUND, errorResponse.ErrorCodeEnum);
        }
        public async void GetSpecificComponentTest()
        {
            Location location1 = await this.locationRepository.CreateAsync(LocationFactory.CreateLocation(1));

            await this.componentRepository.CreateAsync(ComponentFactory.CreateComponent(1, location1));

            await this.componentRepository.CreateAsync(ComponentFactory.CreateComponent(2, location1));

            HttpRequest request = HttpRequestFactory.CreateGetRequest();

            ObjectResult result = (ObjectResult)await this.componentController.ComponentsGetById(request, 1, 1);

            ComponentResponse component = (ComponentResponse)result.Value;

            // status code should be 200 OK
            Assert.Equal(200, result.StatusCode);
            // check if the right location was found
            Assert.Equal(1, component.Id);
        }
예제 #9
0
        public async void GetAllLocationsTest()
        {
            await this.locationRepository.CreateAsync(LocationFactory.CreateLocation(1));

            await this.locationRepository.CreateAsync(LocationFactory.CreateLocation(2));

            await this.locationRepository.CreateAsync(LocationFactory.CreateLocation(3));

            HttpRequest request = HttpRequestFactory.CreateGetRequest();

            ObjectResult result = (ObjectResult)await this.locationController.LocationGetAll(request);

            List <Location> locations = (List <Location>)result.Value;

            // status code should be 200 OK
            Assert.Equal(200, result.StatusCode);
            // amount of found locations should be 3
            Assert.Equal(3, locations.Count);
        }
        public async void GetLocationEvent()
        {
            //Create 1 location using the locationFactory
            Location locationTest = await this.locationRepository.CreateAsync(LocationFactory.CreateLocation(1));

            //Create 2 Events using the eventFactory
            Event event1 = await this.eventRepository.CreateAsync(EventFactory.CreateEvent(1, 1, 1));

            HttpRequest request = HttpRequestFactory.CreateGetRequest();

            ObjectResult result = (ObjectResult)await eventController.LocationGetEvent(request, locationTest.Id, event1.Id);

            EventResponse eventResult = (EventResponse)result.Value;

            // Status code should return 200 OK
            Assert.Equal(200, result.StatusCode);

            //Check if organisorId is the same for both
            //Assert.Equal(1, eventResult.Organisor);
        }
예제 #11
0
        public async void GetWorkoutWithoutMovementformsQueryParameterTest()
        {
            FillDatabase();

            // create query parameters
            Dictionary <string, StringValues> query = new Dictionary <string, StringValues>
            {
                { "amount", "5" }
            };

            HttpRequest request = HttpRequestFactory.CreateGetRequest(query);

            ObjectResult result = (ObjectResult)await this.workoutController.WorkoutGenerate(request);

            List <ExerciseResponse> exercises = (List <ExerciseResponse>)result.Value;

            // status code should be 200 OK
            Assert.Equal(200, result.StatusCode);
            // amount of found exercises should be 5
            Assert.Equal(5, exercises.Count);
        }
예제 #12
0
        public async void GetWorkoutAmountShouldBeBetweenOneAndFiveTest(int amount, int expected)
        {
            FillDatabase();

            // create query parameters
            Dictionary <string, StringValues> query = new Dictionary <string, StringValues>
            {
                { "amount", amount.ToString() },
                { "movementforms", "" }
            };

            HttpRequest request = HttpRequestFactory.CreateGetRequest(query);

            ObjectResult result = (ObjectResult)await this.workoutController.WorkoutGenerate(request);

            List <ExerciseResponse> exercises = (List <ExerciseResponse>)result.Value;

            // status code should be 200 OK
            Assert.Equal(200, result.StatusCode);
            // amount of found exercises should be the expected
            Assert.Equal(expected, exercises.Count);
        }
예제 #13
0
        public async void GetWorkoutWithInvalidMovementFormTest(string movementforms)
        {
            FillDatabase();

            // create query parameters
            Dictionary <string, StringValues> query = new Dictionary <string, StringValues>
            {
                { "amount", "2" },
                { "movementforms", movementforms }
            };

            HttpRequest request = HttpRequestFactory.CreateGetRequest(query);

            ObjectResult result = (ObjectResult)await this.workoutController.WorkoutGenerate(request);

            ErrorResponse errorResponse = (ErrorResponse)result.Value;

            // status code should be 400 BAD REQUEST
            Assert.Equal(400, result.StatusCode);
            // error code must be invalid movement form provided
            Assert.Equal(ErrorCode.INVALID_MOVEMENT_FORM_PROVIDED, errorResponse.ErrorCodeEnum);
        }
예제 #14
0
        public async void GetAllUsersAsNonAdminTest()
        {
            // add user to database
            await this.userRepository.CreateAsync(UserFactory.CreateNormalUser());

            HttpRequest request = HttpRequestFactory.CreateGetRequest();

            ObjectResult resultUser = (ObjectResult)await this.userController.UsersGetAll(request, this.organiserClaim);

            ObjectResult resultOrganiser = (ObjectResult)await this.userController.UsersGetAll(request, this.organiserClaim);

            ErrorResponse errorMessageUser      = (ErrorResponse)resultUser.Value;
            ErrorResponse errorMessageOrganiser = (ErrorResponse)resultOrganiser.Value;

            // status code should be 403 FORBIDDEN
            Assert.Equal(403, resultUser.StatusCode);
            Assert.Equal(403, resultOrganiser.StatusCode);

            // error code must be unauthorized because role has no permissions
            Assert.Equal(ErrorCode.UNAUTHORIZED_ROLE_NO_PERMISSIONS, errorMessageUser.ErrorCodeEnum);
            Assert.Equal(ErrorCode.UNAUTHORIZED_ROLE_NO_PERMISSIONS, errorMessageOrganiser.ErrorCodeEnum);
        }
예제 #15
0
        public async void GetOneUserAsUserTest()
        {
            // add user to database
            await this.userRepository.CreateAsync(UserFactory.CreateNormalUser(4));

            await this.userRepository.CreateAsync(UserFactory.CreateNormalUser(1000));

            HttpRequest request = HttpRequestFactory.CreateGetRequest();

            ObjectResult resultAuthorized = (ObjectResult)await this.userController.UsersGet(request, 4, this.userClaim);

            ObjectResult resultNotAuthorized = (ObjectResult)await this.userController.UsersGet(request, 1000, this.userClaim);

            UserResponse user = (UserResponse)resultAuthorized.Value;

            // status code should be 200 OK
            Assert.Equal(200, resultAuthorized.StatusCode);
            // status code should be 403 FORBIDDEN
            Assert.Equal(403, resultNotAuthorized.StatusCode);
            // check if the right user was found
            Assert.Equal(4, user.Id);
        }
예제 #16
0
        public async void GetAllUsersAsAdminTest()
        {
            // add 3 different users to database
            await this.userRepository.CreateAsync(UserFactory.CreateNormalUser());

            await this.userRepository.CreateAsync(UserFactory.CreateOrganiserUser());

            await this.userRepository.CreateAsync(UserFactory.CreateAdminUser());

            HttpRequest request = HttpRequestFactory.CreateGetRequest();

            ObjectResult result = (ObjectResult)await this.userController.UsersGetAll(request, this.adminClaim);

            List <UserResponse> users = (List <UserResponse>)result.Value;

            // status code should be 200 OK
            Assert.Equal(200, result.StatusCode);
            // amount of found users should be 3
            Assert.Equal(3, users.Count);
            // check the account type of the users
            Assert.True(users[0].Type == UserType.User);
            Assert.True(users[1].Type == UserType.Organiser);
            Assert.True(users[2].Type == UserType.Admin);
        }
예제 #17
0
        public async void GetWorkoutWithSpecificMovementFormsTest()
        {
            FillDatabase(false);

            List <Exercise> exercisestest = await this.exerciseRepository.ListAsync();

            // create query parameters
            Dictionary <string, StringValues> query = new Dictionary <string, StringValues>
            {
                { "amount", "5" },
                { "movementforms", "balans|mikken" }
            };

            HttpRequest request = HttpRequestFactory.CreateGetRequest(query);

            ObjectResult result = (ObjectResult)await this.workoutController.WorkoutGenerate(request);

            List <ExerciseResponse> exercises = (List <ExerciseResponse>)result.Value;

            // status code should be 200 OK
            Assert.Equal(200, result.StatusCode);
            // amount of found exercises should be 3
            Assert.Equal(3, exercises.Count);
        }