public void AppendLinksTo(IWebLinkable webLinkable, ApiResourceEndPoint endPoint, ITestApiContext context) { var weblinkType = webLinkable.GetType(); if (!_linkCreators.ContainsKey(webLinkable.GetType())) { return; } _linkCreators[weblinkType].AppendFunctionsTo(webLinkable, endPoint, context); }
/// <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); }
/// <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); }
/// <summary> /// Appends the links to. /// </summary> /// <param name="webLinkable">The <see cref="IWebLinkable" /> object.</param> /// <param name="endPoint"></param> /// <param name="context">Context containing information about the request.</param> //public void AppendFunctionsTo(IWebLinkable webLinkable, ApiResourceEndPoint endPoint, ITestApiContext context) //{ // var webLinkableType = webLinkable.GetType(); // if (webLinkableType != CreatesLinksFor) // { // context.AddWarning( // string.Format( // @"Trying to add functions to invalid type {0} in LightboxDetailFunctionAppender. Operation Cancelled", // webLinkableType)); // return; // } // var securableObjectPermission = // context.AuthenticatedUser.Permissions.FirstOrDefault( // p => p.SecurableObjectType.Equals(SecurableObjectType.OrgUnit)); // webLinkable.Links.Self = "lightbox"; // if (securableObjectPermission == null) // { // AddFunctionsToWebLinkable( // f => f.Value.ResourceEndPoints.Contains(endPoint) && f.Value.Permissions == ulong.MaxValue, // webLinkable.Links); // return; // } // AddFunctionsToWebLinkable( // f => f.Value.ResourceEndPoints.Contains(endPoint) && (f.Value.Permissions & securableObjectPermission.Permissions) > 0 || f.Value.Permissions == ulong.MaxValue, // webLinkable.Links); //} public void AppendFunctionsTo(IWebLinkable webLinkable, ApiResourceEndPoint endPoint, ITestApiContext context) { var webLinkableType = webLinkable.GetType(); if (webLinkableType != CreatesLinksFor) { context.AddWarning( string.Format( @"Trying to add functions to invalid type {0} in LightboxDetailFunctionAppender. Operation Cancelled", webLinkableType)); return; } webLinkable.Links.Self = "tickets"; AddFunctionsToWebLinkable( f => f.Value.ResourceEndPoints.Contains(endPoint) && f.Value.Permissions == ulong.MaxValue, webLinkable.Links); }
private void AppendFunctionsTo <T>(IEnumerable <T> webLinkable, ApiResourceEndPoint endPoint, ITestApiContext context) where T : IWebLinkable { webLinkable.ForEach(linkable => this._functionAppender.AppendLinksTo(linkable, endPoint, context)); }