예제 #1
0
        public async void AsyncEnumerableDataPipelineWithDependencyInjection()
        {
            // arrange
            var services = new ServiceCollection().AddSingleton <Counter>().AddSingleton <MultiplyPipe>().AddSingleton <ILogger, ILoggerFake>();
            var provider = services.BuildServiceProvider();
            var engine   = new EnginePipelineBuilder <IAsyncEnumerable <int> >()
                           .AddEngine()
                           .AddPipe <MultiplyPipe, IAsyncEnumerable <float> >(provider)  // 6
                           .AddPipe(a => a.Select(i => (int)i + 2))                      // 8
                           .AddPipe <MultiplyPipe, IAsyncEnumerable <float> >(provider); // 24
            // act
            var asyncEnumerable = engine.Flow(new[] { 3, 4, 5 }.ToAsyncEnumerable());
            // assert
            var e = asyncEnumerable.GetAsyncEnumerator();

            await HasNextAsync(e, 24);
            await HasNextAsync(e, 90);
            await HasNextAsync(e, 224);
            await NoNextAsync(e);

            var logger = provider.Get <ILogger, ILoggerFake>();

            Assert.Equal(logger.Messages.Count, 6);

            var rEnumerator = new[] { 234.0f, 462, 806 }.GetEnumerator();

            await foreach (var value in asyncEnumerable)
            {
                Assert.True(rEnumerator.MoveNext());
                Assert.Equal(value, rEnumerator.Current);
            }
        }
        public void ObservableDataPipelineRunWithDependencyInjection()
        {
            // arrange
            var services = new ServiceCollection().AddSingleton <Counter>().AddSingleton <MultiplyPipe>().AddSingleton <ObservableEngine>().AddSingleton <ILogger, ILoggerFake>();
            var provider = services.BuildServiceProvider();

            var engine = new EnginePipelineBuilder <IObservable <int> >()
                         .AddEngine <ObservableEngine>(provider)
                         .AddPipe <MultiplyPipe, IObservable <float> >(provider)  // 6
                         .AddPipe(a => a.Select(i => (int)i + 2))                 // 8
                         .AddPipe <MultiplyPipe, IObservable <float> >(provider); // 24
            // act
            var scheduler = new TestScheduler();

            engine.Run(new Context()
            {
                { "scheduler", scheduler }
            }, o => /*Flow()*/ {
                var observer = scheduler.Start(() => o, 0, 0, TimeSpan.FromMilliseconds(2000).Ticks);
                var msg      = observer.Messages;
                // assert
                Assert.Equal(msg.Count, 2);
                Assert.Equal(msg[0].Value.Value, 24);
                Assert.Equal(msg[1].Value.Kind, NotificationKind.OnCompleted);
                return(null);
            });
        }
예제 #3
0
        public void SimpleDataPipelineWithDependencyInjection()
        {
            var services = new ServiceCollection().AddSingleton <Counter>().AddSingleton <multiplyPipeFromDI>();
            var provider = services.BuildServiceProvider();

            var engine = new EnginePipelineBuilder <int>()
                         .AddEngine()
                         .AddPipe <multiplyPipeFromDI, float>(provider)  // 6
                         .AddPipe(a => (int)a + 2)                       // 8
                         .AddPipe <multiplyPipeFromDI, float>(provider); // 24

            var r = engine.Flow(3);

            Assert.Equal(r, 24, 0);
        }
예제 #4
0
        public void SimpleDataPipelineTest()
        {
            var engine = new EnginePipelineBuilder <int>()
                         .AddEngine()
                         .AddPipe((int a) => a + 1)
                         .AddPipe(new doublePipe())
                         .AddPipe(i => 3.0 * i)
                         .AddPipe(new Pipe <double, double>(i => ++ i));

            var r = engine.Flow(3);

            Assert.Equal(r, 25, 1);

            var r1 = engine.Flow(5);

            Assert.Equal(r1, 37, 1);
        }
예제 #5
0
        public void SimpleDataPipelineWithContextTest()
        {
            var engine = new EnginePipelineBuilder <int>()
                         .AddEngine()
                         .AddPipe((int a, IContext context) => a + 2)
                         .AddPipe((a, context) =>
            {
                context[key] = 3;
                return(--a);
            })
                         .AddPipe(new multiplePipe())
                         .AddPipe(i => 3.0 * i)
                         .AddPipe(new Pipe <double, double>((i, Context) => i + (int)Context[key]));

            var r = engine.Flow(3);

            Assert.Equal(r, 39, 0);

            var r1 = engine.Flow(5, new Context());

            Assert.Equal(r1, 57, 0);
        }