示例#1
0
        static VsTestFilter()
        {
            // Initialize the property cache
            SupportedPropertiesCache = new Dictionary <string, TestProperty>(StringComparer.OrdinalIgnoreCase)
            {
                ["FullyQualifiedName"] = TestCaseProperties.FullyQualifiedName,
                ["Name"]         = TestCaseProperties.DisplayName,
                ["TestCategory"] = CategoryList.NUnitTestCategoryProperty,
                ["Category"]     = CategoryList.NUnitTestCategoryProperty,
            };
            // Initialize the trait cache
            var priorityTrait = new NTrait("Priority", "");
            var categoryTrait = new NTrait("Category", "");

            SupportedTraitCache = new Dictionary <string, NTrait>(StringComparer.OrdinalIgnoreCase)
            {
                ["Priority"]     = priorityTrait,
                ["TestCategory"] = categoryTrait,
                ["Category"]     = categoryTrait
            };
            // Initialize the trait property map, since TFS doesnt know about traits
            TraitPropertyMap = new Dictionary <NTrait, TestProperty>(new NTraitNameComparer());
            var priorityProperty = TestProperty.Find("Priority") ??
                                   TestProperty.Register("Priority", "Priority", typeof(string), typeof(TestCase));

            TraitPropertyMap[priorityTrait] = priorityProperty;
            var categoryProperty = TestProperty.Find("TestCategory") ??
                                   TestProperty.Register("TestCategory", "TestCategory", typeof(string), typeof(TestCase));

            TraitPropertyMap[categoryTrait] = categoryProperty;
            // Initialize a merged list of properties and traits to fool TFS Build to think traits is properties
            SupportedProperties = new List <string>();
            SupportedProperties.AddRange(SupportedPropertiesCache.Keys);
            SupportedProperties.AddRange(SupportedTraitCache.Keys);
        }
示例#2
0
        private void VerifyDummyPropertyIsRegistered()
        {
            var dummyProperty = TestProperty.Find("DummyProperty");

            Assert.IsNotNull(dummyProperty);
            Assert.AreEqual("DummyPropertyLabel", dummyProperty.Label);
            Assert.AreEqual("System.String", dummyProperty.ValueType);
        }
        private void Events_DiscoveredTests(object sender, DiscoveredTestsEventArgs e)
        {
            TestCaseInfos = TestCaseInfos.Concat(e.DiscoveredTestCases.Select(testCase =>
            {
                string name = testCase.DisplayName;

                string[] categories;

                try
                {
                    categories = testCase.GetPropertyValue <string[]>(TestProperty.Find("MSTestDiscoverer.TestCategory"), new string[] { });
                }
                catch
                {
                    categories = new string[] { };
                }

                string description;

                try
                {
                    description = testCase.GetPropertyValue <string>(TestProperty.Find("Description"), String.Empty);
                }
                catch
                {
                    description = String.Empty;
                }

                var testcaseToolTipBuilder = new StringBuilder();

                testcaseToolTipBuilder.Append(name);

                if (categories.Length > 0)
                {
                    testcaseToolTipBuilder.Append(Environment.NewLine + "Category:");

                    foreach (var category in categories)
                    {
                        testcaseToolTipBuilder.Append(Environment.NewLine + "  " + category);
                    }
                }
                if (!string.IsNullOrEmpty(description))
                {
                    testcaseToolTipBuilder.Append(Environment.NewLine + "Description:");

                    testcaseToolTipBuilder.Append(Environment.NewLine + "  " + description);
                }

                return(new TestCaseInfo
                {
                    Category = categories,
                    Description = description,
                    FullName = testCase.FullyQualifiedName,
                    Name = testCase.DisplayName,
                    ToolTipOnUI = testcaseToolTipBuilder.ToString(),
                });
            }));
        }
