public async Task <string> Execute(AddResouceSetParameter addResourceSetParameter)
        {
            var json = addResourceSetParameter == null ? string.Empty : JsonConvert.SerializeObject(addResourceSetParameter);

            _umaServerEventSource.StartToAddResourceSet(json);
            if (addResourceSetParameter == null)
            {
                throw new ArgumentNullException(nameof(addResourceSetParameter));
            }

            var resourceSet = new ResourceSet
            {
                Id      = Guid.NewGuid().ToString(),
                Name    = addResourceSetParameter.Name,
                Uri     = addResourceSetParameter.Uri,
                Type    = addResourceSetParameter.Type,
                Scopes  = addResourceSetParameter.Scopes,
                IconUri = addResourceSetParameter.IconUri
            };

            _resourceSetParameterValidator.CheckResourceSetParameter(resourceSet);
            if (!await _resourceSetRepository.Insert(resourceSet))
            {
                throw new BaseUmaException(ErrorCodes.InternalError,
                                           ErrorDescriptions.TheResourceSetCannotBeInserted);
            }

            _umaServerEventSource.FinishToAddResourceSet(JsonConvert.SerializeObject(resourceSet));
            return(resourceSet.Id);
        }
Пример #2
0
        public async Task When_ResourceSet_Is_Inserted_Then_Id_Is_Returned()
        {
            // ARRANGE
            InitializeFakeObjects();
            var addResourceParameter = new AddResouceSetParameter
            {
                Name   = "name",
                Scopes = new List <string> {
                    "scope"
                },
                IconUri = "http://localhost",
                Uri     = "http://localhost"
            };

            _resourceSetRepositoryStub.Setup(r => r.Insert(It.IsAny <ResourceSet>()))
            .Returns(Task.FromResult(true));

            // ACT
            var result = await _addResourceSetAction.Execute(addResourceParameter);

            // ASSERTS
            Assert.NotNull(result);
        }
Пример #3
0
        public async Task When_Resource_Set_Cannot_Be_Inserted_Then_Exception_Is_Thrown()
        {
            // ARRANGE
            InitializeFakeObjects();
            var addResourceParameter = new AddResouceSetParameter
            {
                Name   = "name",
                Scopes = new List <string> {
                    "scope"
                },
                IconUri = "http://localhost",
                Uri     = "http://localhost"
            };

            _resourceSetRepositoryStub.Setup(r => r.Insert(It.IsAny <ResourceSet>()))
            .Returns(() => Task.FromResult(false));

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

            Assert.NotNull(exception);
            Assert.True(exception.Code == ErrorCodes.InternalError);
            Assert.True(exception.Message == ErrorDescriptions.TheResourceSetCannotBeInserted);
        }
Пример #4
0
 public Task <string> AddResourceSet(AddResouceSetParameter addResouceSetParameter)
 {
     return(_addResourceSetAction.Execute(addResouceSetParameter));
 }