public async Task When_ResourceSet_Doesnt_Exist_Then_Exception_Is_Thrown() { // ARRANGE const string clientId = "client_id"; const string resourceSetId = "resource_set_id"; InitializeFakeObjects(); var addPermissionParameter = new AddPermissionParameter { ResourceSetId = resourceSetId, Scopes = new List <string> { "scope" } }; _repositoryExceptionHelperStub.Setup(r => r.HandleException(It.IsAny <string>(), It.IsAny <Func <Task <IEnumerable <ResourceSet> > > >())) .Returns(Task.FromResult((IEnumerable <ResourceSet>) new List <ResourceSet>())); // ACT & ASSERTS var exception = await Assert.ThrowsAsync <BaseUmaException>(() => _addPermissionAction.Execute(clientId, addPermissionParameter)); Assert.NotNull(exception); Assert.True(exception.Code == ErrorCodes.InvalidResourceSetId); Assert.True(exception.Message == string.Format(ErrorDescriptions.TheResourceSetDoesntExist, resourceSetId)); }
public async Task When_RequiredParameter_ResourceSetId_Is_Not_Specified_Then_Exception_Is_Thrown() { // ARRANGE InitializeFakeObjects(); var addPermissionParameter = new AddPermissionParameter(); // ACT & ASSERTS var exception = await Assert.ThrowsAsync <BaseUmaException>(() => _addPermissionAction.Execute(new[] { "audience" }, addPermissionParameter)); Assert.NotNull(exception); Assert.True(exception.Code == ErrorCodes.InvalidRequestCode); Assert.True(exception.Message == string.Format(ErrorDescriptions.TheParameterNeedsToBeSpecified, Constants.AddPermissionNames.ResourceSetId)); }
public async Task <string> Execute(IEnumerable <string> audiences, AddPermissionParameter addPermissionParameter) { if (audiences == null) { throw new ArgumentNullException(nameof(audiences)); } if (addPermissionParameter == null) { throw new ArgumentNullException(nameof(addPermissionParameter)); } var result = await Execute(audiences, new[] { addPermissionParameter }); return(result); }
public async Task When_Adding_Permission_Then_TicketId_Is_Returned() { // ARRANGE const string clientId = "client_id"; const string resourceSetId = "resource_set_id"; InitializeFakeObjects(); var addPermissionParameter = new AddPermissionParameter { ResourceSetId = resourceSetId, Scopes = new List <string> { "scope" } }; IEnumerable <ResourceSet> resources = new List <ResourceSet> { new ResourceSet { Id = resourceSetId, Scopes = new List <string> { "scope" } } }; _ticketStoreStub.Setup(r => r.AddAsync(It.IsAny <Ticket>())).Returns(Task.FromResult(true)); _repositoryExceptionHelperStub.Setup(r => r.HandleException(It.IsAny <string>(), It.IsAny <Func <Task <IEnumerable <ResourceSet> > > >())) .Returns(Task.FromResult(resources)); _configurationServiceStub.Setup(c => c.GetTicketLifeTime()).Returns(Task.FromResult(2)); // ACT var result = await _addPermissionAction.Execute(clientId, addPermissionParameter); // ASSERTS Assert.NotEmpty(result); }
public async Task When_Scope_Doesnt_Exist_Then_Exception_Is_Thrown() { // ARRANGE const string resourceSetId = "resource_set_id"; InitializeFakeObjects(); var addPermissionParameter = new AddPermissionParameter { ResourceSetId = resourceSetId, Scopes = new List <string> { "invalid_scope" } }; IEnumerable <ResourceSet> resources = new List <ResourceSet> { new ResourceSet { Id = resourceSetId, Scopes = new List <string> { "scope" } } }; _repositoryExceptionHelperStub.Setup(r => r.HandleException(It.IsAny <string>(), It.IsAny <Func <Task <IEnumerable <ResourceSet> > > >())) .Returns(Task.FromResult(resources)); // ACT & ASSERTS var exception = await Assert.ThrowsAsync <BaseUmaException>(() => _addPermissionAction.Execute(new[] { "audience" }, addPermissionParameter)); Assert.NotNull(exception); Assert.True(exception.Code == ErrorCodes.InvalidScope); Assert.True(exception.Message == ErrorDescriptions.TheScopeAreNotValid); }
public async Task <string> Execute(string clientId, AddPermissionParameter addPermissionParameter) { var result = await Execute(clientId, new[] { addPermissionParameter }); return(result); }
public Task <string> Add(AddPermissionParameter addPermissionParameter, string clientId) { return(_addPermissionAction.Execute(clientId, addPermissionParameter)); }
public Task <string> Add(IEnumerable <string> audiences, AddPermissionParameter addPermissionParameter) { return(_addPermissionAction.Execute(audiences, addPermissionParameter)); }