public void Build_PredicateFuncs_Empty() { new TestCaseRunner() .Run(() => FilterPipeline.Build(new MiddlewareFunc <DummyContext, Task <PredicateFunc <DummyEntity> > > [0])) .Verify((actual, desc) => { var actualPredicate = actual(new DummyContext()).GetAwaiter().GetResult(); Assert.AreEqual(PredicateMiddleware <DummyContext, DummyEntity> .NullPredicate, actualPredicate, desc); }, (Type)null); }
public async Task Usage_IMiddleware() { var middlewares = new PredicateMiddleware <Uri, FileInfo>[] { new HttpsPredicate(), new StaticFilePredicate(), }; Func <Uri, Task <PredicateFunc <FileInfo> > > pipeline = FilterPipeline.Build(middlewares.Select(x => x.ToDelegate())); var predicate = await pipeline(new Uri("https://example.com/foo")); Assert.AreEqual(true, predicate(new FileInfo("foo.html"))); Assert.AreEqual(false, predicate(new FileInfo("bar.html"))); Assert.AreEqual(false, (await pipeline(new Uri("http://example.com/foo")))(new FileInfo("foo.html"))); }
public async Task Usage_MiddlewareFunc() { Func <Uri, Task <PredicateFunc <FileInfo> > > pipeline = FilterPipeline.Build(new MiddlewareFunc <Uri, Task <PredicateFunc <FileInfo> > >[] { next => async context => { if (!context.Scheme.Equals("https", StringComparison.OrdinalIgnoreCase)) { return(_ => false); } return(await next(context)); }, next => async context => { var nextPredicate = await next(context); var uriPath = context.AbsolutePath.TrimStart('/'); return(file => Path.GetFileNameWithoutExtension(file.Name).Equals(uriPath, StringComparison.OrdinalIgnoreCase) && nextPredicate(file)); }, }); var predicate = await pipeline(new Uri("https://example.com/foo")); Assert.AreEqual(true, predicate(new FileInfo("foo.html"))); Assert.AreEqual(false, predicate(new FileInfo("bar.html"))); Assert.AreEqual(false, (await pipeline(new Uri("http://example.com/foo")))(new FileInfo("foo.html"))); }
public void Build_PredicateFuncs_Null() { new TestCaseRunner() .Run(() => FilterPipeline.Build((MiddlewareFunc <DummyContext, Task <PredicateFunc <DummyEntity> > >[])null)) .Verify((actual, desc) => { }, typeof(ArgumentNullException)); }