Exemple #1
0
        private IEnumerable <TestCaseData> BuildTestCases(IEnumerable <TestXml> tests)
        {
            var testCases = new List <TestCaseData>(tests.Count());

            foreach (var test in tests)
            {
                TestCaseData testCaseDataNUnit = new TestCaseData(test);
                testCaseDataNUnit.SetName(test.GetName());
                testCaseDataNUnit.SetDescription(test.Description);
                foreach (var category in test.Categories)
                {
                    testCaseDataNUnit.SetCategory(CategoryHelper.Format(category));
                }
                foreach (var property in test.Traits)
                {
                    testCaseDataNUnit.SetProperty(property.Name, property.Value);
                }

                //Assign auto-categories
                if (EnableAutoCategories)
                {
                    foreach (var system in test.Systems)
                    {
                        foreach (var category in system.GetAutoCategories())
                        {
                            testCaseDataNUnit.SetCategory(CategoryHelper.Format(category));
                        }
                    }
                }
                //Assign auto-categories
                if (EnableGroupAsCategory)
                {
                    foreach (var groupName in test.GroupNames)
                    {
                        testCaseDataNUnit.SetCategory(CategoryHelper.Format(groupName));
                    }
                }

                testCases.Add(testCaseDataNUnit);
            }
            return(testCases);
        }
Exemple #2
0
        private IEnumerable <TestCaseData> BuildTestCases(IEnumerable <TestXml> tests)
        {
            var testCases = new List <TestCaseData>(tests.Count());

            foreach (var test in tests)
            {
                // Build different instances for a test, if no instance-settling is defined then the default instance is created
                var instanceArgsBuilder = new InstanceArgsBuilder(serviceLocator, Variables);
                instanceArgsBuilder.Setup(test.InstanceSettling);
                instanceArgsBuilder.Build();

                var factory   = new InstanceFactory();
                var instances = factory.Instantiate(instanceArgsBuilder.GetArgs());

                // For each instance create a test-case
                foreach (var instance in instances)
                {
                    var scalarHelper = new ScalarHelper(serviceLocator, instance.Variables);

                    var testName = instance.IsDefault
                        ? $"{test.GetName()}"
                        : test.GetName().StartsWith("~")
                            ? scalarHelper.InstantiateResolver <string>(test.GetName()).Execute()
                            : $"{test.GetName()} ({instance.GetName()})";
                    Trace.WriteLineIf(Extensibility.NBiTraceSwitch.TraceVerbose, $"Loading test named: {testName}");
                    var testCaseDataNUnit = new TestCaseData(test, testName, instance.Variables);
                    testCaseDataNUnit.SetName(testName);

                    testCaseDataNUnit.SetDescription(test.Description);
                    foreach (var category in test.Categories)
                    {
                        testCaseDataNUnit.SetCategory(CategoryHelper.Format(category));
                    }
                    foreach (var property in test.Traits)
                    {
                        testCaseDataNUnit.SetProperty(property.Name, property.Value);
                    }

                    //Assign instance categories and traits
                    foreach (var category in instance.Categories)
                    {
                        var evaluatedCategory = scalarHelper.InstantiateResolver <string>(category).Execute();
                        testCaseDataNUnit.SetCategory(CategoryHelper.Format(evaluatedCategory));
                    }

                    foreach (var trait in instance.Traits)
                    {
                        var evaluatedTraitValue = scalarHelper.InstantiateResolver <string>(trait.Value).Execute();
                        testCaseDataNUnit.SetProperty(trait.Key, evaluatedTraitValue);
                    }

                    //Assign auto-categories
                    if (EnableAutoCategories)
                    {
                        foreach (var system in test.Systems)
                        {
                            foreach (var category in system.GetAutoCategories())
                            {
                                testCaseDataNUnit.SetCategory(CategoryHelper.Format(category));
                            }
                        }
                    }
                    //Assign auto-categories
                    if (EnableGroupAsCategory)
                    {
                        foreach (var groupName in test.GroupNames)
                        {
                            testCaseDataNUnit.SetCategory(CategoryHelper.Format(groupName));
                        }
                    }

                    testCases.Add(testCaseDataNUnit);
                }
            }
            return(testCases);
        }