public async Task When_Trying_To_Update_A_Not_Existed_Scope_Then_False_Is_Returned() { // ARRANGE InitializeFakeObjects(); var updateScopeParameter = new UpdateScopeParameter(); _scopeRepositoryStub.Setup(s => s.Get(It.IsAny <string>())) .Returns(Task.FromResult((Scope)null)); // ACT var result = await _updateScopeAction.Execute(updateScopeParameter); // ASSERT Assert.False(result); }
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); } }
public async Task When_A_Scope_Is_Updated_Then_True_Is_Returned() { // ARRANGE InitializeFakeObjects(); var updateScopeParameter = new UpdateScopeParameter(); _scopeRepositoryStub.Setup(s => s.Get(It.IsAny <string>())) .Returns(Task.FromResult(new Scope())); _scopeRepositoryStub.Setup(s => s.Insert(It.IsAny <Scope>())) .Returns(Task.FromResult(true)); // ACT var result = await _updateScopeAction.Execute(updateScopeParameter); // ASSERT Assert.True(result); }
public async Task When_An_Error_Occured_While_Retrieving_Scope_Then_Exception_Is_Thrown() { // ARRANGE InitializeFakeObjects(); var updateScopeParameter = new UpdateScopeParameter(); _scopeRepositoryStub.Setup(s => s.Get(It.IsAny <string>())) .Callback(() => { throw new Exception(); }); // ACT & ASSERTS var exception = await Assert.ThrowsAsync <BaseUmaException>(() => _updateScopeAction.Execute(updateScopeParameter)); Assert.NotNull(exception); Assert.True(exception.Code == ErrorCodes.InternalError); Assert.True(exception.Message == ErrorDescriptions.TheScopeCannotBeRetrieved); }
public Task <bool> UpdateScope(UpdateScopeParameter updateScopeParameter) { return(_updateScopeAction.Execute(updateScopeParameter)); }