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