Esempio n. 1
0
        public void CreateGenerator_GenericGeneratorWithNoTypeArguments_ThrowsError()
        {
            var attr = new GeneratorAttribute(typeof(TestGenericGenerator <,>));

            Assert.That(
                () => attr.CreateGenerator(GetDSLMethod(x => x.GetTestGenerator()), new Dictionary <string, object>()),
                Throws.ArgumentException);
        }
Esempio n. 2
0
        public void CreateGenerator_NonGenericGeneratorFromGenericMethod_ReturnsGenerator()
        {
            var attr = new GeneratorAttribute(typeof(TestGenerator));

            var generator = attr.CreateGenerator(
                GetDSLMethod(x => x.GetTestGenericGenerator <int, string>()),
                new Dictionary <string, object>());

            Assert.That(generator, Is.Not.Null.And.InstanceOf <TestGenerator>());
        }
Esempio n. 3
0
        public void CreateGenerator_GeneratorWithoutParameters_ReturnsGenerator()
        {
            var attr = new GeneratorAttribute(typeof(TestGenerator));

            dynamic generator = attr.CreateGenerator(GetDSLMethod(x => x.GetTestGenerator()), new Dictionary <string, object>());

            Assert.That(generator, Is.Not.Null.And.InstanceOf <TestGenerator>());
            Assert.That(generator.Length, Is.EqualTo(5));
            Assert.That(generator.Source, Is.EqualTo("The really long expression."));
        }
Esempio n. 4
0
        public void CreateGenerator_IncorrectParameters_ThrowsError()
        {
            var attr = new GeneratorAttribute(typeof(TestGenerator));

            Assert.Throws <MissingMethodException>(
                () =>
                attr.CreateGenerator(
                    GetDSLMethod(x => x.GetTestGenerator(1, "adf")),
                    new Dictionary <string, object> {
                ["source1"] = 15, ["length"] = "The short one."
            }));
        }
Esempio n. 5
0
        public void CreateGenerator_GenericGenerator_ReturnsGenerator()
        {
            var attr = new GeneratorAttribute(typeof(TestGenericGenerator <,>));

            dynamic generator = attr.CreateGenerator(
                GetDSLMethod(x => x.GetTestGenericGenerator("a", 33)),
                new Dictionary <string, object> {
                ["value1"] = "test", ["value2"] = 554
            });

            Assert.That(generator, Is.InstanceOf <TestGenericGenerator <string, int> >());
            Assert.That(generator.Value1, Is.EqualTo("test"));
            Assert.That(generator.Value2, Is.EqualTo(554));
        }
Esempio n. 6
0
        public void CreateGenerator_GeneratorWithParameters_ReturnsGenerator()
        {
            var attr = new GeneratorAttribute(typeof(TestGenerator));

            dynamic generator = attr.CreateGenerator(
                GetDSLMethod(x => x.GetTestGenerator(1, "a")),
                new Dictionary <string, object> {
                ["length"] = 15, ["source"] = "The short one."
            });

            Assert.That(generator, Is.Not.Null.And.InstanceOf <TestGenerator>());
            Assert.That(generator.Length, Is.EqualTo(15));
            Assert.That(generator.Source, Is.EqualTo("The short one."));
        }
Esempio n. 7
0
        public void CreateGenerator_WithDefaultParameters_ReturnsGenerator()
        {
            var attr = new GeneratorAttribute(typeof(TestGeneratorWithDefaultParameters));

            dynamic generator = attr.CreateGenerator(
                GetDSLMethod(x => x.GetTestGeneratorWithDefaultParameters(0, "")),
                new Dictionary <string, object> {
                ["numberInteger"] = 10, ["text2"] = "abc"
            });

            Assert.That(generator, Is.InstanceOf <TestGeneratorWithDefaultParameters>());
            Assert.That(generator.NumberInteger, Is.EqualTo(10));
            Assert.That(generator.Text1, Is.EqualTo("a"));
            Assert.That(generator.Text2, Is.EqualTo("abc"));
        }