Esempio n. 1
0
        public void verify_named_start_up_continue_operation()
        {
            var module = new SimplePipelineModule(item =>
                                                      {
                                                          item.RegisterPipeline<IEnumerable<int>, IEnumerable<int>>()
                                                              .Bind<PipelineInjectionTests.Adder, IEnumerable<int>>()
                                                              .Bind<PipelineInjectionTests.Divider, IEnumerable<int>>();

                                                          item.RegisterPipeline<IEnumerable<int>, IEnumerable<string>>()
                                                              .ContinueWith<IEnumerable<int>>()
                                                              .Bind<PipelineInjectionTests.Stringifier>();
                                                      });

            var builder = new ContainerBuilder();
            builder.RegisterModule(module);
            var container = builder.Build();

            var function = container.Resolve<Functor<IEnumerable<int>, IEnumerable<string>>>();

            var items = new[] { 10, 20, 30 };

            var resolvedItems = function(items);

            Assert.That(resolvedItems.Count(), Is.EqualTo(3));
            Assert.That(resolvedItems.ToArray()[0], Is.EqualTo("6"));
            Assert.That(resolvedItems.ToArray()[1], Is.EqualTo("11"));
            Assert.That(resolvedItems.ToArray()[2], Is.EqualTo("16"));
        }
        public void verify_usage_across_multiple_registration_modules()
        {
            var module1 = new SimplePipelineModule(item =>
            {
                item.RegisterPipeline<MultipipelineTests.In, MultipipelineTests.Out>()
                    .Bind<MultipipelineTests.InOutTranslator>();

                item.RegisterPipeline<string, int, string>("foo")
                    .Bind(p => (p * 3).ToString());

            });

            var module2 = new SimplePipelineModule(item => item.RegisterPipeline<int, string>()
                                                               .Bind(p => (p * 2).ToString()));

            var builder = new ContainerBuilder();
            builder.RegisterModule(module1);
            builder.RegisterModule(module2);

            var ctx = builder.Build();

            var value1 = ctx.Resolve<Functor<MultipipelineTests.In, MultipipelineTests.Out>>()(new MultipipelineTests.In()).NewValue;
            var value2 = ctx.Resolve<Functor<int, string>>()(10);
            var value3 = ctx.Resolve<Functor<string, int, string>>()("foo", 10);

            Assert.That(value1, Is.EqualTo(20));
            Assert.That(value2, Is.EqualTo("20"));
            Assert.That(value3, Is.EqualTo("30"));
        }
Esempio n. 3
0
        public void verify_fallback_to_default_named_pipelines()
        {
            var module = new SimplePipelineModule(item =>
                                                      {
                                                          item.RegisterPipeline<int, string>()
                                                              .Alternate<string>()
                                                              .Bind(Convert.ToDouble)
                                                              .ContinueWith<string>();

                                                          item.RegisterPipeline<double, string>()
                                                              .Bind(p => p.ToString());

                                                          item.RegisterPipeline<string, double, string>("foo")
                                                              .Bind(p => (p*2).ToString());
                                                      });

            var builder = new ContainerBuilder();
            builder.RegisterModule(module);

            var ctx = builder.Build();

            var value2 = ctx.Resolve<Functor<int, string>>()(10);
            var value3 = ctx.Resolve<Functor<string, int, string>>()("foo", 10);

            Assert.That(value2, Is.EqualTo("10"));
            Assert.That(value3, Is.EqualTo("20"));
        }
Esempio n. 4
0
        public void verify_incomplete_registration_error()
        {
            var module = new SimplePipelineModule(item => item.RegisterPipeline<IEnumerable<int>, IEnumerable<string>>()
                                                              .Bind(a => from p in a select p + 2)
                                                              .Bind(a => from p in a select p / 2));

            var builder = new ContainerBuilder();
            builder.RegisterModule(module);

            Assert.Throws<MismatchedClosingTypeDeclarationException>(() => builder.Build());
        }
Esempio n. 5
0
        public void verify_ordered_construction()
        {
            var module = new SimplePipelineModule(item => item.RegisterPipeline<IEnumerable<int>, IEnumerable<int>>()
                                                              .Bind(a => from p in a select p / 2)
                                                              .Bind(a => from p in a select p + 2));

            var builder = new ContainerBuilder();
            builder.RegisterModule(module);
            var container = builder.Build();

            var function = container.Resolve<Functor<IEnumerable<int>, IEnumerable<int>>>();
            var items = new[] { 10, 20, 30 };

            var resolvedItems = function(items);

            Assert.That(resolvedItems.Count(), Is.EqualTo(3));
            Assert.That(resolvedItems.ToArray()[0], Is.EqualTo(7));
            Assert.That(resolvedItems.ToArray()[1], Is.EqualTo(12));
            Assert.That(resolvedItems.ToArray()[2], Is.EqualTo(17));
        }
Esempio n. 6
0
        public void verify_failed_call_on_default_when_not_defined()
        {
            var module = new SimplePipelineModule(item =>
            {
                item.RegisterPipeline<int, string>()
                    .Alternate<string>()
                    .Bind(Convert.ToDouble)
                    .ContinueWith<string>();

                item.RegisterPipeline<string, double, string>("foo")
                    .Bind(p => (p * 2).ToString());
            });

            var builder = new ContainerBuilder();
            builder.RegisterModule(module);

            var ctx = builder.Build();

            Assert.Throws<PipelineNotLocatedException>(() => ctx.Resolve<Functor<int, string>>()(10));
            var value3 = ctx.Resolve<Functor<string, int, string>>()("foo", 10);

            Assert.That(value3, Is.EqualTo("20"));
        }