コード例 #1
0
        public void ErrorHttpCode_Is_Honoured_in_Error_Response_Test(int?errorHttpCode, int expectedErrorHttpCode)
        {
            var defaultValue = ActionResultConventions.ErrorHttpCode;

            // GIVEN a custom HTTP code for errors
            if (errorHttpCode.HasValue)
            {
                ActionResultConventions.ErrorHttpCode = errorHttpCode.Value;
            }

            // WHEN a IDomainResult with Status 'Error' gets converted to ActionResult
            var domainResult = IDomainResult.Failed();
            var actionRes    = domainResult.ToActionResult() as ObjectResult;

            // THEN the HTTP code is expected
            Assert.Equal(expectedErrorHttpCode, actionRes !.StatusCode);

            ActionResultConventions.ErrorHttpCode = defaultValue;
        }
コード例 #2
0
        public void NotFoundHttpDetailsTitle_Is_Honoured_in_NotFound_Response_Test(string notFoundTitle, string expectedNotFoundTitle)
        {
            var defaultValue = ActionResultConventions.NotFoundProblemDetailsTitle;

            // GIVEN a custom HTTP code for errors
            if (!string.IsNullOrEmpty(notFoundTitle))
            {
                ActionResultConventions.NotFoundProblemDetailsTitle = notFoundTitle;
            }

            // WHEN a IDomainResult with Status 'Not Found' gets converted to ActionResult
            var domainResult   = IDomainResult.NotFound();
            var actionRes      = domainResult.ToActionResult() as ObjectResult;
            var problemDetails = actionRes !.Value as ProblemDetails;

            // THEN the ProblemDetails Title is expected
            Assert.Equal(expectedNotFoundTitle, problemDetails !.Title);

            ActionResultConventions.NotFoundProblemDetailsTitle = defaultValue;
        }
コード例 #3
0
 /// <summary>
 ///		Returns HTTP code 200 (OK) with a value or a 4xx code in case of an error
 /// </summary>
 /// <typeparam name="T"> The returned value type from the domain operation in <paramref name="domainResult"/> </typeparam>
 /// <param name="domainResult"> Details of the operation results (<see cref="DomainResult{T}"/>) </param>
 /// <param name="errorAction"> Optional processing in case of an error </param>
 public static ActionResult <T> ToActionResultOfT <T>(this IDomainResult <T> domainResult,
                                                      Action <ProblemDetails, IDomainResult <T> >?errorAction = null)
 => ToActionResultOfT(domainResult.Value, domainResult, errorAction, (value) => new ActionResult <T>(value));
コード例 #4
0
        public async Task <IApplicationResult <bool> > RegisterAsync(ClientMessage message)
        {
            IDomainResult <bool> domainResult = await ClientEntityService.RegisterAsync(ClientMapper.MapTo(message));

            return(ResultMapper.MapFromDomainResult(domainResult, (domain) => domain));
        }
コード例 #5
0
        public async Task <IApplicationResult <List <ClientMessage> > > GetAllAsync()
        {
            IDomainResult <List <Client> > domainResult = await ClientEntityService.GetAllAsync();

            return(ResultMapper.MapFromDomainResult(domainResult, (domain) => ClientMapper.MapTo(domain)));
        }
コード例 #6
0
        public async Task <IApplicationResult <ClientMessage> > GetAsync(ClientSearchMessage message)
        {
            IDomainResult <Client> domainResult = await ClientEntityService.GetAsync(message.Cpf);

            return(ResultMapper.MapFromDomainResult(domainResult, (domain) => ClientMapper.MapTo(domain)));
        }
コード例 #7
0
 /// <summary>
 ///     Convert to a <see cref="IDomainResult{T}" /> with a new value type <typeparamref name="TNew"/>
 /// </summary>
 /// <typeparam name="TOld"> The old value type (converting from) </typeparam>
 /// <typeparam name="TNew"> The new value type (converting to) </typeparam>
 public static IDomainResult <TNew> To <TOld, TNew>(this IDomainResult <TOld> domainResult)
 {
     return(DomainResult <TNew> .From(domainResult));
 }
コード例 #8
0
 /// <summary>
 ///     Initiate from a <see cref="IDomainResult{T}"/> instance of another 'T'
 /// </summary>
 public static IDomainResult <TValue> From <TOld>(IDomainResult <TOld> result)
 => new DomainResult <TValue>(default, new DomainResult(result.Status, result.Errors));
コード例 #9
0
        public async Task <IApplicationResult <List <ChargeMessage> > > GetAsync(ChargeSearchMessage message)
        {
            IDomainResult <List <Charge> > domainResult = await ChargeEntityService.GetAsync(message.Cpf, message.ReferenceMonth);

            return(ResultMapper.MapFromDomainResult(domainResult, (domain) => ChargeMapper.MapTo(domain)));
        }
