SetCategory() public method

Applies a category to the test
public SetCategory ( string category ) : TestCaseData
category string
return TestCaseData
Example #1
0
 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.SetCategory("Specifications");
             data.SetCategory("server-selection");
             return data.SetName(fullName.Remove(fullName.Length - 5));
         });
 }
Example #2
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;
        }
    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")]
Example #4
0
 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.SetCategory("Specifications");
             data.SetCategory("server-discovery-and-monitoring");
             return data
                 .SetName(fullName.Remove(fullName.Length - 5).Replace(".", "_"))
                 .SetDescription(definition["description"].ToString());
         });
 }
Example #5
0
            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.SetCategory("Specifications");
                            testCase.SetCategory("command-monitoring");
                            testCase.SetName($"{definition["description"]}({async})");
                            yield return testCase;
                        }
                    }
                }
            }
Example #6
0
 public static IEnumerable<ITestCaseData> GetTestCases()
 {
     const string prefix = "MongoDB.Driver.Specifications.connection_string.tests.";
     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.SetCategory("Specifications");
                 data.SetCategory("ConnectionString");
                 var testName = fullName.Remove(fullName.Length - 5) + ": " + test["description"];
                 if (_ignoredTestNames.Contains(testName))
                 {
                     data = data.Ignore("Does not apply");
                 }
                 list.Add(data.SetName(testName));
             }
             return list;
         });
 }