public AllowedOptionsBuilderTest() { var httpContextStorage = new ScopedStorage <HttpContext> { Value = new DefaultHttpContext { User = new MockPrincipal() } }; this.builder = new AllowedOptionsBuilder <Entity>(httpContextStorage); }
/// <summary> /// Emits an <see cref="OptionsResult"/> which lists the allowed /// HTTP verbs. /// <para> /// Catches <see cref="ValidationException"/> and converts it to /// an appropriate <see cref="IActionResult"/>. /// </para> /// <para>Requires usage of <see cref="HttpContextProviderAttribute"/>.</para> /// </summary> /// <typeparam name="TSource">The type of the value.</typeparam> /// <param name="observable">The parent observable.</param> /// <param name="factory">A factory function for the allowed HTTP verbs.</param> /// <returns>An instance of <see cref="IProviderObservable{IActionResult}"/>.</returns> public static IProviderObservable <IActionResult> ToOptionsResult <TSource>( this IProviderObservable <TSource> observable, Func <AllowedOptionsBuilder <TSource>, AllowedOptionsBuilder <TSource> > factory) { Check.IsNull(factory, nameof(factory)); return(observable.ToOptionsResult(s => { var httpContext = observable.ServiceProvider .GetRequiredService <IScopedStorage <HttpContext> >(); var allowedOptionsBuilder = new AllowedOptionsBuilder <TSource>( httpContext?.Value.User); return factory(allowedOptionsBuilder) .GenerateAllowedVerbs(s); })); }
public AllowedOptionsBuilderTest() { this.builder = new AllowedOptionsBuilder <Entity>(new MockPrincipal()); }
public static AllowedOptionsBuilder <TSource> IsPutAllowed <TSource>( this AllowedOptionsBuilder <TSource> builder, Func <TSource, bool> validCheck) => builder.IsPutAllowed((c, i) => validCheck(i));
public static AllowedOptionsBuilder <TSource> IsPutAllowed <TSource>( this AllowedOptionsBuilder <TSource> builder, Func <ClaimsPrincipal, TSource, bool> validCheck) => builder.IsAllowed(new[] { HttpVerb.Put }, validCheck);
public static AllowedOptionsBuilder <TSource> IsAllowedForAll <TSource>( this AllowedOptionsBuilder <TSource> builder, Func <TSource, bool> validCheck) => builder.IsAllowedForAll((p, i) => validCheck(i));
public static AllowedOptionsBuilder <TSource> IsAllowedForAll <TSource>( this AllowedOptionsBuilder <TSource> builder, Func <ClaimsPrincipal, TSource, bool> validCheck) => builder.IsAllowed( new[] { HttpVerb.Delete, HttpVerb.Get, HttpVerb.Patch, HttpVerb.Post, HttpVerb.Put }, validCheck);