Example #1
0
        public static void TestResultSchemaMatches()
        {
            Assert.Multiple(() =>
            {
                var controller = new FrameworkController("mock-assembly", Test.IdPrefix, new Dictionary <string, string>());
                controller.LoadTests();

                var frameworkXml = XElement.Parse(controller.RunTests(null));

                var fullXml = new XElement("test-run",
                                           new XElement("command-line"),
                                           new XElement("filter"),
                                           frameworkXml,
                                           new XAttribute("id", 0),
                                           new XAttribute("name", 0),
                                           new XAttribute("fullname", 0),
                                           new XAttribute("testcasecount", 0),
                                           new XAttribute("result", "Passed"),
                                           new XAttribute("total", 0),
                                           new XAttribute("passed", 0),
                                           new XAttribute("failed", 0),
                                           new XAttribute("inconclusive", 0),
                                           new XAttribute("skipped", 0),
                                           new XAttribute("warnings", 0),
                                           new XAttribute("asserts", 0),
                                           new XAttribute("random-seed", 0));

                SchemaTestUtils.AssertValidXml(fullXml.ToString(), "TestResult.xsd");
            });
        }
Example #2
0
        public override int Execute()
        {
            int errorCount = 0;

            IList <DomainUsage> domainUsages = SchemaTestUtils.GetDomainUsages(_table);

            foreach (DomainUsage domainUsage in domainUsages)
            {
                IDomain domain = domainUsage.Domain;

                string          message;
                TextLengthIssue?lengthIssue = SchemaTestUtils.HasValidLength(
                    domain.Description, _maximumLength, "description", out message);
                if (lengthIssue != null)
                {
                    errorCount += ReportSchemaPropertyError(
                        GetIssueCode(lengthIssue.Value), domain.Name,
                        LocalizableStrings
                        .QaSchemaFieldDomainDescriptions_DomainDescriptionInvalidLength,
                        domain.Name, message, domain.Description);
                }
            }

            if (_requireUniqueDescriptions)
            {
                errorCount += CheckDuplicateDescriptions(domainUsages);
            }

            return(errorCount);
        }
Example #3
0
 public static void TestFilterSchemaMatches()
 {
     Assert.Multiple(() =>
     {
         SchemaTestUtils.AssertValidXml(@"
             <filter>
               <class>c</class>
               <or>
                 <not>
                   <class re='1'>c</class>
                 </not>
                 <and>
                   <cat>c</cat>
                   <cat re='1'>c</cat>
                   <id>i</id>
                   <id re='1'>i</id>
                   <method>m</method>
                   <method re='1'>m</method>
                   <name>n</name>
                   <name re='1'>n</name>
                   <namespace>n</namespace>
                   <namespace re='1'>n</namespace>
                   <prop name='p'>v</prop>
                   <prop name='p' re='1'>v</prop>
                   <test>t</test>
                   <test re='1'>t</test>
                 </and>
               </or>
             </filter>",
                                        "TestFilter.xsd");
     });
 }
Example #4
0
 public static void TestSchemaDisallowsDuplicateIds()
 {
     SchemaTestUtils.AssertInvalidXml(@"
         <test-suite id='0' name='0' fullname='0' runstate='Runnable' type='TestMethod' testcasecount='0'>
           <test-suite id='1' name='0' fullname='0' runstate='Runnable' type='TestMethod' testcasecount='0'>
             <test-case id='0' name='0' fullname='0' runstate='Runnable' seed='0' />
           </test-suite>
         </test-suite>",
                                      "Test.xsd");
 }
        public override int Execute()
        {
            int errorCount = 0;

            foreach (DomainUsage domainUsage in SchemaTestUtils.GetDomainUsages(_table))
            {
                errorCount += CheckDomain(domainUsage);
            }

            return(errorCount);
        }
Example #6
0
        public static void TestSchemaMatches()
        {
            Assert.Multiple(() =>
            {
                var controller = new FrameworkController("mock-assembly", Test.IdPrefix, new Dictionary <string, string>());
                var loadXml    = controller.LoadTests();
                var exploreXml = controller.ExploreTests(null);

                SchemaTestUtils.AssertValidXml(loadXml, "Test.xsd");
                SchemaTestUtils.AssertValidXml(exploreXml, "Test.xsd");
            });
        }
