public ValidatableResponse( VerifyWarrantyCaseRequest request, WarrantyCaseOperation operation, Guid requestId, WarrantyResponse warrantyResponse) { Request = request; Operation = operation; RequestId = requestId; WarrantyResponse = warrantyResponse; }
public Result <WarrantyCaseResponse, IFailure> Convert( VerifyWarrantyCaseRequest request, WarrantyCaseOperation operation, Guid requestId, WarrantyResponse warrantyResponse) { try { var warrantyCaseResponse = new WarrantyCaseResponse( orderId: request.OrderId, warrantyCaseId: warrantyResponse.Header.WarrantyCaseId !) { Operation = operation, WarrantyCaseStatus = WarrantyCaseStatusMap[warrantyResponse.Body !.CaseStatus],
public Result <Unit, IFailure> Validate( VerifyWarrantyCaseRequest request, WarrantyCaseOperation operation, Guid requestId, WarrantyResponse warrantyResponse) { if (warrantyResponse.Header.WarrantyResponseErrors .FirstOrDefault(e => e.Type == WarrantyResponseErrorType.ServiceNotAvailable) is WarrantyResponseError serviceNotAvailableError) { return(new Result <Unit, IFailure>( new ServiceNotAvailableFailure(serviceNotAvailableError.Message))); } if (warrantyResponse.Header.WarrantyResponseErrors .FirstOrDefault(e => e.Type == WarrantyResponseErrorType.InvalidRequest) is WarrantyResponseError invalidRequestError) { return(new Result <Unit, IFailure>( new InvalidRequestFailure(invalidRequestError.Message))); } if (warrantyResponse.Header.WarrantyResponseErrors .FirstOrDefault(e => e.Type == WarrantyResponseErrorType.InternalError) is WarrantyResponseError warrantyServiceInternalError) { return(new Result <Unit, IFailure>( new WarrantyServiceInternalErrorFailure(warrantyServiceInternalError.Message))); } var validatableResponse = new ValidatableResponse( request, operation, requestId, warrantyResponse); var validationResult = Validator.Validate(validatableResponse); if (validationResult.IsValid) { return(new Result <Unit, IFailure>(Unit.Value)); } var errorMessages = string.Join(Environment.NewLine, validationResult.Errors.Select(x => x.ErrorMessage)); return(new Result <Unit, IFailure>( new ResponseValidationFailure( $"Response of RequestId: `{requestId}` failed validation:" + Environment.NewLine + errorMessages))); }