public void CreateAsync_Cancelled() { PredicateFunc <DummyEntity> createResult = _ => Rand.Bool(); var middleware = new SpyPredicateMiddlewareToCreateAsync(createResult, cancelled: true); var context = new DummyContext(); Func <DummyContext, Task <PredicateFunc <DummyEntity> > > next = _ => throw new AssertFailedException("next は呼ばれてはいけません。"); new TestCaseRunner() .Run(() => middleware.CreateAsync(context, next)) .Verify((actual, desc) => { Assert.AreEqual(createResult, actual, desc); Assert.AreEqual(context, middleware.ActualContext, desc); Assert.AreEqual(false, middleware.ActualCancelled, desc); }, (Type)null); }
public void CreateAsync_NullNextPredicate() { PredicateFunc <DummyEntity> createResult = _ => Rand.Bool(); var middleware = new SpyPredicateMiddlewareToCreateAsync(createResult, cancelled: false); var context = new DummyContext(); DummyContext actualNextContext = default; Func <DummyContext, Task <PredicateFunc <DummyEntity> > > next = ctx => { actualNextContext = ctx; return(Task.FromResult(SpyPredicateMiddlewareToCreateAsync.NullPredicate)); }; new TestCaseRunner() .Run(() => middleware.CreateAsync(context, next)) .Verify((actual, desc) => { Assert.AreEqual(createResult, actual, desc); Assert.AreEqual(context, middleware.ActualContext, desc); Assert.AreEqual(false, middleware.ActualCancelled, desc); Assert.AreEqual(context, actualNextContext, desc); }, (Type)null); }
public void CreateAsync_Abyss() { var context = new DummyContext(); var entity = new DummyEntity(); Action TestCase(int testNumber, bool createResult, bool nextResult, (bool result, DummyEntity nextEntity) expected) => () => { DummyEntity actualEntity = default; var middleware = new SpyPredicateMiddlewareToCreateAsync(x => { actualEntity = x; return(createResult); }, cancelled: false); DummyContext actualNextContext = default; DummyEntity actualNextEntity = default; Func <DummyContext, Task <PredicateFunc <DummyEntity> > > next = ctx => { actualNextContext = ctx; return(Task.FromResult <PredicateFunc <DummyEntity> >(x => { actualNextEntity = x; return nextResult; })); }; new TestCaseRunner($"No.{testNumber}") .Run(async() => (await middleware.CreateAsync(context, next))(entity)) .Verify((actual, desc) => { Assert.AreEqual(expected.result, actual, desc); Assert.AreEqual(context, middleware.ActualContext, desc); Assert.AreEqual(false, middleware.ActualCancelled, desc); Assert.AreEqual(entity, actualEntity, desc); Assert.AreEqual(context, actualNextContext, desc); Assert.AreEqual(expected.nextEntity, actualNextEntity, desc); }, (Type)null); }; new[] {