示例#4
0
        public void SetPropertyValue_Trait_CorrectValidation()
        {
            var testCase = TestDataCreator.CreateDummyTestCases("Foo.Bar").Single().ToVsTestCase();

            testCase.Traits.Add(new Trait("MyTrait", "value1"));

            //registers TestProperty objects for trait names
            // ReSharper disable once ObjectCreationAsStatement
            new TestCaseFilter(MockRunContext.Object, new HashSet <string> {
                "MyTrait"
            }, TestEnvironment.Logger);
            TestProperty property = TestProperty.Find("MyTrait");

            Action action = () => testCase.SetPropertyValue(property, "i");

            action.ShouldNotThrow();

            action = () => testCase.SetPropertyValue(property, "_i");
            action.ShouldNotThrow();

            action = () => testCase.SetPropertyValue(property, "äöüÄÖÜß$");
            action.ShouldNotThrow();

            action = () => testCase.SetPropertyValue(property, "_äöüÄÖÜß$");
            action.ShouldNotThrow();

            // since we are not at the beginning of the method name
            action = () => testCase.SetPropertyValue(property, "1");
            action.ShouldNotThrow();

            action = () => testCase.SetPropertyValue(property, "_1");
            action.ShouldNotThrow();

            action = () => testCase.SetPropertyValue(property, "_");
            action.ShouldNotThrow();

            action = () => testCase.SetPropertyValue(property, "");
            action.ShouldThrow <ArgumentException>().WithMessage("MyTrait");

            action = () => testCase.SetPropertyValue(property, "_(");
            action.ShouldThrow <ArgumentException>().WithMessage("MyTrait");

            action = () => testCase.SetPropertyValue(property, "a(");
            action.ShouldThrow <ArgumentException>().WithMessage("MyTrait");

            action = () => testCase.SetPropertyValue(property, "1(");
            action.ShouldThrow <ArgumentException>().WithMessage("MyTrait");

            action = () => testCase.SetPropertyValue(property, "%");
            action.ShouldThrow <ArgumentException>().WithMessage("MyTrait");

            action = () => testCase.SetPropertyValue(property, "+");
            action.ShouldThrow <ArgumentException>().WithMessage("MyTrait");
        }
示例#5
0
        static IEnumerable <KeyValuePair <string, string> > GetTraits(TestCase testCase)
        {
            var traitProperty = TestProperty.Find("TestObject.Traits");

            if (traitProperty != null)
            {
                return(testCase.GetPropertyValue(traitProperty, Enumerable.Empty <KeyValuePair <string, string> >().ToArray()));
            }

            return(Enumerable.Empty <KeyValuePair <string, string> >());
        }
示例#6
0
        private void InitProperties(ISet <string> traitNames)
        {
            _testPropertiesMap[nameof(TestCaseProperties.FullyQualifiedName)] = TestCaseProperties.FullyQualifiedName;
            _testPropertiesMap[nameof(TestCaseProperties.DisplayName)]        = TestCaseProperties.DisplayName;
            _testPropertiesMap[nameof(TestCaseProperties.LineNumber)]         = TestCaseProperties.LineNumber;
            _testPropertiesMap[nameof(TestCaseProperties.CodeFilePath)]       = TestCaseProperties.CodeFilePath;
            _testPropertiesMap[nameof(TestCaseProperties.ExecutorUri)]        = TestCaseProperties.ExecutorUri;
            _testPropertiesMap[nameof(TestCaseProperties.Id)]     = TestCaseProperties.Id;
            _testPropertiesMap[nameof(TestCaseProperties.Source)] = TestCaseProperties.Source;

            foreach (string traitName in traitNames)
            {
                var traitTestProperty = TestProperty.Find(traitName) ??
                                        TestProperty.Register(traitName, traitName, typeof(string), typeof(TestCase));
                _traitPropertiesMap[traitName] = traitTestProperty;
            }
        }
