public void When_Passing_Null_Parameter_Then_Exception_Is_Thrown()
        {
            // ARRANGE
            InitializeFakeObjects();

            // ACT & ASSERT
            Assert.Throws <ArgumentNullException>(() => _scopeParameterValidator.CheckScopeParameter(null));
        }
        public async Task <bool> Execute(AddScopeParameter addScopeParameter)
        {
            var json = addScopeParameter == null ? string.Empty : JsonConvert.SerializeObject(addScopeParameter);

            _umaServerEventSource.StartToAddScope(json);
            if (addScopeParameter == null)
            {
                throw new ArgumentNullException(nameof(addScopeParameter));
            }

            Scope scope = null;

            try
            {
                scope = await _scopeRepository.Get(addScopeParameter.Id);
            }
            catch (Exception ex)
            {
                throw new BaseUmaException(ErrorCodes.InternalError,
                                           ErrorDescriptions.TheScopeCannotBeRetrieved,
                                           ex);
            }

            if (scope != null)
            {
                throw new BaseUmaException(ErrorCodes.InvalidRequestCode,
                                           string.Format(ErrorDescriptions.TheScopeAlreadyExists, addScopeParameter.Id));
            }

            scope = new Scope
            {
                Id      = addScopeParameter.Id,
                IconUri = addScopeParameter.IconUri,
                Name    = addScopeParameter.Name
            };
            _scopeParameterValidator.CheckScopeParameter(scope);

            try
            {
                await _scopeRepository.Insert(scope);

                _umaServerEventSource.FinishToAddScope(json);
                return(true);
            }
            catch (Exception ex)
            {
                throw new BaseUmaException(ErrorCodes.InternalError,
                                           ErrorDescriptions.TheScopeCannotBeInserted,
                                           ex);
            }
        }
        public async Task <bool> Execute(UpdateScopeParameter updateScopeParameter)
        {
            if (updateScopeParameter == null)
            {
                throw new ArgumentNullException(nameof(updateScopeParameter));
            }

            Scope scope = null;

            try
            {
                scope = await _scopeRepository.Get(updateScopeParameter.Id);
            }
            catch (Exception ex)
            {
                throw new BaseUmaException(ErrorCodes.InternalError,
                                           ErrorDescriptions.TheScopeCannotBeRetrieved,
                                           ex);
            }

            if (scope == null)
            {
                return(false);
            }

            scope = new Scope
            {
                Id      = updateScopeParameter.Id,
                IconUri = updateScopeParameter.IconUri,
                Name    = updateScopeParameter.Name
            };
            _scopeParameterValidator.CheckScopeParameter(scope);

            try
            {
                await _scopeRepository.Update(scope);

                return(true);
            }
            catch (Exception ex)
            {
                throw new BaseUmaException(ErrorCodes.InternalError,
                                           ErrorDescriptions.TheScopeCannotBeUpdated,
                                           ex);
            }
        }