public static IList <string> BddPrefixes(this TestFileAnalysisSettings settings)
        {
            List <string> list = (settings.BddPrefix ?? "").Split(',').ToList();

            list.RemoveAll(string.IsNullOrEmpty);
            return(list);
        }
        public static IList <string> TestingAttributes(this TestFileAnalysisSettings settings)
        {
            List <string> list = (settings.TestingAttributeText ?? "").Split(',').ToList();

            list.RemoveAll(string.IsNullOrEmpty);
            return(list);
        }
        public static IList <string> TestClassSuffixes(this TestFileAnalysisSettings settings)
        {
            List <string> list = (settings.TestClassSuffix ?? "").Split(',').ToList();

            list.RemoveAll(string.IsNullOrEmpty);
            list.Sort((a, b) => b.Length - a.Length);
            return(list);
        }
        public void TestClassSuffixesHandlesSingleEntry()
        {
            var settings = new TestFileAnalysisSettings {
                TestClassSuffix = "Tests"
            };

            Assert.AreEqual(1, settings.TestClassSuffixes().Count);
            Assert.AreEqual("Tests", settings.TestClassSuffixes()[0]);
        }
        public void TestClassSuffixesAreSortedLongestFirst()
        {
            var settings = new TestFileAnalysisSettings {
                TestClassSuffix = "Tests,IntegrationTests,Test"
            };

            Assert.AreEqual(3, settings.TestClassSuffixes().Count);
            Assert.AreEqual("IntegrationTests", settings.TestClassSuffixes()[0]);
            Assert.AreEqual("Tests", settings.TestClassSuffixes()[1]);
            Assert.AreEqual("Test", settings.TestClassSuffixes()[2]);
        }
        public static IEnumerable <string> GetAppropriateTestClassSuffixes(this TestFileAnalysisSettings settings,
                                                                           string baseFileName)
        {
            var testClassSuffixes = settings.TestClassSuffixes();

            if (baseFileName.EndsWith(testClassSuffixes))
            {
                return(new[] { testClassSuffixes.First(baseFileName.EndsWith) });
            }
            return(testClassSuffixes);
        }
示例#7
0
        private void BindWithValidationMustBeAFileTemplate(TestFileAnalysisSettings testFileAnalysisSettings, TextBox tb, string property)
        {
            var boundSettingsStore = _application.Settings.BindToContextTransient(ContextRange.ApplicationWide);

            var binding = new Binding {
                Path = new PropertyPath(property)
            };
            var rule = new IsAFileTemplateValidationRule(_lifetime, _storedTemplatesProvider, boundSettingsStore);

            binding.ValidationRules.Add(rule);
            binding.NotifyOnValidationError = true;
            binding.UpdateSourceTrigger     = UpdateSourceTrigger.PropertyChanged;
            tb.DataContext = testFileAnalysisSettings;
            tb.SetBinding(TextBox.TextProperty, binding);
        }
示例#8
0
        public static void BindWithValidationMustBeARegex(this TextBox tb, TestFileAnalysisSettings testFileAnalysisSettings, string property)
        {
            var binding = new Binding {
                Path = new PropertyPath(property)
            };
            var namespaceRule = new IsARegexValidationRule
            {
                ErrorMessage             = "Invalid Regex",
                RegexOptions             = RegexOptions.IgnoreCase,
                MinimumGroupsInRegex     = 2,
                ValidatesOnTargetUpdated = true
            };

            binding.ValidationRules.Add(namespaceRule);
            binding.NotifyOnValidationError = true;
            binding.ValidatesOnDataErrors   = true;
            binding.ValidatesOnExceptions   = true;
            binding.UpdateSourceTrigger     = UpdateSourceTrigger.PropertyChanged;
            tb.DataContext = testFileAnalysisSettings;
            tb.SetBinding(TextBox.TextProperty, binding);
        }
