Exemplo n.º 1
0
        static void Main(string[] args)
        {
            var lucky       = new ContainsPipe(3, "lucky");
            var fizz        = new NumberSubstitutePipe(3, "fizz");
            var buzz        = new NumberSubstitutePipe(5, "buzz");
            var fizzbuzz    = new CompositePipe(fizz, buzz);
            var defaultPipe = new DefaultNumberPipe();

            List <IPipe> pipes = new List <IPipe>()
            {
                lucky,
                fizzbuzz,
                fizz,
                buzz,
                defaultPipe
            };

            var runner = new Runner(Enumerable.Range(1, 20), pipes);

            foreach (var item in runner.Run())
            {
                Console.WriteLine(item);
            }

            Console.ReadLine();
        }
Exemplo n.º 2
0
        public void PipeReturnsCorrectResult()
        {
            // Fixture setup
            var v1 = this.CreateValue();
            var v2 = this.CreateValue();
            var v3 = this.CreateValue();
            var v4 = this.CreateValue();
            var p1 = new Mock <IPipe <T> >();
            var p2 = new Mock <IPipe <T> >();
            var p3 = new Mock <IPipe <T> >();

            p1.Setup(p => p.Pipe(v1)).Returns(v2);
            p2.Setup(p => p.Pipe(v2)).Returns(v3);
            p3.Setup(p => p.Pipe(v3)).Returns(v4);

            var sut = new CompositePipe <T>(p1.Object, p2.Object, p3.Object);

            // Exercise system
            var actual = sut.Pipe(v1);

            // Verify outcome
            Assert.Equal(v4, actual);

            // Teardown
        }
Exemplo n.º 3
0
        public void False_and_true_pipes_returns_false_on_check()
        {
            var pipe = new CompositePipe(new TruePipe(), new FalsePipe(), new TruePipe());

            for (int i = 0; i < 20; i++)
            {
                Assert.False(pipe.Check(i));
            }
        }
Exemplo n.º 4
0
        public void True_only_pipes_returns_true_on_check()
        {
            var pipe = new CompositePipe(new TruePipe(), new TruePipe(), new TruePipe());

            for (int i = 0; i < 20; i++)
            {
                Assert.True(pipe.Check(i));
            }
        }
Exemplo n.º 5
0
        public void SutYieldsInjectedPipes()
        {
            var expected = new[]
            {
                new Mock <IPipe <T> >().Object,
                new Mock <IPipe <T> >().Object,
                new Mock <IPipe <T> >().Object,
            };
            var sut = new CompositePipe <T>(expected);

            Assert.True(expected.SequenceEqual(sut));
            Assert.True(
                expected.Cast <object>().SequenceEqual(sut.OfType <object>()));
        }
Exemplo n.º 6
0
        public void AddTotalToSimpleBasket()
        {
            // Fixture setup
            var basket = new Basket(
                new BasketItem("Chocolate", 50, 2),
                new BasketItem("Rice", 30, 1),
                new BasketItem("Wine", 110, 1));
            var pipe = new CompositePipe <Basket>(
                new BasketVisitorPipe(
                    new BasketTotalVisitor()));
            // Exercise system
            var actual = pipe.Pipe(basket);

            // Verify outcome
            Assert.Equal(
                240,
                actual.OfType <BasketTotal>().Single().Total);
            // Teardown
        }
        public void Should_CallPipe_When_PipelineIsCreated()
        {
            var mockPipe     = new CompositePipe <AnalysisResults>();
            var mockPipeline = Mock.Of <IPipeline <AnalysisResults> >(
                pl => pl.Create() == mockPipe
                );

            var builder = new PipelineFactoryBuilder()
                          .SetPipeline(mockPipeline);

            var mockPipelineFactory = builder.Build();

            var sut = new RepositoryAnalyser(mockPipelineFactory);

            var result = sut.Analyse(builder.RepositoryUrl, builder.RepositoryDestination);

            var expected = mockPipe.Pipe(new AnalysisResults());

            Assert.Equal(expected, result);
        }
Exemplo n.º 8
0
        public void SutIsSequence()
        {
            var sut = new CompositePipe <T>();

            Assert.IsAssignableFrom <IEnumerable <IPipe <T> > >(sut);
        }
Exemplo n.º 9
0
        public void SutIsPipe()
        {
            var sut = new CompositePipe <T>();

            Assert.IsAssignableFrom <IPipe <T> >(sut);
        }
Exemplo n.º 10
0
        public void Pipe_returns_concatenation_of_composed_pipes(IPipe[] pipes, string expected)
        {
            var pipe = new CompositePipe(pipes);

            Assert.Equal(expected, pipe.Process(0));
        }