コード例 #10
0
        public void DomainResult_Converted_To_CreatedResultOfT_Test <TValue>(IDomainResult <TValue> domainValue, Func <IDomainResult <TValue>, TValue> getValueFunc, Uri urlUri)
        {
            var actionResult = domainValue.ToCustomActionResultOfT(val => new CreatedResult(urlUri, val));

            Then_ResponseType_And_Value_And_Url_Are_Correct(actionResult, getValueFunc(domainValue));
        }
コード例 #11
0
ファイル: ErrorMessage.cs プロジェクト: Kmaczek/ldme
 public ErrorDto(IDomainResult result)
 {
     Errors.AddRange(result.Errors);
 }
コード例 #12
0
 /// <summary>
 ///     Deconstructs the instance to a (TValue, IDomainResult) pair
 /// </summary>
 /// <param name="value"> The result value returned by the domain operation </param>
 /// <param name="details"> Details of the domain operation (like status) </param>
 public void Deconstruct(out TValue value, out IDomainResult details) => (value, details) = (Value, _status);
コード例 #13
0
 /// <summary>
 ///		The most generic constructor. Creates a new instance with a specified status and error messages
 /// </summary>
 /// <param name="value"> The value to be returned </param>
 /// <param name="errorDetails"> Error details described in <see cref="IDomainResult"/> </param>
 protected DomainResult([AllowNull] TValue value, IDomainResult errorDetails)
 {
     Value   = value;
     _status = errorDetails;
 }
コード例 #14
0
 /// <summary>
 ///		Creates a new instance with a 'error'/'not found' status
 /// </summary>
 /// <param name="errorDetails"> Error details described in <see cref="IDomainResult"/> </param>
 protected DomainResult(IDomainResult errorDetails)      : this(default, errorDetails)
 {
 }
コード例 #15
0
        //
        // Conversion to HTTP code 200 (OK) - ActionResult
        //

        /// <summary>
        ///		Returns HTTP code 200 (OK) with a value or a 4xx code in case of an error
        /// </summary>
        /// <typeparam name="T"> The returned value type from the domain operation in <paramref name="domainResult"/> </typeparam>
        /// <param name="domainResult"> Details of the operation results (<see cref="DomainResult{T}"/>) </param>
        /// <param name="errorAction"> Optional processing in case of an error </param>
        public static IActionResult ToActionResult <T>(this IDomainResult <T> domainResult,
                                                       Action <ProblemDetails, IDomainResult <T> >?errorAction = null)
        => ToActionResult(domainResult.Value, domainResult, errorAction, value => new OkObjectResult(value));
コード例 #16
0
        public void Failed_DomainResult(IDomainResult domainValue, int expectedCode, string expectedTitle, string expectedErrorMsg)
        {
            var actionRes = domainValue.ToActionResult();

            Then_ResponseType_Correct_And_ProblemDetails_StatusAndText_Correct(actionRes, expectedCode, expectedTitle, expectedErrorMsg);
        }
コード例 #17
0
        public static IApplicationResult <TApplication> MapFromDomainResult <TDomain, TApplication>(IDomainResult <TDomain> domainResult, Func <TDomain, TApplication> mapper)
        {
            IApplicationResult <TApplication> applicationResult = new ApplicationResult <TApplication>()
            {
                Data       = mapper(domainResult.Data),
                Messages   = domainResult.Messages,
                StatusCode = GetStatusCode(domainResult.ResultType)
            };


            return(applicationResult);
        }
コード例 #18
0
 /// <summary>
 ///     Convert to <see cref="IDomainResult{T}" /> (the domain operation result with a returned value)
 /// </summary>
 /// <typeparam name="T"> Value type of returned by the domain operation </typeparam>
 public static IDomainResult <T> To <T>(this IDomainResult domainResult)
 {
     return(DomainResult <T> .From(domainResult));
 }
コード例 #19
0
        public async Task <IApplicationResult <bool> > RegisterAsync(List <ChargeMessage> messages)
        {
            IDomainResult <bool> domainResult = await ChargeEntityService.RegisterAsync(ChargeMapper.MapTo(messages));

            return(ResultMapper.MapFromDomainResult(domainResult, (domain) => domain));
        }
コード例 #20
0
 /// <summary>
 ///     Initiate from a <see cref="IDomainResult"/> instance
 /// </summary>
 public static IDomainResult <TValue> From(IDomainResult result) => new DomainResult <TValue>(result);