Example #7
0
 public static void TestResultSchemaDisallowsRootElement_TestCase()
 {
     SchemaTestUtils.AssertInvalidXml(@"
         <test-case
           result='Passed'
           asserts='0'
           id='0'
           name='0'
           fullname='0'
           runstate='Runnable'
           seed='0' />",
                                      "TestResult.xsd");
 }
Example #8
0
        public override int Execute()
        {
            var errorCount = 0;

            foreach (DomainUsage domainUsage in SchemaTestUtils.GetDomainUsages(_table))
            {
                foreach (IField referencingField in domainUsage.ReferencingFields)
                {
                    errorCount += CheckDomainUsage(domainUsage.Domain, referencingField);
                }
            }

            return(errorCount);
        }
Example #9
0
 public static void MultipleTestsAreAllowedInsideTestRun()
 {
     Assert.Multiple(() =>
     {
         SchemaTestUtils.AssertValidXml(@"
             <test-run id='0' name='0' fullname='0' testcasecount='0' result='Passed' total='0' passed='0' failed='0' inconclusive='0' skipped='0' warnings='0' asserts='0' random-seed='0'>
               <command-line />
               <filter />
               <test-case result='Passed' asserts='0' id='1' name='0' fullname='0' runstate='Runnable' seed='0' />
               <test-suite result='Passed' asserts='0' total='0' passed='0' failed='0' warnings='0' inconclusive='0' skipped='0' id='2' name='0' fullname='0' runstate='Runnable' type='TestMethod' testcasecount='0' />
               <test-case result='Passed' asserts='0' id='3' name='0' fullname='0' runstate='Runnable' seed='0' />
             </test-run>",
                                        "TestResult.xsd");
     });
 }
Example #10
0
        private int CheckExpectedCase([NotNull] IField field,
                                      [NotNull] string aliasName)
        {
            string message;

            if (SchemaTestUtils.HasExpectedCase(aliasName, _expectedCase, "alias name",
                                                out message))
            {
                return(NoError);
            }

            return(ReportSchemaPropertyError(
                       GetIssueCode(_expectedCase),
                       field.Name,
                       LocalizableStrings.QaSchemaFieldAliases_FieldNameCase,
                       aliasName, field.Name, message));
        }
Example #11
0
        private int CheckMaximumLength([NotNull] IField field,
                                       [NotNull] string aliasName)
        {
            string          message;
            TextLengthIssue?lengthIssue = SchemaTestUtils.HasValidLength(
                aliasName, _maximumLength, "alias name", out message);

            if (lengthIssue == null)
            {
                return(NoError);
            }

            return(ReportSchemaPropertyError(
                       GetIssueCode(lengthIssue.Value), field.Name,
                       LocalizableStrings.QaSchemaFieldAliases_FieldNameCase,
                       aliasName, field.Name, message));
        }
Example #12
0
 public static void TestResultSchemaDisallowsRootElement_TestSuite()
 {
     SchemaTestUtils.AssertInvalidXml(@"
         <test-suite
           result='Passed'
           asserts='0'
           total='0'
           passed='0'
           failed='0'
           warnings='0'
           inconclusive='0'
           skipped='0'
           id='0'
           name='0'
           fullname='0'
           runstate='Runnable'
           type='TestMethod'
           testcasecount='0' />",
                                      "TestResult.xsd");
 }
Example #13
0
        private int ValidateFieldName([NotNull] IField field)
        {
            Assert.ArgumentNotNull(field, nameof(field));

            const int noError = 0;

            if (HasPredefinedName(field))
            {
                return(noError);
            }

            string fieldName = field.Name;

            const string fieldMessageFormat = "Field '{0}': {1}";
            int          errorCount         = 0;
            string       caseMessage;

            if (!SchemaTestUtils.HasExpectedCase(fieldName, _expectedCase, "name",
                                                 out caseMessage))
            {
                errorCount += ReportSchemaPropertyError(
                    GetIssueCode(_expectedCase), fieldName,
                    fieldMessageFormat, fieldName, caseMessage);
            }

            string          lengthMessage;
            TextLengthIssue?lengthIssue = SchemaTestUtils.HasValidLength(
                fieldName, _maximumLength, "name", out lengthMessage);

            if (lengthIssue != null)
            {
                errorCount += ReportSchemaPropertyError(
                    GetIssueCode(lengthIssue.Value), fieldName,
                    fieldMessageFormat, fieldName,
                    lengthMessage);
            }

            return(errorCount);
        }
