public WpfPipelineProperty
 (
     IPropertyChangeRaiser propertyChanged,
     Expression <Func <TType> > propertyExpression,
     AssignablePipelineStage <TType>?setter
 )
     : this(propertyChanged, propertyExpression, setter, setter)
 {
 }
        public void OutputIsTakenFromTheSelectedInput(int selected, int[] inputValues, int expected)
        {
            var select = AssignablePipelineStage.Create("Select", selected);
            var inputs = CreateInputs(inputValues.Select(i => i.AsPipelineConstant()).ToArray());

            var sut = new MultiplexingPipelineStage <int, int>("Name", select, inputs);

            PipelineAssert.Value(sut, expected);
        }
        public void StageInvalidatesDependentStages()
        {
            var select = AssignablePipelineStage.Create("Select", 0);
            var inputs = CreateInputs(2.AsPipelineConstant(), 4.AsPipelineConstant());

            var sut = new MultiplexingPipelineStage <int, int>("Name", select, inputs);

            PipelineAssert.AssertPipelineIsInvalidatingDependentStages(sut);
        }
        public void PassiveStageIsNeverInvalidated()
        {
            var assignable = new AssignablePipelineStage <int>("", 10);
            var passive    = new PassivePipelineStage <int>(assignable);
            var test       = passive.AttachTestStage();

            assignable.SetValue(11);
            test.AssertInvalidations(0);
        }
        public void RemovingTheCurrentlySelectedInputCausesException()
        {
            var select = AssignablePipelineStage.Create("Select", 0);
            var input0 = AssignablePipelineStage.Create("Input 0", 0);
            var inputs = CreateInputs(input0);

            var sut = new MultiplexingPipelineStage <int, int>("Name", select, inputs);

            Assert.Catch(() => sut.RemoveInput(0));
        }
        public void StageIsInvalidatedWhenCurrentlySelectedInputChanges()
        {
            var select = AssignablePipelineStage.Create("Select", 0);
            var input  = AssignablePipelineStage.Create("Input", 0);
            var inputs = CreateInputs(input);

            var sut  = new MultiplexingPipelineStage <int, int>("Name", select, inputs);
            var test = sut.AttachTestStage();

            input.SetValue(1);
            test.AssertInvalidations(1);
        }
        public void RemovingAStageRemovesDependency()
        {
            var select = AssignablePipelineStage.Create("Select", 0);
            var input0 = AssignablePipelineStage.Create("Input 0", 0);
            var input1 = AssignablePipelineStage.Create("Input 1", 0);
            var inputs = CreateInputs(input0, input1);

            var sut = new MultiplexingPipelineStage <int, int>("Name", select, inputs);

            sut.RemoveInput(1);
            PipelineAssert.NotDependentOn(sut, input1);
        }
示例#8
0
        public void ExtractorIsUsedToCalculateNewDelta(int old, int @new, int expected)
        {
            var input = new AssignablePipelineStage <int>("", old);
            var sut   = new DeltaPipelineStage <int, int>("", Extractor, input, expected - 1);
            var test  = sut.AttachTestStage();

            PipelineAssert.Value(sut, expected - 1);

            input.SetValue(@new);
            test.AssertInvalidations(1);
            PipelineAssert.Value(sut, expected);
        }
        public void ExceptionInPropagationAreHandledAndATraceIsCreated()
        {
            var sut = new DataRetrievalPipelineStage <int>("Exception", () => throw new Exception("EXCEPTION!"));
            var ss  = AssignablePipelineStage.Create("Assignable", 10);
            var dd  = PipelineOperations.Create("operation", (a, e) => a, ss, sut);

            var sdf = dd.CreateReaction(a => { }, false);

            var exception = Assert.Catch <PipelineException>(() => ss.SetValue(11));

            TestContext.WriteLine(exception.Message);
        }
示例#10
0
        public void PotentialConcurrentUpdateOfStageIsCorrectlyDiscovered()
        {
            using var goAhead = new ManualResetEvent(false);

            var value1 = new AssignablePipelineStage <int>("", 1000);
            var value2 = new AssignablePipelineStage <int>("", 2000);

            var concurrent = PipelineOperations.Create("Concurrent Stage", (a, b) => Wait(goAhead, 1000), value1, value2).AsEager();

            Task.Run(() => value1.SetValue(1001));
            goAhead.WaitOne();
            var message = Assert.Throws <PipelineException>(() => value2.SetValue(1001));
        }
        public void StageIsInvalidatedWhenSelectSignalChanges()
        {
            var select = AssignablePipelineStage.Create("Select", 0);
            var inputs = CreateInputs(2.AsPipelineConstant(), 4.AsPipelineConstant());

            var sut  = new MultiplexingPipelineStage <int, int>("Name", select, inputs);
            var test = sut.AttachTestStage();

            select.SetValue(1);
            select.SetValue(0);

            test.AssertInvalidations(2);
        }
