public async Task <bool> Execute(UpdateResourceSetParameter udpateResourceSetParameter)
        {
            if (udpateResourceSetParameter == null)
            {
                throw new ArgumentNullException(nameof(udpateResourceSetParameter));
            }

            if (await _resourceSetRepository.Get(udpateResourceSetParameter.Id) == null)
            {
                return(false);
            }

            var resourceSet = new ResourceSet
            {
                Id      = udpateResourceSetParameter.Id,
                Name    = udpateResourceSetParameter.Name,
                Uri     = udpateResourceSetParameter.Uri,
                Type    = udpateResourceSetParameter.Type,
                Scopes  = udpateResourceSetParameter.Scopes,
                IconUri = udpateResourceSetParameter.IconUri
            };

            _resourceSetParameterValidator.CheckResourceSetParameter(resourceSet);
            if (!await _resourceSetRepository.Update(resourceSet))
            {
                throw new BaseUmaException(
                          ErrorCodes.InternalError,
                          string.Format(ErrorDescriptions.TheResourceSetCannotBeUpdated, resourceSet.Id));
            }

            return(true);
        }
        public async Task When_A_ResourceSet_Is_Updated_Then_True_Is_Returned()
        {
            // ARRANGE
            const string id = "id";

            InitializeFakeObjects();
            var udpateResourceSetParameter = new UpdateResourceSetParameter
            {
                Id = id
            };
            var resourceSet = new ResourceSet
            {
                Id = id
            };

            _resourceSetRepositoryStub.Setup(r => r.Get(It.IsAny <string>()))
            .Returns(Task.FromResult(resourceSet));
            _resourceSetRepositoryStub.Setup(r => r.Update(It.IsAny <ResourceSet>()))
            .Returns(Task.FromResult(true));

            // ACT
            var result = await _updateResourceSetAction.Execute(udpateResourceSetParameter);

            // ASSERTS
            Assert.NotNull(result);
            Assert.True(result);
        }
        public async Task When_ResourceSet_Cannot_Be_Updated_Then_Exception_Is_Thrown()
        {
            // ARRANGE
            InitializeFakeObjects();
            const string id = "id";
            var          udpateResourceSetParameter = new UpdateResourceSetParameter
            {
                Id = id
            };
            var resourceSet = new ResourceSet
            {
                Id = id
            };

            _resourceSetRepositoryStub.Setup(r => r.Get(It.IsAny <string>()))
            .Returns(Task.FromResult(resourceSet));
            _resourceSetRepositoryStub.Setup(r => r.Update(It.IsAny <ResourceSet>()))
            .Returns(() => Task.FromResult(false));

            // ACT & ASSERTS
            var exception = await Assert.ThrowsAsync <BaseUmaException>(() => _updateResourceSetAction.Execute(udpateResourceSetParameter));

            Assert.NotNull(exception);
            Assert.True(exception.Code == ErrorCodes.InternalError);
            Assert.True(exception.Message == string.Format(ErrorDescriptions.TheResourceSetCannotBeUpdated, udpateResourceSetParameter.Id));
        }
Пример #4
0
        public async Task <bool> Execute(UpdateResourceSetParameter udpateResourceSetParameter)
        {
            if (udpateResourceSetParameter == null)
            {
                throw new ArgumentNullException(nameof(udpateResourceSetParameter));
            }

            var json = JsonConvert.SerializeObject(udpateResourceSetParameter);

            _umaServerEventSource.StartToUpdateResourceSet(json);
            var resourceSet = new ResourceSet
            {
                Id      = udpateResourceSetParameter.Id,
                Name    = udpateResourceSetParameter.Name,
                Uri     = udpateResourceSetParameter.Uri,
                Type    = udpateResourceSetParameter.Type,
                Scopes  = udpateResourceSetParameter.Scopes,
                IconUri = udpateResourceSetParameter.IconUri,
                Owner   = udpateResourceSetParameter.Owner,
                AcceptPendingRequest = udpateResourceSetParameter.AcceptPendingRequest
            };

            if (string.IsNullOrWhiteSpace(udpateResourceSetParameter.Id))
            {
                throw new BaseUmaException(ErrorCodes.InvalidRequestCode, string.Format(ErrorDescriptions.TheParameterNeedsToBeSpecified, "id"));
            }
            _resourceSetParameterValidator.CheckResourceSetParameter(resourceSet);
            if (await _resourceSetRepository.Get(udpateResourceSetParameter.Id) == null)
            {
                return(false);
            }

            if (!await _resourceSetRepository.Update(resourceSet))
            {
                throw new BaseUmaException(ErrorCodes.InternalError, string.Format(ErrorDescriptions.TheResourceSetCannotBeUpdated, resourceSet.Id));
            }

            _umaServerEventSource.FinishToUpdateResourceSet(json);
            return(true);
        }
Пример #5
0
 public Task <bool> UpdateResourceSet(UpdateResourceSetParameter updateResourceSetParameter)
 {
     return(_updateResourceSetAction.Execute(updateResourceSetParameter));
 }