Ejemplo n.º 1
0
        public void CreateAsync_Abyss()
        {
            var createResult = Rand.Array <DummyEntity>();
            IEnumerable <DummyEntity> actualSource = default;
            var middleware = new SpyFilterMiddlewareToCreateAsync(src => {
                actualSource = src;
                return(createResult);
            }, cancelled: false);

            var          nextResult                    = Rand.Array <DummyEntity>();
            DummyContext actualNextContext             = default;
            IEnumerable <DummyEntity> actualNextSource = default;
            Func <DummyContext, Task <FilterFunc <DummyEntity> > > next = ctx => {
                actualNextContext = ctx;
                return(Task.FromResult <FilterFunc <DummyEntity> >(src => {
                    actualNextSource = src;
                    return nextResult;
                }));
            };

            var context = new DummyContext();
            var source  = new[] { new DummyEntity(), new DummyEntity() };

            new TestCaseRunner()
            .Run(async() => (await middleware.CreateAsync(context, next))(source))
            .Verify((actual, desc) => {
                Assert.AreEqual(nextResult, actual, desc);

                Assert.AreEqual(context, middleware.ActualContext, desc);
                Assert.AreEqual(false, middleware.ActualCancelled, desc);
                Assert.AreEqual(source, actualSource, desc);
                Assert.AreEqual(context, actualNextContext, desc);
                Assert.AreEqual(createResult, actualNextSource, desc);
            }, (Type)null);
        }
Ejemplo n.º 2
0
        public void CreateAsync_Cancelled()
        {
            FilterFunc <DummyEntity> createResult = _ => Rand.Array <DummyEntity>();
            var middleware = new SpyFilterMiddlewareToCreateAsync(createResult, cancelled: true);
            var context    = new DummyContext();
            Func <DummyContext, Task <FilterFunc <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);
        }
Ejemplo n.º 3
0
        public void CreateAsync_NullNextFunc()
        {
            FilterFunc <DummyEntity> createResult = _ => Rand.Array <DummyEntity>();
            var middleware = new SpyFilterMiddlewareToCreateAsync(createResult, cancelled: false);
            var context    = new DummyContext();

            DummyContext actualNextContext = default;
            Func <DummyContext, Task <FilterFunc <DummyEntity> > > next = ctx => {
                actualNextContext = ctx;
                return(Task.FromResult(SpyFilterMiddlewareToCreateAsync.NullFilter));
            };

            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);
        }