Beispiel #1
0
        public void Build(IEnumerable <string> templates, string[] variables, DataTable dataTable, bool useGrouping, IDictionary <string, object> globalVariables)
        {
            if (templates.Count() == 0)
            {
                throw new ArgumentException("No template was specified. You must at least define a template before generating a test suite.");
            }

            if (templates.Count() == 1)
            {
                Build(templates.ElementAt(0), variables, dataTable, useGrouping, globalVariables);
            }
            else
            {
                var cases = GetCases(dataTable, useGrouping);
                foreach (var indiv in cases)
                {
                    foreach (var template in templates)
                    {
                        var generator = new StringTemplateEngine(template, variables);
                        generator.Progressed += new EventHandler <ProgressEventArgs>(this.OnTestGenerated);
                        lastGeneration        = generator.BuildTests(new List <List <List <object> > >()
                        {
                            indiv
                        }, globalVariables).ToList();
                        generator.Progressed -= new EventHandler <ProgressEventArgs>(this.OnTestGenerated);
                        Tests = Tests.Concat(lastGeneration).ToList();
                    }
                }
            }
        }
Beispiel #2
0
        public void Build_OrderedFullTemplate_CorrectTest()
        {
            var template  = ReadTemplateFile("OrderedFull");
            var variables = new string[] { "perspective", "dimension", "hierarchy", "order", "descending", "exclude" };
            var data      = new List <List <List <object> > >()
            {
                BuildCase(new string[] { "myPerspective", "myDimension", "myHierarchy", "specific", "true", "Unknown" })
            };

            var engine    = new StringTemplateEngine(template, variables);
            var testSuite = engine.Build <TestStandaloneXml>(data, null);
            var test      = testSuite.ElementAt(0);

            //Test the object
            var members = test.Systems[0] as MembersXml;

            Assert.That(members.Exclude.Items, Is.Not.Null.And.Not.Empty);

            var ordered = test.Constraints[0] as OrderedXml;

            Assert.That(ordered.Rule, Is.EqualTo(OrderedXml.Order.Specific));
            Assert.That(ordered.Descending, Is.EqualTo(true));
            Assert.That(ordered.Definition, Is.Not.Null.And.Not.Empty);

            //Test the content serialized
            var content = test.Content;

            Assert.That(content, Does.Contain("rule=\"specific\""));
            Assert.That(content, Does.Contain("descending=\"true\""));
            Assert.That(content, Does.Contain("<rule-definition"));
            Assert.That(content, Does.Contain("<exclude"));
        }
Beispiel #3
0
        public void Build_OrderedLightTemplate_CorrectTest()
        {
            var template  = ReadTemplateFile("OrderedLight");
            var variables = new string[] { "perspective", "dimension", "hierarchy", "order" };
            var data      = new List <List <List <object> > >();

            data.Add(BuildCase(new string[] { "myPerspective", "myDimension", "myHierarchy", "numerical" }));

            var engine    = new StringTemplateEngine(template, variables);
            var testSuite = engine.Build(data);
            var test      = testSuite.ElementAt(0);

            //Test the object
            var members = test.Systems[0] as MembersXml;

            Assert.That(members.Exclude.Items, Is.Null.Or.Empty);
            Assert.That(members.Exclude.Patterns, Is.Null.Or.Empty);

            var ordered = test.Constraints[0] as OrderedXml;

            Assert.That(ordered.Rule, Is.EqualTo(OrderedXml.Order.Numerical));
            Assert.That(ordered.Descending, Is.EqualTo(false));
            Assert.That(ordered.Definition, Is.Null.Or.Empty);

            //Test the content serialized
            var content = test.Content;

            Assert.That(content, Is.StringContaining("rule=\"numerical\""));
            Assert.That(content, Is.Not.StringContaining("descending=\"false\""));
            Assert.That(content, Is.Not.StringContaining("<rule-definition"));
            Assert.That(content, Is.Not.StringContaining("<exclude"));
        }
Beispiel #4
0
 public void Build(string template, string[] variables, DataTable dataTable, bool useGrouping)
 {
     var generator = new StringTemplateEngine(template, variables);
     var cases = GetCases(dataTable, useGrouping);
     generator.Progressed += new EventHandler<ProgressEventArgs>(this.OnTestGenerated);
     lastGeneration = generator.Build(cases).ToList();
     generator.Progressed -= new EventHandler<ProgressEventArgs>(this.OnTestGenerated);
     tests = tests.Concat(lastGeneration).ToList();
 }