示例#12
0
        public void ConcurrentUpdateOfTwoSeparateGraphsAreNotLabeledAsConcurrent()
        {
            using var goAhead = new ManualResetEvent(false);
            var v1 = new AssignablePipelineStage <int>("", 1);
            var v2 = new AssignablePipelineStage <int>("", 3);

            var g1 = PipelineReactions.Create(_ => Wait(goAhead, 1000), v1);
            var g2 = PipelineReactions.Create(_ => Wait(goAhead, 1000), v2);

            Task.Run(() => v1.SetValue(1001));
            goAhead.WaitOne();
            Assert.DoesNotThrow(() => v2.SetValue(1001));
        }
        public void DependencyIsOnlyRemovedIfAllInputsDependentOnThatStageAreChanged()
        {
            var select    = AssignablePipelineStage.Create("Select", 0);
            var input0    = AssignablePipelineStage.Create("Input 0", 0);
            var newInput0 = AssignablePipelineStage.Create("Input 0 (new)", 0);
            var inputs    = CreateInputs(input0, input0);

            var sut = new MultiplexingPipelineStage <int, int>("Name", select, inputs);

            sut.SetInput(0, newInput0);
            PipelineAssert.DependentOn(sut, input0);
            sut.SetInput(1, newInput0);
            PipelineAssert.NotDependentOn(sut, input0);
        }
        public void SettingANewMappingRemovesOldDependencyAndAddsNew()
        {
            var select    = AssignablePipelineStage.Create("Select", 0);
            var input0    = AssignablePipelineStage.Create("Input 0", 0);
            var newInput0 = AssignablePipelineStage.Create("Input 0 (new)", 0);
            var inputs    = CreateInputs(input0);

            var sut = new MultiplexingPipelineStage <int, int>("Name", select, inputs);

            sut.SetInput(0, newInput0);

            PipelineAssert.NotDependentOn(sut, input0);
            PipelineAssert.DependentOn(sut, newInput0);
        }
        public void SettingANewInputForAnUnselectedInputCausesNoInvalidation()
        {
            var select    = AssignablePipelineStage.Create("Select", 1);
            var input0    = AssignablePipelineStage.Create("Input 0", 0);
            var input1    = AssignablePipelineStage.Create("Input 1", 0);
            var newInput0 = AssignablePipelineStage.Create("Input 0 (new)", 100);
            var inputs    = CreateInputs(input0, input1);

            var sut  = new MultiplexingPipelineStage <int, int>("Name", select, inputs);
            var test = sut.AttachTestStage();

            sut.SetInput(0, newInput0);

            test.AssertInvalidations(0);
        }
        public void NewValueAndChangedStageAtTheSameTimeHasTheIntendedReaction(PipelineSuspensionState initial, PipelineSuspensionState state, int invalidations)
        {
            var stateStage = Suspender(initial);
            var value      = new AssignablePipelineStage <int>("", 1);
            var sut        = new SuspendingPipelineStage <int>(value, stateStage);
            var test       = sut.AttachTestStage();

            value.SetValueWithoutInvalidating(2);
            stateStage.SetValueWithoutInvalidating(state);

            PipelineCore.Invalidate(stateStage, value);

            test.AssertInvalidations(invalidations);
            PipelineAssert.Value(sut, 2);
        }
        public WpfPipelineProperty
        (
            IPropertyChangeRaiser propertyChanged,
            Expression <Func <TType> > propertyExpression,
            IPipelineStage <TType> getter,
            AssignablePipelineStage <TType>?setter
        )
        {
            PropertyChanged = propertyChanged ?? throw new ArgumentNullException(nameof(propertyChanged));
            PropertyName    = GetPropertyNameFromExpression(propertyExpression);
            Getter          = getter ?? throw new ArgumentNullException(nameof(getter));
            Setter          = setter;

            Reaction = getter.CreateReaction(RaisePropertyChangedOnValueChanged);
        }
