Beispiel #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;
        }
Beispiel #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;
        }
 /// <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));
Beispiel #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));
        }
Beispiel #5
0
        public async Task <IApplicationResult <List <ClientMessage> > > GetAllAsync()
        {
            IDomainResult <List <Client> > domainResult = await ClientEntityService.GetAllAsync();

            return(ResultMapper.MapFromDomainResult(domainResult, (domain) => ClientMapper.MapTo(domain)));
        }
Beispiel #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)));
        }
Beispiel #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));
 }
Beispiel #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));
        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)));
        }
        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));
        }
Beispiel #11
0
 public ErrorDto(IDomainResult result)
 {
     Errors.AddRange(result.Errors);
 }
Beispiel #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);
Beispiel #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;
 }
Beispiel #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)
 {
 }
        //
        // 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));
        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);
        }
        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);
        }
Beispiel #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));
 }
        public async Task <IApplicationResult <bool> > RegisterAsync(List <ChargeMessage> messages)
        {
            IDomainResult <bool> domainResult = await ChargeEntityService.RegisterAsync(ChargeMapper.MapTo(messages));

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