Beispiel #5
0
        public void Build(string template, string[] variables, DataTable dataTable, bool useGrouping, IDictionary <string, object> globalVariables)
        {
            var generator = new StringTemplateEngine(template, variables);
            var cases     = GetCases(dataTable, useGrouping);

            generator.Progressed += new EventHandler <ProgressEventArgs>(this.OnTestGenerated);
            lastGeneration        = generator.BuildTests(cases, globalVariables).ToList();
            generator.Progressed -= new EventHandler <ProgressEventArgs>(this.OnTestGenerated);
            Tests = Tests.Concat(lastGeneration).ToList();
        }
Beispiel #6
0
        public void BuildTestString_OneRowWithNotIgnoredVariable_CorrectRenderingTextIsDisplayed()
        {
            var template = "$dimension$ ... $if(ignore)$<ignore>$ignore$</ignore>$endif$";
            var engine = new StringTemplateEngine(template, new string[] { "dimension", "ignore" });

            var values = new List<List<object>>();
            var firstCell = new List<object>() { "myDim" };
            var secondCell = new List<object>() { "reason to ignore" };
            values.Add(firstCell);
            values.Add(secondCell);
            var loaded = new List<string>();

            engine.InitializeTemplate();
            var result = engine.BuildTestString(values);

            Assert.That(result, Is.EqualTo("myDim ... <ignore>reason to ignore</ignore>"));
        }
Beispiel #7
0
        public void BuildTestString_OneRowWithMultipleItems_CorrectRendering()
        {
            var template = "$dimension$ ... <subsetOf>\r\n\t<item>$items; separator=\"</item>\r\n\t<item>\"$</item>\r\n</subsetOf>";
            var engine = new StringTemplateEngine(template, new string[] { "dimension", "items" });

            var values = new List<List<object>>();
            var firstCell = new List<object>() { "myDim" };
            var secondCell = new List<object>() { "item A", "item B" };
            values.Add(firstCell);
            values.Add(secondCell);
            var loaded = new List<string>();

            engine.InitializeTemplate();
            var result = engine.BuildTestString(values);

            Assert.That(result, Is.EqualTo("myDim ... <subsetOf>\r\n\t<item>item A</item>\r\n\t<item>item B</item>\r\n</subsetOf>"));
        }
        public void BuildTestString_EncodeXml_CorrectEncoding()
        {
            var template = "<element attribute=\"$value; format=\"xml-encode\"$\" other-attribute=\"$other$\">";
            var engine = new StringTemplateEngine(template, new string[] { "value", "other" });

            var values = new List<List<object>>();
            var firstCell = new List<object>() { "<value&"};
            var secondCell = new List<object>() { "<value&" };
            values.Add(firstCell);
            values.Add(secondCell);
            var loaded = new List<string>();

            engine.InitializeTemplate();
            var result = engine.BuildTestString(values);

            Assert.That(result, Is.EqualTo("<element attribute=\"&lt;value&amp;\" other-attribute=\"<value&\">"));
        }
Beispiel #9
0
        public void BuildTestString_OneRowWithEmptyVariable_CorrectRenderingTextIsIgnoredAndVariablePlaceHolderIsEmpty()
        {
            var template = "$dimension$ ->$empty$<- ... $if(empty)$<ignore>$empty$</ignore>$endif$";
            var engine = new StringTemplateEngine(template, new string[] { "dimension", "empty" });

            var values = new List<List<object>>();
            var firstCell = new List<object>() { "myDim" };
            var secondCell = new List<object>() { string.Empty };
            values.Add(firstCell);
            values.Add(secondCell);
            var loaded = new List<string>();

            engine.InitializeTemplate();
            var result = engine.BuildTestString(values);

            Assert.That(result, Is.EqualTo("myDim -><- ... "));
        }