示例#9
0
        public static void BindWithRegexMatchesValidation(this TextBox tb, TestFileAnalysisSettings testFileAnalysisSettings, string property, string regexString, string errorMessage = "Invalid suffix.")
        {
            var binding = new Binding {
                Path = new PropertyPath(property)
            };
            var namespaceRule = new RegexValidationRule
            {
                RegexText                = regexString,
                ErrorMessage             = errorMessage,
                RegexOptions             = RegexOptions.IgnoreCase,
                ValidatesOnTargetUpdated = true
            };

            binding.ValidationRules.Add(namespaceRule);
            binding.NotifyOnValidationError = true;
            binding.ValidatesOnDataErrors   = true;
            binding.ValidatesOnExceptions   = true;
            binding.UpdateSourceTrigger     = UpdateSourceTrigger.PropertyChanged;
            tb.DataContext = testFileAnalysisSettings;
            tb.SetBinding(TextBox.TextProperty, binding);
        }
示例#10
0
        private void BuildTestStrategyCombo(TestFileAnalysisSettings testFileAnalysisSettings)
        {
            MultiTestRegex.Tag              = MultiTestRegexHelp.Tag = TestProjectStrategy.TestProjectPerCodeProject;
            SingleTestRegex.Tag             = SingleTestRegexHelp.Tag = TestProjectStrategy.SingleTestProjectPerSolution;
            MultiTestSameNamespaceRegex.Tag = TestProjectStrategy.TestProjectHasSameNamespaceAsCodeProject;

            TestCopStrategyCombo.Items.Clear();

            foreach (var value in Enum.GetValues(typeof(TestProjectStrategy)).Cast <TestProjectStrategy>())
            {
                var item = new ListBoxItem()
                {
                    Content = value.GetDescription(), Tag = value
                };
                TestCopStrategyCombo.Items.Add(item);

                if (value == testFileAnalysisSettings.TestCopProjectStrategy)
                {
                    TestCopStrategyCombo.SelectedItem = item;
                }
            }
        }
示例#11
0
        protected static IEnumerable <TestCopProjectItem.FilePatternMatcher> AssociatedFileNames(TestFileAnalysisSettings settings, string className)
        {
            string classNameUnderTest = className;

            foreach (var suffix in settings.TestClassSuffixes())
            {
                if (className.EndsWith(suffix))
                {
                    classNameUnderTest = className.Split(new[] { '.' }, 2)[0].RemoveTrailing(suffix);
                    break;
                }
            }

            if (className != classNameUnderTest)
            {
                yield return(new TestCopProjectItem.FilePatternMatcher(new Regex(classNameUnderTest), ""));
            }
            else
            {
                foreach (var suffix in settings.TestClassSuffixes())
                {
                    yield return(new TestCopProjectItem.FilePatternMatcher(new Regex(string.Format(@"{0}{1}", classNameUnderTest, suffix)), suffix));     //e.g. Class1Tests

                    yield return(new TestCopProjectItem.FilePatternMatcher(new Regex(string.Format(@"{0}\..*{1}", classNameUnderTest, suffix)), suffix)); //e.g. Class1.SecurityTests
                }
            }
        }
