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