Beispiel #10
0
        public void Build_OrderedLightTemplate_ConditionSetupCleanupAreNotAvailable()
        {
            var template  = ReadTemplateFile("OrderedLight");
            var variables = new string[] { "perspective", "dimension", "hierarchy", "order" };
            var data      = new List <List <List <object> > >();

            data.Add(BuildCase(new string[] { "myPerspective", "myDimension", "myHierarchy", "numerical" }));

            var engine    = new StringTemplateEngine(template, variables);
            var testSuite = engine.Build(data);
            var test      = testSuite.ElementAt(0);

            //Test the content serialized
            var content = test.Content;

            Assert.That(content, Is.Not.StringContaining("<setup"));
            Assert.That(content, Is.Not.StringContaining("<condition"));
            Assert.That(content, Is.Not.StringContaining("<cleanup"));
        }
Beispiel #11
0
        public void ReSerialize_ContainWithCaption_ContainItems()
        {
            var template = "<test><system-under-test><members><level/></members></system-under-test><assert><contain caption=\"$member$\"/></assert></test>";
            var engine   = new StringTemplateEngine(template, new string[] { "member" });
            var list     = new List <List <List <object> > >()
            {
                new List <List <object> >()
                {
                    new List <object>()
                    {
                        "myMember"
                    }
                }
            };
            var tests   = engine.Build(list, null);
            var content = tests.ElementAt(0).Content;

            Assert.That(content, Is.StringContaining("<item>"));
            Assert.That(content, Is.StringContaining("myMember"));
            Assert.That(content, Is.Not.StringContaining("caption"));
        }
Beispiel #12
0
        public void BuildTestString_OneSimpleRow_CorrectRendering()
        {
            var template = "<dimension caption='$dimension$' perspective='$perspective$'/>";
            var engine   = new StringTemplateEngine(template, new string[] { "dimension", "perspective" });

            var values    = new List <List <object> >();
            var firstCell = new List <object>()
            {
                "myDim"
            };
            var secondCell = new List <object>()
            {
                "myPersp"
            };

            values.Add(firstCell);
            values.Add(secondCell);

            engine.InitializeTemplate(null);
            var result = engine.RenderTemplate(values);

            Assert.That(result, Is.EqualTo("<dimension caption='myDim' perspective='myPersp'/>"));
        }
Beispiel #13
0
        public void BuildTestString_OneRowWithMultipleItems_CorrectRendering()
        {
            var template = "$dimension$ ... <subsetOf>\r\n\t<item>$items; separator=\"</item>\r\n\t<item>\"$</item>\r\n</subsetOf>";
            var engine   = new StringTemplateEngine(template, new string[] { "dimension", "items" });

            var values    = new List <List <object> >();
            var firstCell = new List <object>()
            {
                "myDim"
            };
            var secondCell = new List <object>()
            {
                "item A", "item B"
            };

            values.Add(firstCell);
            values.Add(secondCell);

            engine.InitializeTemplate(null);
            var result = engine.RenderTemplate(values);

            Assert.That(result, Is.EqualTo("myDim ... <subsetOf>\r\n\t<item>item A</item>\r\n\t<item>item B</item>\r\n</subsetOf>"));
        }
Beispiel #14
0
        public void BuildTestString_OneRowWithEmptyVariable_CorrectRenderingTextIsIgnoredAndVariablePlaceHolderIsEmpty()
        {
            var template = "$dimension$ ->$empty$<- ... $if(empty)$<ignore>$empty$</ignore>$endif$";
            var engine   = new StringTemplateEngine(template, new string[] { "dimension", "empty" });

            var values    = new List <List <object> >();
            var firstCell = new List <object>()
            {
                "myDim"
            };
            var secondCell = new List <object>()
            {
                string.Empty
            };

            values.Add(firstCell);
            values.Add(secondCell);

            engine.InitializeTemplate(null);
            var result = engine.RenderTemplate(values);

            Assert.That(result, Is.EqualTo("myDim -><- ... "));
        }
Beispiel #15
0
        public void BuildTestString_OneRowWithNotIgnoredVariable_CorrectRenderingTextIsDisplayed()
        {
            var template = "$dimension$ ... $if(ignore)$<ignore>$ignore$</ignore>$endif$";
            var engine   = new StringTemplateEngine(template, new string[] { "dimension", "ignore" });

            var values    = new List <List <object> >();
            var firstCell = new List <object>()
            {
                "myDim"
            };
            var secondCell = new List <object>()
            {
                "reason to ignore"
            };

            values.Add(firstCell);
            values.Add(secondCell);

            engine.InitializeTemplate(null);
            var result = engine.RenderTemplate(values);

            Assert.That(result, Is.EqualTo("myDim ... <ignore>reason to ignore</ignore>"));
        }