Example #14
0
        public static void TestResultSchemaMatches()
        {
            Assert.Multiple(() =>
            {
                var result = TestBuilder.RunTestFixture(typeof(MockTestFixture));

                var xml = new StringWriter();
                new NUnit3XmlOutputWriter().WriteResultFile(
                    result,
                    xml,
                    runSettings: new Dictionary <string, object>
                {
                    ["TestDictionary"] = new Dictionary <string, string>
                    {
                        ["TestKey"]      = "TestValue",
                        ["ValuelessKey"] = null
                    }
                },
                    filter: TestFilter.FromXml("<filter><id>x</id><or><not><cat re='1'>c</cat></not><and><prop name='x'>v</prop></and></or></filter>"));

                SchemaTestUtils.AssertValidXml(xml.ToString(), "TestResult.xsd");
            });
        }
Example #15
0
        public static void TestResultSchemaDisallowsDuplicateIds()
        {
            SchemaTestUtils.AssertInvalidXml(@"
                <test-run id='0' name='0' fullname='0' testcasecount='0' result='Passed' total='0' passed='0' failed='0' inconclusive='0' skipped='0' asserts='0' random-seed='0'>
                  <command-line />
                  <filter />
                  <test-suite id='1' result='Passed' asserts='0' total='0' passed='0' failed='0' warnings='0' inconclusive='0' skipped='0' name='0' fullname='0' runstate='Runnable' type='TestMethod' testcasecount='0'>
                    <test-case id='0' result='Passed' asserts='0' name='0' fullname='0' runstate='Runnable' seed='0' />
                  </test-suite>
                </test-run>",
                                             "TestResult.xsd");

            SchemaTestUtils.AssertInvalidXml(@"
                <test-run id='0' name='0' fullname='0' testcasecount='0' result='Passed' total='0' passed='0' failed='0' inconclusive='0' skipped='0' asserts='0' random-seed='0'>
                  <command-line />
                  <filter />
                  <test-suite id='1' result='Passed' asserts='0' total='0' passed='0' failed='0' warnings='0' inconclusive='0' skipped='0' name='0' fullname='0' runstate='Runnable' type='TestMethod' testcasecount='0'>
                    <test-suite id='2' result='Passed' asserts='0' total='0' passed='0' failed='0' warnings='0' inconclusive='0' skipped='0' name='0' fullname='0' runstate='Runnable' type='TestMethod' testcasecount='0'>
                      <test-case id='1' result='Passed' asserts='0' name='0' fullname='0' runstate='Runnable' seed='0' />
                    </test-suite>
                  </test-suite>
                </test-run>",
                                             "TestResult.xsd");
        }
Example #16
0
 public static void TestResultSchemaDisallowsRootElement_Filter()
 {
     SchemaTestUtils.AssertInvalidXml("<filter />", "TestResult.xsd");
 }
Example #17
0
 public static void TestResultSchemaIsValid()
 {
     Assert.Multiple(() => SchemaTestUtils.AssertValidXsd("TestResult.xsd"));
 }
Example #18
0
        private int CheckDomain([NotNull] DomainUsage domainUsage)
        {
            Assert.ArgumentNotNull(domainUsage, nameof(domainUsage));

            string domainName = domainUsage.DomainName;

            int errorCount = 0;

            string caseMessage;

            if (!SchemaTestUtils.HasExpectedCase(domainName, _expectedCase, "name",
                                                 out caseMessage))
            {
                errorCount += ReportSchemaPropertyError(
                    GetIssueCode(_expectedCase), domainName,
                    "Domain name '{0}' has unexpected case: {1}",
                    domainName, caseMessage);
            }

            if (StringUtils.IsNotEmpty(_expectedPrefix))
            {
                if (!domainName.StartsWith(_expectedPrefix))
                {
                    errorCount +=
                        ReportSchemaPropertyError(
                            Codes[Code.DoesStartWithPrefix], domainName,
                            "Domain name '{0}' does not start with prefix '{1}'",
                            domainName, _expectedPrefix);
                }
            }

            if (_mustContainFieldName)
            {
                foreach (IField field in domainUsage.ReferencingFields)
                {
                    string fieldName = field.Name;

                    if (domainName.Contains(fieldName))
                    {
                        continue;
                    }

                    errorCount +=
                        ReportSchemaPropertyError(
                            Codes[Code.DoesNotContainFieldName], domainName,
                            "Domain name '{0}' does not contain the field name '{1}'",
                            domainName, fieldName);
                }
            }

            if (_maximumLength > 0)
            {
                string          message;
                TextLengthIssue?lengthIssue = SchemaTestUtils.HasValidLength(
                    domainName, _maximumLength, "name", out message);
                if (lengthIssue != null)
                {
                    errorCount += ReportSchemaPropertyError(
                        GetIssueCode(lengthIssue.Value), domainName,
                        "Domain '{0}': '{1}'",
                        domainName, message);
                }
            }

            return(errorCount);
        }
