Exemple #1
0
        public async void DeleteUserAsNonAdminTest()
        {
            // create user
            await this.userRepository.CreateAsync(UserFactory.CreateNormalUser(2000));

            // database should contain 1 user
            Assert.Single(await this.userRepository.ListAsync());

            HttpRequest request = HttpRequestFactory.CreateDeleteRequest();

            ObjectResult resultUser = (ObjectResult)await this.userController.UserDelete(request, 2000, this.userClaim);

            ObjectResult resultOrganiser = (ObjectResult)await this.userController.UserDelete(request, 2000, 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 non admin user can only edit or delete own account
            Assert.Equal(ErrorCode.UNAUTHORIZED_TO_DELETE_USER, errorMessageUser.ErrorCodeEnum);
            Assert.Equal(ErrorCode.UNAUTHORIZED_TO_DELETE_USER, errorMessageOrganiser.ErrorCodeEnum);
            // database should still contain 1 user
            Assert.Single(await this.userRepository.ListAsync());
        }
Exemple #2
0
        public async void DeleteLocationAsAdminTest()
        {
            // create location
            await this.locationRepository.CreateAsync(LocationFactory.CreateLocation(9000));

            // create delete request
            HttpRequest deleteRequest = HttpRequestFactory.CreateDeleteRequest();

            OkResult result = (OkResult)await this.locationController.LocationDelete(deleteRequest, 9000, this.adminClaim);

            // status code should be 200 OK
            Assert.Equal(200, result.StatusCode);
            // the account should be removed
            Assert.Empty(await this.locationRepository.ListAsync());
        }
Exemple #3
0
        public async void DeleteLocationAsAdminNotFoundTest()
        {
            // create location
            await this.locationRepository.CreateAsync(LocationFactory.CreateLocation(9000));

            // create delete request
            HttpRequest deleteRequest = HttpRequestFactory.CreateDeleteRequest();

            ObjectResult result = (ObjectResult)await this.locationController.LocationDelete(deleteRequest, 1, this.adminClaim);

            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);
        }
        public async void DeleteComponentAsAdminTest()
        {
            //create location and component
            Location location = await this.locationRepository.CreateAsync(LocationFactory.CreateLocation(1));

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

            // create delete request
            HttpRequest deleteRequest = HttpRequestFactory.CreateDeleteRequest();

            OkResult result = (OkResult)await this.componentController.ComponentDelete(deleteRequest, 1, 1, this.adminClaim);

            // status code should be 200 OK
            Assert.Equal(200, result.StatusCode);
            // the account should be removed
            Assert.Empty(await this.componentRepository.ListAsync());
        }
        public async void DeleteComponentAsAdminNotFoundTest()
        {
            //create location and component
            Location location = await this.locationRepository.CreateAsync(LocationFactory.CreateLocation(1));

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

            // create delete request
            HttpRequest deleteRequest = HttpRequestFactory.CreateDeleteRequest();

            ObjectResult result = (ObjectResult)await this.componentController.ComponentDelete(deleteRequest, 1, 5, this.adminClaim);

            ErrorResponse errorResponse = (ErrorResponse)result.Value;

            // status code should be 404 not found
            Assert.Equal(404, result.StatusCode);
            Assert.Equal(ErrorCode.COMPONENT_NOT_FOUND, errorResponse.ErrorCodeEnum);
        }
Exemple #6
0
        public async void DeleteUserAsAdminTest()
        {
            // create user
            await this.userRepository.CreateAsync(UserFactory.CreateNormalUser(2000));

            // database should contain 1 user
            Assert.Single(await this.userRepository.ListAsync());

            // create delete request
            HttpRequest request = HttpRequestFactory.CreateDeleteRequest();

            StatusCodeResult result = (StatusCodeResult)await this.userController.UserDelete(request, 2000, this.adminClaim);

            // status code should be 200 OK
            Assert.Equal(200, result.StatusCode);
            // the account should be removed
            Assert.Empty(await this.userRepository.ListAsync());
        }
Exemple #7
0
        public async void DeleteLocationAsNonAdminTest()
        {
            // create location
            await this.locationRepository.CreateAsync(LocationFactory.CreateLocation(9000));

            // create delete request
            HttpRequest deleteRequest = HttpRequestFactory.CreateDeleteRequest();

            ObjectResult resultUser = (ObjectResult)await this.locationController.LocationDelete(deleteRequest, 9000, this.userClaim);

            ObjectResult resultOrganiser = (ObjectResult)await this.locationController.LocationDelete(deleteRequest, 9000, 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);

            Assert.Equal(ErrorCode.UNAUTHORIZED_ROLE_NO_PERMISSIONS, errorMessageUser.ErrorCodeEnum);
            Assert.Equal(ErrorCode.UNAUTHORIZED_ROLE_NO_PERMISSIONS, errorMessageOrganiser.ErrorCodeEnum);
        }