示例#18
0
        public void CustomComparerIsUsedWhenEvaluatingInvalidation(int value)
        {
            var comparer = new SettableEqualityComparer <int>(false);
            var sut      = new AssignablePipelineStage <int>("", value, comparer);
            var test     = sut.AttachTestStage();

            sut.SetValue(value);
            test.AssertInvalidations(1);
            test.AssertStageInvalidated(sut);

            comparer.Equal = true;
            test.PrepareForNext();
            sut.SetValue(value + 1);
            test.AssertInvalidations(1);
            test.AssertStageNotInvalidated(sut);
        }
        public void DependencyIsOnlyRemovedIfAllInputsDependentOnThatStageAreRemoved()
        {
            var select = AssignablePipelineStage.Create("Select", 0);
            var input0 = AssignablePipelineStage.Create("Input 0", 0);
            var input2 = AssignablePipelineStage.Create("Input 2", 0);
            var inputs = CreateInputs(input0, input0, input2);

            var sut = new MultiplexingPipelineStage <int, int>("Name", select, inputs);

            sut.RemoveInput(1);
            PipelineAssert.DependentOn(sut, input0, input2);
            select.SetValue(2); // To prevent exception
            sut.RemoveInput(0);
            PipelineAssert.NotDependentOn(sut, input0);
            PipelineAssert.DependentOn(sut, input2);
        }
        public void SettingANewInputForTheCurrentlySelectedInputCausesInvalidationAndGetsTheNewValue()
        {
            var select    = AssignablePipelineStage.Create("Select", 0);
            var input0    = AssignablePipelineStage.Create("Input 0", 0);
            var input1    = AssignablePipelineStage.Create("Input 1", 0);
            var newInput0 = AssignablePipelineStage.Create("Input 0 (new)", 100);
            var inputs    = CreateInputs(input0, input1);

            var sut  = new MultiplexingPipelineStage <int, int>("Name", select, inputs);
            var test = sut.AttachTestStage();

            sut.SetInput(0, newInput0);

            test.AssertInvalidations(1);
            PipelineAssert.Value(sut, 100);
        }
        public void EachNewInvalidationPicksUpNewInformation()
        {
            var a    = new AssignablePipelineStage <int>("", 1);
            var sut  = new PipelinePropagationInformationStage <int>("", inv => a.GetValue(), a.GetValue(), a);
            var test = sut.AttachTestStage();

            PipelineAssert.Value(sut, 1);

            a.SetValue(2);
            test.AssertInvalidations(1);
            PipelineAssert.Value(sut, 2);
            PipelineAssert.Value(sut, 2);

            a.SetValue(5);
            test.AssertInvalidations(2);
            PipelineAssert.Value(sut, 5);
            PipelineAssert.Value(sut, 5);
        }
示例#22
0
        public static void Test()
        {
            var one = 1.AsPipelineConstant();
            var two = 2.AsPipelineConstant();

            var value               = new AssignablePipelineStage <int>("integer", 0);
            var suspension          = new AssignablePipelineStage <PipelineSuspensionState>("suspender", PipelineSuspensionState.Resume);
            var changeableOperation = new AssignablePipelineStage <Func <int, int> >("suspender", a => a);

            var multiply   = PipelineOperations.Create("multiply", Multiply, value, two);
            var changeable = PipelineOperations.Create("changeable", changeableOperation, multiply);
            var cache      = changeable.WithCache();
            var suspender  = cache.WithConditionalSuspender(suspension);

            var reaction = PipelineReactions.Create(Reaction, suspender);

            value.SetValue(1);
            value.SetValue(2);
            changeableOperation.SetValue(a => a * 2);

            GC.KeepAlive(reaction);
            Console.ReadLine();
        }
示例#23
0
        public void GivenNameIsReflected(string name)
        {
            var sut = new AssignablePipelineStage <int>(name, 10);

            Assert.AreEqual(name, sut.Name);
        }
示例#24
0
        public void InitialValueIsReflectedInGetValue(int initial)
        {
            var sut = new AssignablePipelineStage <int>("", initial);

            Assert.AreEqual(initial, sut.GetValue());
        }
        /// <summary>
        /// Adds an update to an <see cref="AssignablePipelineStage{TValue}"/>.
        /// </summary>
        /// <typeparam name="TValue">The data type.</typeparam>
        /// <param name="transaction">The transaction.</param>
        /// <param name="stage">The stage to set value for.</param>
        /// <param name="value">The new value.</param>
        /// <returns>The same transaction object.</returns>
        public static IPipelineTransaction Update <TValue>(this IPipelineTransaction transaction, AssignablePipelineStage <TValue> stage, TValue value)
        {
            bool AssignableUpdate() => stage.SetValueWithoutInvalidating(value);

            return(transaction.Update(stage, AssignableUpdate));
        }