Example #19
0
 public override int Execute()
 {
     return
         (SchemaTestUtils.GetDomainUsages(_table).Sum(
              domainUsage => CheckDomain(domainUsage)));
 }
Example #20
0
        private int CheckDomain([NotNull] DomainUsage domainUsage)
        {
            IDomain domain = domainUsage.Domain;

            var codedValueDomain = domain as ICodedValueDomain;

            if (codedValueDomain == null)
            {
                return(NoError);
            }

            List <CodedValue> codedValues = DomainUtils.GetCodedValueList(codedValueDomain);

            int nonEqualNameValueCount = 0;

            int errorCount = 0;

            foreach (CodedValue codedValue in codedValues)
            {
                if (!Equals(codedValue.Value.ToString().Trim(), codedValue.Name.Trim()))
                {
                    nonEqualNameValueCount++;
                }

                if (!StringUtils.IsNotEmpty(codedValue.Name))
                {
                    if (!_allowEmptyName)
                    {
                        errorCount +=
                            ReportSchemaPropertyError(
                                Codes[Code.NoName], domain.Name,
                                new[] { codedValue.Value },
                                "Value [{0}] in coded value domain '{1}' does not have an associated name",
                                codedValue.Value, domain.Name);
                    }

                    continue;
                }

                string          message;
                TextLengthIssue?lengthIssue = SchemaTestUtils.HasValidLength(
                    codedValue.Name, _maximumNameLength, "name", out message);

                if (lengthIssue != null)
                {
                    errorCount +=
                        ReportSchemaPropertyError(GetIssueCode(lengthIssue.Value), domain.Name,
                                                  new[] { codedValue.Value },
                                                  "Value [{0}] in coded value domain '{1}': {2} ('{3}')",
                                                  codedValue.Value, domain.Name, message,
                                                  codedValue.Name);
                }
            }

            // report non-unique names
            errorCount += CheckUniqueNames(domainUsage, codedValues);

            // report error if the number of coded values is less than the minimum count
            if (codedValues.Count < _minimumValueCount)
            {
                string format = codedValues.Count == 1
                                                        ? "Domain '{0}' has {1} coded value. Minimum: {2}"
                                                        : "Domain '{0}' has {1} coded values. Minimum: {2}";

                string description = string.Format(format,
                                                   domainUsage.DomainName, codedValues.Count,
                                                   _minimumValueCount);

                errorCount += ReportSchemaPropertyError(Codes[Code.TooFewCodedValues],
                                                        domainUsage.DomainName, description);
            }

            // report error if the number of coded values with non-equal name/value pair is
            // less than the minimum count for non-equal values (and the total coded value
            // count exceeds that minimum value; otherwise an error would always be reported)
            if (nonEqualNameValueCount < _minimumNonEqualNameValueCount &&
                codedValues.Count >= _minimumNonEqualNameValueCount)
            {
                string description = string.Format(
                    "Domain '{0}' has {1} coded values with a name that is different from the value. Minimum: {2}",
                    domainUsage.DomainName, nonEqualNameValueCount,
                    _minimumNonEqualNameValueCount);

                errorCount +=
                    ReportSchemaPropertyError(Codes[Code.NotEnoughNamesDifferentFromValue],
                                              domainUsage.DomainName, description);
            }

            return(errorCount);
        }
Example #21
0
 public static void TestFilterSchemaDisallowsRootElement_And()
 {
     SchemaTestUtils.AssertInvalidXml("<and><class>x</class></and>", "TestFilter.xsd");
 }