Example #1
0
        public void MultipleDependencies()
        {
            var localMap = new ActionPipeMap()
                           .StartsAt <DummyAction1>()
                           .Then <DummyAction1B>()
                           .Then <DummyMultipleIn>();

            var pipe = new ActionPipe(localMap, token, new TransientDependencyResolver());

            Assert.IsTrue(pipe.TryGetNextTask(resourceManager, taskFactory, out Task t1));
            t1.Wait();
            Assert.IsTrue(token.Contains <DummyType>());

            Assert.IsTrue(pipe.TryGetNextTask(resourceManager, taskFactory, out Task t2));
            t2.Wait();
            Assert.IsTrue(token.Contains <DummyType2>());

            Assert.IsTrue(pipe.TryGetNextTask(resourceManager, taskFactory, out Task t3));
            t3.Wait();

            Assert.IsFalse(pipe.BreakRequested);
            Assert.IsTrue(pipe.Finished);
            Assert.IsTrue(pipe.CurrentActionsFinished);
            Assert.IsFalse(pipe.TryGetNextTask(resourceManager, taskFactory, out Task _));
            Assert.AreEqual(0, pipe.Current.Length);
            Assert.AreEqual("ok", token.Get <string>());
        }
Example #2
0
        public void ProcessesActions()
        {
            var pipe = new ActionPipe(map, token, new TransientDependencyResolver());

            Assert.IsFalse(pipe.BreakRequested);
            Assert.IsFalse(pipe.Finished);
            Assert.IsTrue(pipe.CurrentActionsFinished);
            Assert.AreEqual(0, pipe.Current.Length);
            Assert.AreEqual(2, map.MaxDegreeOfParallelism);

            Assert.IsTrue(pipe.TryGetNextTask(resourceManager, taskFactory, out Task t1));
            t1.Wait();
            Assert.AreEqual(1, pipe.Current.Length);
            Assert.AreEqual(typeof(DummyAction1), pipe.Current[0].GetType());
            Assert.IsTrue(pipe.TryGetNextTask(resourceManager, taskFactory, out Task t2));
            t2.Wait();
            Assert.AreEqual(1, pipe.Current.Length);
            Assert.AreEqual(typeof(DummyAction2), pipe.Current[0].GetType());
            Assert.IsTrue(pipe.TryGetNextTask(resourceManager, taskFactory, out Task t3));
            t3.Wait();
            Assert.AreEqual(2, pipe.Current.Length);
            Assert.AreEqual(typeof(DummyAction3), pipe.Current[0].GetType());
            Assert.AreEqual(typeof(DummyAction4), pipe.Current[1].GetType());

            Assert.IsFalse(pipe.BreakRequested);
            Assert.IsTrue(pipe.Finished);
            Assert.IsTrue(pipe.CurrentActionsFinished);
            Assert.IsFalse(pipe.TryGetNextTask(resourceManager, taskFactory, out Task _));
            Assert.AreEqual(0, pipe.Current.Length);

            Assert.AreEqual(4, token.Get <DummyType>().Property);
            Assert.AreEqual(4, pipe.ProcessingStats.Items.Count());
        }