Ejemplo n.º 1
0
        protected IActionResult CommandResult(CommandExecutionResult result, ResultStatusCode resultStatusCode)
        {
            if (result.Success)
            {
                return resultStatusCode switch
                       {
                           ResultStatusCode.Created => Created("", result.Data),
                           ResultStatusCode.Updated => Ok(result.Data),
                           ResultStatusCode.Deleted => NoContent(),
                           ResultStatusCode.Patched => Ok(result.Data),
                           _ => BadRequest(),
                       }
            }
            ;

            if (result.ErrorCode == ErrorCode.NotFound)
            {
                return(NotFound());
            }

            return(BadRequest(result.Errors));
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Result"/> class, using the provided status code
 /// and value.
 /// </summary>
 /// <param name="status">The status code of the result.</param>
 /// <param name="value">The result value.</param>
 public Result(ResultStatusCode status, object value)
     : this(status)
 {
     this.Value = value;
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Result"/> class, using the provided status code.
 /// </summary>
 /// <param name="status">The status code of the result.</param>
 public Result(ResultStatusCode status)
 {
     this.Status = status;
 }
Ejemplo n.º 4
0
        public async Task Scrap_WhenRequestReturnSomeError_ReturnsIt(HttpStatusCode status, ResultStatusCode expected)
        {
            // Arrange
            var message     = "some error message";
            var mockHttp    = _testHelper.CreateMockHttp(HttpMethod.Get, message, status);
            var githubScrap = new GitHubScrap(mockHttp);

            var param = new GitHubInItem
            {
                Location = new List <string>
                {
                    "São Paulo",
                },
                Language = new List <string>
                {
                    "C#",
                }
            };

            // Act
            var result = await githubScrap.Scrap(param, CancellationToken.None);

            // Assert
            Assert.NotNull(result);
            Assert.Equal(expected, result.Status);
            Assert.Equal(message, result.Value.ToString());
        }
Ejemplo n.º 5
0
 public void SetError(string msg, Exception ex)
 {
     this.ErrorMsg = msg;
     this.Error = ex;
     this.StatusCode = ResultStatusCode.Error;
 }
Ejemplo n.º 6
0
 public ErrorResult(ResultStatusCode statusCode, IEnumerable <ValidationError> errors) : base(statusCode)
 {
     Errors = errors;
 }
Ejemplo n.º 7
0
 public ErrorResult(ResultStatusCode statusCode, ValidationError error) : base(statusCode)
 {
     Errors = new[] { error };
 }
Ejemplo n.º 8
0
 public Result(ResultStatusCode status, object value)
 {
     Status         = status;
     Value          = value;
     ValueAsSuccess = (T)value;
 }
Ejemplo n.º 9
0
 public MethodResult(ResultStatusCode status)
 {
     Status = status;
 }