Beispiel #16
0
        public void BuildTestString_EncodeXml_CorrectEncoding()
        {
            var template = "<element attribute=\"$value; format=\"xml-encode\"$\" other-attribute=\"$other$\">";
            var engine   = new StringTemplateEngine(template, new string[] { "value", "other" });

            var values    = new List <List <object> >();
            var firstCell = new List <object>()
            {
                "<value&"
            };
            var secondCell = new List <object>()
            {
                "<value&"
            };

            values.Add(firstCell);
            values.Add(secondCell);

            engine.InitializeTemplate(null);
            var result = engine.RenderTemplate(values);

            Assert.That(result, Is.EqualTo("<element attribute=\"&lt;value&amp;\" other-attribute=\"<value&\">"));
        }
Beispiel #17
0
        public void Build_OrderedLightTemplate_CorrectTest()
        {
            var template = ReadTemplateFile("OrderedLight");
            var variables = new string[] { "perspective", "dimension", "hierarchy", "order" };
            var data = new List<List<List<object>>>();
            data.Add(BuildCase(new string[] { "myPerspective", "myDimension", "myHierarchy", "numerical" }));

            var engine = new StringTemplateEngine(template, variables);
            var testSuite = engine.Build(data);
            var test = testSuite.ElementAt(0);

            //Test the object
            var members = test.Systems[0] as MembersXml;
            Assert.That(members.Exclude.Items, Is.Null.Or.Empty);
            Assert.That(members.Exclude.Patterns, Is.Null.Or.Empty);

            var ordered = test.Constraints[0] as OrderedXml;
            Assert.That(ordered.Rule, Is.EqualTo(OrderedXml.Order.Numerical));
            Assert.That(ordered.Descending, Is.EqualTo(false));
            Assert.That(ordered.Definition, Is.Null.Or.Empty);

            //Test the content serialized
            var content = test.Content;
            Assert.That(content, Is.StringContaining("rule=\"numerical\""));
            Assert.That(content, Is.Not.StringContaining("descending=\"false\""));
            Assert.That(content, Is.Not.StringContaining("<rule-definition"));
            Assert.That(content, Is.Not.StringContaining("<exclude"));
        }
Beispiel #18
0
        public void Build_OrderedLightTemplate_ConditionSetupCleanupAreNotAvailable()
        {
            var template = ReadTemplateFile("OrderedLight");
            var variables = new string[] { "perspective", "dimension", "hierarchy", "order" };
            var data = new List<List<List<object>>>();
            data.Add(BuildCase(new string[] { "myPerspective", "myDimension", "myHierarchy", "numerical" }));

            var engine = new StringTemplateEngine(template, variables);
            var testSuite = engine.Build(data);
            var test = testSuite.ElementAt(0);

            //Test the content serialized
            var content = test.Content;
            Assert.That(content, Is.Not.StringContaining("<setup"));
            Assert.That(content, Is.Not.StringContaining("<condition"));
            Assert.That(content, Is.Not.StringContaining("<cleanup"));
        }
Beispiel #19
0
        public void BuildTestString_OneSimpleRow_CorrectRendering()
        {
            var template = "<dimension caption='$dimension$' perspective='$perspective$'/>";
            var engine = new StringTemplateEngine(template, new string[] {"dimension", "perspective"});

            var values = new List<List<object>>();
            var firstCell = new List<object>() {"myDim"};
            var secondCell = new List<object>() {"myPersp"};
            values.Add(firstCell);
            values.Add(secondCell);
            var loaded = new List<string>();

            engine.InitializeTemplate();
            var result = engine.BuildTestString(values);

            Assert.That(result, Is.EqualTo("<dimension caption='myDim' perspective='myPersp'/>"));
        }
Beispiel #20
0
        private string ApplyVariablesToTemplate(string template, IEnumerable <IQueryTemplateVariable> variables)
        {
            var templateEngine = new StringTemplateEngine(template, variables);

            return(templateEngine.Build());
        }
Beispiel #21
0
 private string ApplyVariablesToTemplate(string template, IEnumerable<IQueryTemplateVariable> variables)
 {
     var templateEngine = new StringTemplateEngine(template, variables);
     return templateEngine.Build();
 }