Esempio n. 1
0
        /// <summary>
        /// Create the response from the request context and the record.
        /// </summary>
        /// <param name="context">
        /// Context containing information about the request.
        /// </param>
        /// <param name="results">
        /// The data record for the request.
        /// </param>
        /// <typeparam name="T">
        /// The type of object that is being returned from the request.
        /// </typeparam>
        /// <returns>
        /// The <see cref="ResponseEnvelope{T}"/> describing the data for the request.
        /// </returns>
        public ResponseEnvelope <T> CreateResponse <T>(ITestApiContext context, IApiSearchResult <T> results)
        {
            var response = new ResponseEnvelope <T>
            {
                Meta        = context.MetaData,
                Payload     = results.Results,
                RecordCount = CreateRecordCounts(results.RecordCounts),
                Debug       = ExcludeDebugInformation(context),
                Warnings    = context.Warnings.IsNullOrEmpty() ? null : context.Warnings,
                Errors      = context.Errors.IsNullOrEmpty() ? null : context.Errors
            };

            return(response);
        }
Esempio n. 2
0
        /// <summary>
        /// The create details.
        /// </summary>
        /// <param name="context">
        /// The context.
        /// </param>
        /// <param name="results">
        /// The results.
        /// </param>
        /// <typeparam name="TIn">
        /// </typeparam>
        /// <typeparam name="TOut">
        /// </typeparam>
        /// <returns>
        /// A IEnumerable containing all the results translated.
        /// </returns>
        public IEnumerable <TOut> CreateDetails <TIn, TOut>(
            ITestApiContext context,
            ApiResourceEndPoint endPoint,
            IApiSearchResult <IEnumerable <TIn> > results)
        //// This constraint is to ensure the object being created is an IWebLinkable.  The reason for the
        //// generic is to use in _objectFactory.Create
            where TOut : IWebLinkable
        {
            var recordDetails = context.TimeIt("Transform To Response Type", () => results
                                               .Results
                                               .Select(record => this._objectFactory.Create <TOut>(record))).ToList();

            context.TimeIt("Append Functions", () => AppendFunctionsTo(recordDetails, endPoint, context));

            return(recordDetails);
        }
Esempio n. 3
0
        /// <summary>
        /// The create details.
        /// </summary>
        /// <param name="context">
        /// The context.
        /// </param>
        /// <param name="record">
        /// The record.
        /// </param>
        /// <typeparam name="TIn">
        /// </typeparam>
        /// <typeparam name="TOut">
        /// </typeparam>
        /// <returns>
        /// The <see cref="TOut"/>.
        /// </returns>
        public TOut CreateDetails <TIn, TOut>(ITestApiContext context, ApiResourceEndPoint endPoint, IApiSearchResult <TIn> record)
        //// This constraint is to ensure the object being created is an IWebLinkable.  The reason for the
        //// generic is to use in _objectFactory.Create
            where TOut : IWebLinkable
        {
            var recordDetail = this._objectFactory.Create <TOut>(record.Results);

            AppendFunctionsTo(new[] { recordDetail }, endPoint, context);

            return(recordDetail);
        }