SetName() public method

Sets the name of the test case
public SetName ( string name ) : TestCaseData
name string
return TestCaseData
        private static TestCaseData GetTestCaseData(string name)
        {
            var asm = Assembly.GetExecutingAssembly();
            var originalStream = asm.GetManifestResourceStream(typeof (_Dummy), name + ".txt");
            var goldStream = asm.GetManifestResourceStream(typeof (_Dummy), name + ".gold");

            Debug.Assert(originalStream != null, "originalStream != null");
            Debug.Assert(goldStream != null, "goldStream != null");

            string original;
            string gold;

            using (var streamReader = new StreamReader(originalStream, Encoding.UTF8))
                original = streamReader.ReadToEnd();

            using (var streamReader = new StreamReader(goldStream, Encoding.UTF8))
                gold = streamReader.ReadToEnd();

            var testCaseData = new TestCaseData(original);

            testCaseData.SetName(name);
            testCaseData.Returns(gold.Split(new[] {'\r', '\n'}, StringSplitOptions.RemoveEmptyEntries));

            return testCaseData;
        }
 public static IEnumerable<TestCaseData> Suite()
 {
     string[] files = Directory.GetFiles(@"..\..\Ralph.Core.Tests\AstCompareTests\TestCases", "*.cs");
     foreach (string codefile in files)
     {
         string codefile1 = Path.GetFullPath(codefile);
         var tcase = new TestCaseData(codefile1);
         tcase.SetName(Path.GetFileNameWithoutExtension(codefile));
         yield return tcase;
     }
 }
        public static IEnumerable<TestCaseData> ExtractMethodTestFactoryMethod()
        {
            string[] files = Directory.GetFiles(@"..\..\Ralph.Core.Tests\ExtractMethodTests\TestCases", "*.cs");
            foreach (var file in files)
            {
                string codefile = Path.GetFullPath(file);
                string codeText = File.ReadAllText(codefile);

                var testCaseData = new TestCaseData(codeText);
                testCaseData.SetName(Path.GetFileNameWithoutExtension(codefile));
                testCaseData.SetDescription(ParseDesc(codeText));

                yield return testCaseData;
            }
        }
 public static IEnumerable<ITestCaseData> GetTestCases()
 {
     const string prefix = "MongoDB.Driver.Specifications.server_selection.tests.rtt.";
     return Assembly
         .GetExecutingAssembly()
         .GetManifestResourceNames()
         .Where(path => path.StartsWith(prefix) && path.EndsWith(".json"))
         .Select(path =>
         {
             var definition = ReadDefinition(path);
             var fullName = path.Remove(0, prefix.Length);
             var data = new TestCaseData(definition);
             data.Categories.Add("Specifications");
             data.Categories.Add("server-selection");
             return data.SetName(fullName.Remove(fullName.Length - 5));
         });
 }
        /// <summary>
        /// Constructs the specification and builds test cases from the 
        /// <see cref="SpecificationBase.Tests"/>.
        /// </summary>
        IEnumerable<TestMethod> ITestBuilder.BuildFrom(IMethodInfo method, Test suite)
        {
            var tests = new List<TestMethod>();

            try
            {
                var specification = (SpecificationBase)method.TypeInfo.Construct(null);

                foreach (var test in specification.Tests)
                {
                    tests.Add(builder.BuildTestMethod(method, suite, test));
                }
            }
            catch
            {
                var test = new TestCaseData(new Assertion { Action = () => { } });
                test.SetName(method.TypeInfo.Name);
                tests.Add(builder.BuildTestMethod(method, suite, test));
            }

            return tests;
        }
        static ComplexExpressionTreeBuilderExtensionsTests()
        {
            var targetAssembly = Assembly.LoadFrom("TAlex.MathCore.ComplexExpressions.Extensions.dll");

            ConstantFactory = new ConstantFlyweightFactory<object>();
            ConstantFactory.LoadFromAssemblies(new List<Assembly> { targetAssembly });

            FunctionFactory = new FunctionFactory<object>();
            FunctionFactory.LoadFromAssemblies(new List<Assembly> { targetAssembly });

            ExpressionTreeBuilder = new ComplexExpressionTreeBuilder
            {
                ConstantFactory = ConstantFactory,
                FunctionFactory = FunctionFactory
            };

            FunctionsTestCasesData = FunctionFactory.GetMetadata().Select(x =>
            {
                var d = new TestCaseData(x);
                d.SetName(String.Format("ShouldContainsCorrectedExampleUsages: {0}", x.DisplayName));
                return d;
            }).ToList();
        }
        /// <summary>
        /// Reads the data drive file and set test name.
        /// </summary>
        /// <param name="testData">Name of the child element in xml file.</param>
        /// <param name="diffParam">The difference parameter, will be used in test case name.</param>
        /// <param name="testName">Name of the test.</param>
        /// <returns></returns>
        protected IEnumerable<TestCaseData> ReadDataDriveFile(string testData, string[] diffParam, [Optional] string testName)
        {
            var doc = XDocument.Load(Path);
            foreach (XElement element in doc.Descendants(testData))
            {
                var testParams = element.Attributes().ToDictionary(k => k.Name.ToString(), v => v.Value);

                var testCaseName = string.IsNullOrEmpty(testName) ? testData : testName;
                if (diffParam != null && diffParam.Any())
                {
                    foreach (var p in diffParam)
                    {
                        if (testParams[p] != string.Empty)
                        {
                            testCaseName += "_" + testParams[p];
                        }
                    }
                }

                var data = new TestCaseData(testParams);
                data.SetName(testCaseName);
                yield return data;
            }
        }
    public IEnumerable GetObservations()
    {
      var t = GetType();

      var categoryName = "Uncategorized";
      var description = string.Empty;

#if NET_STANDARD
      var categoryAttributes = t.GetTypeInfo().CustomAttributes.Where(ca => ca.AttributeType == typeof(CategoryAttribute));
      var subjectAttributes = t.GetTypeInfo().CustomAttributes.Where(ca => ca.AttributeType == typeof(SubjectAttribute));
#else
      var categoryAttributes = t.GetCustomAttributes(typeof(CategoryAttribute), true);
      var subjectAttributes = t.GetCustomAttributes(typeof(SubjectAttribute), true);
#endif

#if NET_STANDARD
            if (categoryAttributes.Any())
      {
        categoryName = categoryAttributes.First().ConstructorArguments[0].Value.ToString();
#else
      if (categoryAttributes.Length > 0)
      {
        var categoryAttribute = (CategoryAttribute)categoryAttributes[0];
        categoryName = categoryAttribute.Name;
#endif
      }

#if NET_STANDARD
      if (subjectAttributes.Any())
      {
        description = subjectAttributes.First().ConstructorArguments[0].Value.ToString();
#else
            if (subjectAttributes.Length > 0)
      {
        var subjectAttribute = (SubjectAttribute)subjectAttributes[0];
        description = subjectAttribute.Subject;
#endif
      }

      var fieldInfos = t.GetFields(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.FlattenHierarchy);
      var itFieldInfos = new List<FieldInfo>();

      foreach (var info in fieldInfos)
      {
        if (info.FieldType.Name.Equals("It"))
          itFieldInfos.Add(info);
      }

      foreach (var it in itFieldInfos)
      {
        var data = new TestCaseData(it.GetValue(this));
        data.SetDescription(description);
        data.SetName(it.Name.Replace("_", " "));
        data.SetCategory(categoryName);
        yield return data;
      }
    }

    [Test, SpecificationSource("GetObservations")]
 private static IEnumerable<TestCaseData> GetCases()
 {
     return Cases.Select(c =>
         {
             var data = new TestCaseData(c.Value.Item1, c.Value.Item2);
             data.SetName(c.Key);
             return data;
         });
 }
 public static IEnumerable<ITestCaseData> GetTestCases()
 {
     const string prefix = "MongoDB.Driver.Specifications.server_discovery_and_monitoring.tests.";
     return Assembly
         .GetExecutingAssembly()
         .GetManifestResourceNames()
         .Where(path => path.StartsWith(prefix) && path.EndsWith(".json"))
         .Select(path =>
         {
             var definition = ReadDefinition(path);
             var fullName = path.Remove(0, prefix.Length);
             var data = new TestCaseData(definition);
             data.Categories.Add("Specifications");
             data.Categories.Add("server-discovery-and-monitoring");
             return data
                 .SetName(fullName.Remove(fullName.Length - 5).Replace(".", "_"))
                 .SetDescription(definition["description"].ToString());
         });
 }
        protected static IEnumerable<TestCaseData> ConvertCodeFileToTestCaseData(string[] files, MethodsOnASingleClassCloneFinder clonefinder)
        {
            foreach (var file in files)
            {
                var codefile = Path.GetFullPath(file);
                var codeText = File.ReadAllText(codefile);
                var tcase = new TestCaseData(codefile, clonefinder);

                var desc = string.Join(" ", (from str11 in codeText.Split(Environment.NewLine.ToCharArray())
                                             where str11.TrimStart().StartsWith("//")
                                             select str11.Trim().TrimStart('/')).ToArray()).Trim();
                tcase.SetDescription(desc);
                tcase.SetName(Path.GetFileNameWithoutExtension(file));

                if(desc.StartsWith("Ignore"))
                    tcase.Ignore(desc);

                yield return tcase;
            }
        }
Example #12
0
 private static TestCaseData MapTestCaseData(NPQTest qUnitTest)
 {
     var testCase = new TestCaseData(qUnitTest);
     testCase.SetName(qUnitTest.Name);
     testCase.SetDescription(qUnitTest.Description);
     return testCase;
 }
        protected IEnumerable SpecificationFinder()
        {
            var specMethods =
                GetType().GetMethods().Where(x => typeof(Specification).IsAssignableFrom(x.ReturnType));

            foreach (var specMethod in specMethods)
            {
                var testCase = new TestCaseData(specMethod);
                testCase.SetName(getSpecName(specMethod.DeclaringType, specMethod));

                yield return testCase;
            }
        }
            public static IEnumerable<ITestCaseData> GetTestCases()
            {
                const string prefix = "MongoDB.Driver.Tests.Specifications.command_monitoring.tests.";
                var testDocuments = Assembly
                    .GetExecutingAssembly()
                    .GetManifestResourceNames()
                    .Where(path => path.StartsWith(prefix) && path.EndsWith(".json"))
                    .Select(path => ReadDocument(path));

                foreach (var testDocument in testDocuments)
                {
                    var data = testDocument["data"].AsBsonArray.Cast<BsonDocument>().ToList();
                    var databaseName = testDocument["database_name"].ToString();
                    var collectionName = testDocument["collection_name"].ToString();

                    foreach (BsonDocument definition in testDocument["tests"].AsBsonArray)
                    {
                        foreach (var async in new[] { false, true })
                        {
                            var testCase = new TestCaseData(data, databaseName, collectionName, definition, async);
                            testCase.Categories.Add("Specifications");
                            testCase.Categories.Add("command-monitoring");
                            testCase.SetName($"{definition["description"]}({async})");
                            yield return testCase;
                        }
                    }
                }
            }
Example #15
0
            public static IEnumerable<ITestCaseData> GetTestCases()
            {
                const string prefix = "MongoDB.Driver.Tests.Specifications.command_monitoring.tests.";
                return Assembly
                    .GetExecutingAssembly()
                    .GetManifestResourceNames()
                    .Where(path => path.StartsWith(prefix) && path.EndsWith(".json"))
                    .SelectMany(path =>
                    {
                        var doc = ReadDocument(path);
                        var data = ((BsonArray)doc["data"]).Select(x => (BsonDocument)x).ToList();
                        var databaseName = doc["database_name"].ToString();
                        var collectionName = doc["collection_name"].ToString();

                        return ((BsonArray)doc["tests"]).Select(def =>
                        {
                            var testCase = new TestCaseData(data, databaseName, collectionName, (BsonDocument)def);
                            testCase.Categories.Add("Specifications");
                            testCase.Categories.Add("command-monitoring");
                            return testCase.SetName((string)def["description"]);
                        });
                    });
            }
Example #16
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;
        }
Example #17
0
            public static IEnumerable<TestCaseData> LexerFailureCases()
            {
                var f = TestUtils.GetTestPath(@"IronLua.Tests\Scripts\Lexer01_XXX.lua");

                using (var reader = File.OpenText(f))
                {
                    var snippet = new StringBuilder();
                    string line;
                    while ((line = reader.ReadLine()) != null)
                    {
                        if (line.StartsWith("--XX") || line.StartsWith("--::"))
                        {
                            // failure cases
                            var testData = snippet.ToString();
                            var expect = line.TrimStart('-', 'X', ':').Trim();

                            var testCaseData = new TestCaseData(testData, expect);

                            if (line.StartsWith("--XX"))
                                testCaseData.SetProperty("FailureCase", 1);

                            testCaseData.SetName(testData);
                            yield return testCaseData;

                            snippet.Clear();
                        }
                        else if (!line.StartsWith("--"))
                        {
                            snippet.Append(line);
                        }
                    }
                }
            }
Example #18
0
 static TestCaseData AsTestCaseData(SpecificationToRun spec)
 {
     var data = new TestCaseData(spec);
     data.SetName(spec.Specification.GetName());
     return data;
 }
Example #19
0
        private static TestCaseData datumToTestCase(Datum d)
        {
            var ignore = false;
            var quoted = checkQuote(d);
            if(quoted != null)
            {
                d = quoted;
                ignore = true;
            }
            var combo = d.ToArray();

            if (combo.Length < 3)
                throw new Exception(string.Format("'{0}' is not a valid test case", d));
            var name = combo[0] as Symbol;
            if (name == null)
                throw new Exception(string.Format("'{0}' is not a valid test case", d));

            var expected = combo[1];
            var expression = combo[2];
            var testCase = new TestCaseData(expression);
            testCase.Returns(expected);
            testCase.SetName(name.Identifier);
            if (ignore)
                testCase.Ignore("quoted");
            return testCase;
        }
 public static IEnumerable<ITestCaseData> GetTestCases()
 {
     const string prefix = "MongoDB.Driver.Specifications.read_write_concern.tests.connection_string.";
     return Assembly
         .GetExecutingAssembly()
         .GetManifestResourceNames()
         .Where(path => path.StartsWith(prefix) && path.EndsWith(".json"))
         .SelectMany(path =>
         {
             var definition = ReadDefinition(path);
             var tests = (BsonArray)definition["tests"];
             var fullName = path.Remove(0, prefix.Length);
             var list = new List<TestCaseData>();
             foreach (BsonDocument test in tests)
             {
                 var data = new TestCaseData(test);
                 data.Categories.Add("Specifications");
                 if (test.Contains("readConcern"))
                 {
                     data.Categories.Add("ReadConcern");
                 }
                 else
                 {
                     data.Categories.Add("WriteConcern");
                 }
                 data.Categories.Add("ConnectionString");
                 var testName = fullName.Remove(fullName.Length - 5) + ": " + test["description"];
                 list.Add(data.SetName(testName));
             }
             return list;
         });
 }
        /// <summary>
        /// Reads the data drive file and set test name.
        /// </summary>
        /// <param name="testData">Name of the child element in xml file.</param>
        /// <param name="diffParam">The difference parameter, will be used in test case name.</param>
        /// <param name="testName">Name of the test.</param>
        /// <returns></returns>
        protected IEnumerable<TestCaseData> ReadDataDriveFile(string testData, string[] diffParam, [Optional] string testName)
        {
            var doc = XDocument.Load(Path);

            if (!doc.Descendants(testData).Any())
            {
                throw new Exception(string.Format(" Exception while reading Data Driven file\n row '{0}' not found \n in file '{1}'", testData, Path));
            }

            foreach (XElement element in doc.Descendants(testData))
            {
                var testParams = element.Attributes().ToDictionary(k => k.Name.ToString(), v => v.Value);

                var testCaseName = string.IsNullOrEmpty(testName) ? testData : testName;
                if (diffParam != null && diffParam.Any())
                {
                    foreach (var p in diffParam)
                    {
                        string keyValue;
                        bool keyFlag = testParams.TryGetValue(p, out keyValue);

                        if (keyFlag)
                        {
                            if (!string.IsNullOrEmpty(keyValue))
                            {
                                testCaseName += "_" + keyValue;
                            }
                        }
                        else
                        {
                            throw new Exception(string.Format(" Exception while reading Data Driven file\n test data '{0}' \n test name '{1}' \n searched key '{2}' not found in row \n '{3}'  \n in file '{4}'", testData, testName, p, element, Path));
                        }
                    }
                }

                var data = new TestCaseData(testParams);
                data.SetName(testCaseName);
                yield return data;
            }
        }