/// <inheritdoc /> public async Task <IExecutionResult> RemoveConstraintAsync(string indexName, string value) { if (!cache.ContainsKey(indexName)) { var customMessage = $"indexName: {indexName} not registered"; return(FailedResult.Create( CoreErrorCodes.UnhandledError, CoreErrorCodes.NameIsNotFound, customMessage)); } if (!cache[indexName].Contains(value)) { var customMessage = $"no such value: {value} for indexName: {indexName}"; return(FailedResult.Create( CoreErrorCodes.UnhandledError, CoreErrorCodes.NameIsNotFound, customMessage)); } cache[indexName].Remove(value); return(await Task.FromResult(new SuccessfulResult())); }
public void CreateWithInternal_Creates_2LevelError() { var externalCode = new ErrorCodeInfo(nameof(Core), FixtureUtils.String(), FixtureUtils.String()); var internalCode = new ErrorCodeInfo(nameof(Core), FixtureUtils.String(), FixtureUtils.String()); var result = FailedResult.Create(externalCode, internalCode); result.Code.Should().Be(externalCode.Code); result.Message.Should().Be(externalCode.Message); var internalError = result.Details.Single(); internalError.Message.Should().Be(internalCode.Message); internalError.Code.Should().Be(internalCode.Code); }
/// <inheritdoc /> public async Task <IExecutionResult> ReserveConstraintAsync(string indexName, string value) { if (!cache.ContainsKey(indexName)) { cache.Add(indexName, new HashSet <string>()); } if (cache[indexName].Contains(value)) { var customMessage = $"value: {value} for indexName: {indexName} already exists"; return(FailedResult.Create( CoreErrorCodes.ValidationFailed, CoreErrorCodes.NameIsInUse, customMessage)); } cache[indexName].Add(value); return(await Task.FromResult(new SuccessfulResult())); }
/// <inheritdoc /> public async Task <IExecutionResult> UpdateConstraintAsync(string indexName, string oldValue, string newValue) { var updateOperation = new TableBatchOperation(); updateOperation.Delete(new UniqueTableEntity(indexName, oldValue)); updateOperation.Insert(new UniqueTableEntity(indexName, newValue)); try { await table.ExecuteBatchAsync(updateOperation); } catch (StorageException e) { switch (e.RequestInformation.ExtendedErrorInformation.ErrorCode) { case nameof(TableErrorCodeStrings.EntityAlreadyExists): var inUseMessage = $"The name '{newValue}' is already in use. Please enter another one."; return(FailedResult.Create( CoreErrorCodes.ValidationFailed, CoreErrorCodes.NameIsInUse, inUseMessage)); case nameof(StorageErrorCodeStrings.ResourceNotFound): var notInUseMessage = $"The name '{oldValue}' is not in use. Please enter another one."; return(FailedResult.Create( CoreErrorCodes.UnhandledError, CoreErrorCodes.NameIsNotFound, notInUseMessage)); case "InvalidDuplicateRow": // occures when new value duplicates old value then no error is needed return(new SuccessfulResult()); default: return(FailedResult.Create(CoreErrorCodes.UnhandledError, CoreErrorCodes.UpdateNameFailed)); } } return(new SuccessfulResult()); }
public void ForCommand_WithInnerDetails_ReturnsResultWithCorrectSource() { var internalCodeInfo = CoreErrorCodes.AggregateRootNotFound; var input = FailedResult.Create(CoreErrorCodes.ValidationFailed, internalCodeInfo); var result = input.ForCommand <TestCommand>(c => c.AggregateRootId); var failedResult = (FailedResult)result; failedResult.Source.Should().Be(nameof(TestCommand)); failedResult.Message.Should().Be(CoreErrorCodes.ValidationFailed.Message); failedResult.Code.Should().Be(CoreErrorCodes.ValidationFailed.Code); failedResult.CodeInfo.Should().BeEquivalentTo(CoreErrorCodes.ValidationFailed); var internalError = failedResult.Details.Single(); internalError.Source.Should().Be("TestCommand.AggregateRootId"); internalError.Message.Should().Be(internalCodeInfo.Message); internalError.Code.Should().Be(internalCodeInfo.Code); internalError.CodeInfo.Should().BeEquivalentTo(internalCodeInfo); }
/// <inheritdoc /> public async Task <IExecutionResult> ReserveConstraintAsync(string indexName, string value) { try { await table.ExecuteAsync(TableOperation.Insert(new UniqueTableEntity(indexName, value))); } catch (StorageException e) { var errorCode = e.RequestInformation.ExtendedErrorInformation.ErrorCode; if (TableErrorCodeStrings.EntityAlreadyExists.Equals(errorCode, StringComparison.InvariantCultureIgnoreCase)) { var customMessage = $"The name '{value}' is already in use. Please enter another one."; return(FailedResult.Create( CoreErrorCodes.ValidationFailed, CoreErrorCodes.NameIsInUse, customMessage)); } return(FailedResult.Create(CoreErrorCodes.UnhandledError, CoreErrorCodes.ReserveNameFailed)); } return(new SuccessfulResult()); }
/// <inheritdoc /> public async Task <IExecutionResult> RemoveConstraintAsync(string indexName, string value) { try { await table.ExecuteAsync(TableOperation.Delete(new UniqueTableEntity(indexName, value))); } catch (StorageException e) { var errorCode = e.RequestInformation.ExtendedErrorInformation.ErrorCode; if (StorageErrorCodeStrings.ResourceNotFound.Equals(errorCode, StringComparison.InvariantCultureIgnoreCase)) { var notInUseMessage = $"The name '{value}' is not in use. Please enter another one."; return(FailedResult.Create( CoreErrorCodes.UnhandledError, CoreErrorCodes.NameIsNotFound, notInUseMessage)); } return(FailedResult.Create(CoreErrorCodes.UnhandledError, CoreErrorCodes.DeleteNameFailed)); } return(new SuccessfulResult()); }
/// <inheritdoc /> public async Task <IExecutionResult> UpdateConstraintAsync(string indexName, string oldValue, string newValue) { if (!cache.ContainsKey(indexName)) { var notInUseMessage = $"indexName: {indexName} not registered"; return(FailedResult.Create( CoreErrorCodes.UnhandledError, CoreErrorCodes.NameIsNotFound, notInUseMessage)); } if (!cache[indexName].Contains(oldValue)) { var notInUseMessage = $"no such oldValue: {oldValue} for indexName: {indexName}"; return(FailedResult.Create( CoreErrorCodes.UnhandledError, CoreErrorCodes.NameIsNotFound, notInUseMessage)); } if (cache[indexName].Contains(newValue)) { var inUseMessage = $"newValue: {newValue} for indexName: {indexName} already exists"; return(FailedResult.Create( CoreErrorCodes.ValidationFailed, CoreErrorCodes.NameIsInUse, inUseMessage)); } cache[indexName].Remove(oldValue); cache[indexName].Add(newValue); return(await Task.FromResult(new SuccessfulResult())); }
/// <summary> /// Creates Validation Failed result with some internal error and custom message for it. /// </summary> /// <param name="codeInfo">Error code info about internal error.</param> /// <param name="customMessage">Custom message.</param> /// <returns>Execution result.</returns> protected static IExecutionResult ValidationFailed(ErrorCodeInfo codeInfo, string customMessage) { return(FailedResult.Create(CoreErrorCodes.ValidationFailed, codeInfo, customMessage)); }
/// <summary> /// Creates Validation Failed result with some internal error. /// </summary> /// <param name="codeInfo">Error code info about internal error.</param> /// <returns>Execution result.</returns> protected static IExecutionResult ValidationFailed(ErrorCodeInfo codeInfo) { return(FailedResult.Create(CoreErrorCodes.ValidationFailed, codeInfo)); }
/// <summary> /// Validation failed helper. /// </summary> /// <param name="internalCodeInfo">Error code info.</param> /// <param name="customMessage">Custom error message..</param> /// <returns>Failed Result.</returns> protected static FailedResult ValidationFailed(ErrorCodeInfo internalCodeInfo, string customMessage) { return(FailedResult.Create(CoreErrorCodes.ValidationFailed, internalCodeInfo, customMessage)); }
/// <summary> /// Access denied helper. /// </summary> /// <param name="internalCodeInfo">Error code info.</param> /// <returns>Failed Result.</returns> protected static FailedResult AccessDenied(ErrorCodeInfo internalCodeInfo) { return(FailedResult.Create(CoreErrorCodes.AccessDenied, internalCodeInfo)); }
/// <summary> /// Validation failed helper. /// </summary> /// <param name="internalCodeInfo">Error code info.</param> /// <returns>Failed Result.</returns> protected static FailedResult ValidationFailed(ErrorCodeInfo internalCodeInfo) { return(FailedResult.Create(CoreErrorCodes.ValidationFailed, internalCodeInfo)); }