Ejemplo n.º 1
0
        public void DisposesDisposableAndKeepsPermanentTokens()
        {
            var localMap = new ActionPipeMap()
                           .StartsAt <DummyDisposableAction1>()
                           .Then <DummyDisposableAction2>();

            var newToken        = new ActionToken();
            var disposableType1 = new DummyDisposableType1();
            var disposableType2 = new DummyDisposableType2();

            newToken.Set(disposableType1, ItemLifespan.Permanent);
            newToken.Set(disposableType2, ItemLifespan.SingleRun);
            newToken.Set(new DummyType(), ItemLifespan.Permanent);
            newToken.Set(new DummyType2(), ItemLifespan.SingleRun);

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

            using (var dispatcher = new ActionDispatcher(ResourcePlan.Empty, 2, TaskCreationOptions.None, pipe))
            {
                dispatcher.AsyncExecute().Wait();
            }

            Assert.IsFalse(newToken.Contains <IDisposable>());
            Assert.IsTrue(newToken.Contains <DummyDisposableType1>());
            Assert.IsFalse(newToken.Contains <DummyDisposableType2>());
            Assert.IsFalse(disposableType1.DisposeCalled);
            Assert.IsTrue(disposableType2.DisposeCalled);
            Assert.IsTrue(newToken.Contains <DummyType>());
            Assert.IsFalse(newToken.Contains <DummyType2>());
        }
Ejemplo n.º 2
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>());
        }
Ejemplo n.º 3
0
        public void VisualizesPipeMap()
        {
            var map = new ActionPipeMap()
                      .StartsAt <DummyStart>()
                      .Then <DummyAction1>()
                      .ThenParallely <DummyAction2, DummyAction3, DummyAction4>()
                      .Then <DummyAction5>()
                      .Then <DummyAction6>()
                      .ThenParallely <DummyAction7, DummyAction8, DummyAction9>()
                      .Then <DummyTermination>();

            var pipeVisualization = new MermaidVisualizer().Visualize(map);

            Assert.IsTrue(pipeVisualization.Contains("graph TD"));
            Assert.IsTrue(pipeVisualization.Contains("subgraph DummyStart"));
            Assert.IsTrue(pipeVisualization.Contains("1[DummyStart] --> |IDisposable| 2[DummyAction1]"));
            Assert.IsTrue(pipeVisualization.Contains("2[DummyAction1] --> |NullObject| 3[DummyAction2]"));
            Assert.IsTrue(pipeVisualization.Contains("3[DummyAction2] --> |NullObject| 4[DummyAction5]"));
            Assert.IsTrue(pipeVisualization.Contains("4[DummyAction5] --> |NullObject| 5[DummyAction6]"));
            Assert.IsTrue(pipeVisualization.Contains("5[DummyAction6] --> |NullObject| 6[DummyAction7]"));
            Assert.IsTrue(pipeVisualization.Contains("6[DummyAction7] --> |NullObject| 7[DummyTermination]"));
            Assert.IsTrue(pipeVisualization.Contains("5[DummyAction6] --> |NullObject| 8[DummyAction8]"));
            Assert.IsTrue(pipeVisualization.Contains("5[DummyAction6] --> |NullObject| 9[DummyAction9]"));
            Assert.IsTrue(pipeVisualization.Contains("2[DummyAction1] --> |NullObject| 10[DummyAction3]"));
            Assert.IsTrue(pipeVisualization.Contains("2[DummyAction1] --> |NullObject| 11[DummyAction4]"));
            Assert.IsTrue(pipeVisualization.Contains("end"));
        }
Ejemplo n.º 4
0
 public void Init()
 {
     resourceManager = new ResourceManager();
     map             = new ActionPipeMap()
                       .StartsAt <DummyAction1>()
                       .Then <DummyAction2>()
                       .ThenParallely <DummyAction3, DummyAction4>();
     token       = new ActionToken();
     taskFactory = new TaskFactory();
 }
Ejemplo n.º 5
0
 public ActionPipeMapTests()
 {
     map = new ActionPipeMap();
 }