示例#12
0
        public TestCopOptionPage(Lifetime lifetime, OptionsSettingsSmartContext settings, TemplateScopeManager scopeManager
                                 , IThemedIconManager iconManager, IUIApplication application
                                 , StoredTemplatesProvider storedTemplatesProvider, ILiveTemplatesUIHelper templatesUiHelper, FileTemplatesManager fileTemplatesManager, ISolution solution = null)
        {
            _lifetime                = lifetime;
            _settings                = settings;
            _scopeManager            = scopeManager;
            _application             = application;
            _solution                = solution;
            _fileTemplatesManager    = fileTemplatesManager;
            _storedTemplatesProvider = storedTemplatesProvider;
            _templatesUiHelper       = templatesUiHelper;
            _logger = Logger.GetLogger <TestCopOptionPage>();

            InitializeComponent();
            TestFileAnalysisSettings testFileAnalysisSettings = settings.GetKey <TestFileAnalysisSettings>(SettingsOptimization.DoMeSlowly);

            InitializeComponent();
            BuildTestStrategyCombo(testFileAnalysisSettings);

            //Do this first as it is reference by other display fields
            testClassSuffixTextBox.BindWithRegexMatchesValidation(testFileAnalysisSettings, P(x => x.TestClassSuffix), TestClassSuffixValidationRegEx);

            //Regex Config for Multiple Test Assembly Logic via project naming
            testProjectNameRegExTextBox.BindWithValidationMustBeARegex(testFileAnalysisSettings, P(x => x.TestProjectNameToCodeProjectNameRegEx));
            testProjectNameRegExReplaceTextBox.BindWithRegexMatchesValidation(testFileAnalysisSettings, P(x => x.TestProjectNameToCodeProjectNameRegExReplace), ValidationRegEx);

            //Regex Config for Multiple Test Assembly Logic via namespace naming
            testNamespaceRegExTextBox.BindWithValidationMustBeARegex(testFileAnalysisSettings, P(x => x.TestProjectToCodeProjectNameSpaceRegEx));
            testNamespaceRegExReplaceTextBox.BindWithRegexMatchesValidation(testFileAnalysisSettings, P(x => x.TestProjectToCodeProjectNameSpaceRegExReplace), ValidationRegEx);

            //Regex Config for Single Test Assembly Logic
            SingleTestNamespaceRegExTextBox.BindWithValidationMustBeARegex(testFileAnalysisSettings, P(x => x.SingleTestRegexTestToAssembly));
            SingleTestNamespaceToAssemblyRegExReplaceTextBox.BindWithRegexMatchesValidation(testFileAnalysisSettings, P(x => x.SingleTestRegexTestToAssemblyProjectReplace), ValidationRegEx);
            SingleTestNamespaceToAssemblySubNameSpaceRegExReplaceTextBox.BindWithRegexMatchesValidation(testFileAnalysisSettings, P(x => x.SingleTestRegexTestToAssemblyProjectSubNamespaceReplace), ValidationRegEx);
            SingleTestCodeNamespaceRegExTextBox.BindWithValidationMustBeARegex(testFileAnalysisSettings, P(x => x.SingleTestRegexCodeToTestAssembly));
            SingleTestCodeNamespaceToTestRegExReplaceTextBox.BindWithRegexMatchesValidation(testFileAnalysisSettings, P(x => x.SingleTestRegexCodeToTestReplace), ValidationRegEx);
            //

            foreach (string testingAttribute in testFileAnalysisSettings.TestingAttributes())
            {
                this.testingAttributesListBox.Items.Add(testingAttribute);
            }
            foreach (string bddPrefix in testFileAnalysisSettings.BddPrefixes())
            {
                this.contextPrefixesListBox.Items.Add(bddPrefix);
            }

            OrphanedFilesPatternsTextBox.Text = testFileAnalysisSettings.OrphanedFilesPatterns;

            BindWithValidationMustBeAFileTemplate(testFileAnalysisSettings, codeTemplateTextBox, P(x => x.CodeFileTemplateName));
            BindWithValidationMustBeAFileTemplate(testFileAnalysisSettings, unitTestTemplateTextBox, P(x => x.UnitTestFileTemplateName));

            ShowAllTestsWithUsageCheckBox.IsChecked   = testFileAnalysisSettings.FindAnyUsageInTestAssembly;
            CheckTestNamespaces.IsChecked             = testFileAnalysisSettings.CheckTestNamespaces;
            CheckSearchForOrphanedCodeFiles.IsChecked = testFileAnalysisSettings.FindOrphanedProjectFiles;
            SupportRenameRefactor.IsChecked           = testFileAnalysisSettings.SupportRenameRefactor;

            OutputPanelOpenOnKeyboardMapping.IsChecked = testFileAnalysisSettings.OutputPanelOpenOnKeyboardMapping;

            TestCopLogoImage.Source =
                (ImageSource) new BitmapToImageSourceConverter().Convert(
                    iconManager.Icons[UnnamedThemedIcons.Agent64x64.Id].CurrentGdipBitmap96, null, null, null);
        }