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()); }
void ExecuteAction(IResourceManager resourceManager, IAction action) { var inType = action.InputType; object GetValue(Type type) => type == typeof(NullObject) ? NullObject.Value : ActionToken.Get(type); object GetMultiple(Type[] types) { var values = types.Select(GetValue).ToArray(); return(Activator.CreateInstance(inType, values)); } var inValue = inType.FullName.StartsWith("System.ValueTuple") ? GetMultiple(inType.GenericTypeArguments) : GetValue(inType); var outValue = action.ExecuteUntyped(resourceManager, inValue); if (!(outValue is NullObject)) { ActionToken.Set(outValue, action.OutputType, ItemLifespan.SingleRun); } }