示例#7
0
        public void TestObjectShouldAddPropertyToTestPropertyStoreOnDeserialize()
        {
            var json = "{\"Properties\":[{\"Key\":{\"Id\":\"17\",\"Label\":\"label1\",\"Category\":\"c\",\"Description\":\"d\",\"Attributes\":0,\"ValueType\":\"System.String\"},\"Value\":\"DummyValue\"}]}";

            var test = Deserialize <TestableTestObject>(json);

            var property = TestProperty.Find("17");

            Assert.IsNotNull(property);
            Assert.AreEqual("17", property.Id);
            Assert.AreEqual("label1", property.Label);
            Assert.AreEqual("c", property.Category);
            Assert.AreEqual("d", property.Description);
            Assert.AreEqual(typeof(string), property.GetValueType());
            Assert.AreEqual(TestPropertyAttributes.None, property.Attributes);
            Assert.AreEqual("DummyValue", test.GetPropertyValue(property));
        }
示例#8
0
        private static TestProperty Convert(this Common.Models.TestProperty testProperty)
        {
            var result = TestProperty.Find(testProperty.Id);

            if (result == null)
            {
                var type = GetType(testProperty.ValueType);
                if (type == null)
                {
                    return(null);
                }

                result             = TestProperty.Register(testProperty.Id, testProperty.Label, type, testProperty.Attributes.Convert(), typeof(ConversionExtensions));
                result.Description = testProperty.Description;
                result.Category    = testProperty.Category;
            }
            return(result);
        }
示例#9
0
        private void InitProperties(ISet <string> traitNames)
        {
            _testPropertiesMap[nameof(TestCaseProperties.FullyQualifiedName)] = TestCaseProperties.FullyQualifiedName;
            _testPropertiesMap[nameof(TestCaseProperties.DisplayName)]        = TestCaseProperties.DisplayName;
            _testPropertiesMap[nameof(TestCaseProperties.LineNumber)]         = TestCaseProperties.LineNumber;
            _testPropertiesMap[nameof(TestCaseProperties.CodeFilePath)]       = TestCaseProperties.CodeFilePath;
            _testPropertiesMap[nameof(TestCaseProperties.ExecutorUri)]        = TestCaseProperties.ExecutorUri;
            _testPropertiesMap[nameof(TestCaseProperties.Id)]     = TestCaseProperties.Id;
            _testPropertiesMap[nameof(TestCaseProperties.Source)] = TestCaseProperties.Source;

            foreach (string traitName in traitNames)
            {
                if (_testPropertiesMap.Keys.Contains(traitName))
                {
                    _logger.LogWarning($"Trait has same name as base test property and will thus be ignored for test case filtering: {traitName}");
                    continue;
                }

                var traitTestProperty = TestProperty.Find(traitName) ??
                                        TestProperty.Register(traitName, traitName, "", "", typeof(string),
                                                              ValidateTraitValue, TestPropertyAttributes.None, typeof(TestCase));
                _traitPropertiesMap[traitName] = traitTestProperty;
            }
        }
示例#10
0
        private void InitProperties(ISet <string> traitNames)
        {
            _testPropertiesMap[nameof(TestCaseProperties.FullyQualifiedName)] = TestCaseProperties.FullyQualifiedName;
            _testPropertiesMap[nameof(TestCaseProperties.DisplayName)]        = TestCaseProperties.DisplayName;
            _testPropertiesMap[nameof(TestCaseProperties.LineNumber)]         = TestCaseProperties.LineNumber;
            _testPropertiesMap[nameof(TestCaseProperties.CodeFilePath)]       = TestCaseProperties.CodeFilePath;
            _testPropertiesMap[nameof(TestCaseProperties.ExecutorUri)]        = TestCaseProperties.ExecutorUri;
            _testPropertiesMap[nameof(TestCaseProperties.Id)]     = TestCaseProperties.Id;
            _testPropertiesMap[nameof(TestCaseProperties.Source)] = TestCaseProperties.Source;

            foreach (string traitName in traitNames)
            {
                if (_testPropertiesMap.Keys.Contains(traitName))
                {
                    _logger.LogWarning(String.Format(Resources.TraitIgnoreMessage, traitName));
                    continue;
                }

                var traitTestProperty = TestProperty.Find(traitName) ??
                                        TestProperty.Register(traitName, traitName, "", "", typeof(string),
                                                              ValidateTraitValue, TestPropertyAttributes.None, typeof(TestCase));
                _traitPropertiesMap[traitName] = traitTestProperty;
            }
        }