コード例 #1
0
ファイル: CodeMarkGlyph.xaml.cs プロジェクト: sawilde/Testify
        private void CodeMarkGlyphMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            var glyph = (CodeMarkGlyph)sender;
            UnitTestAdornmentManager manager = UnitTestAdornmentManager.Create(_view);

            //var provider  = Leem.Testify.UnitTestAdornment.UnitTestAdornmentProvider.Create(view);

            ITextSnapshotLine snapshotSpanLine = _view.TextSnapshot.GetLineFromLineNumber(glyph._coveredLine.LineNumber);
            var snapshotSpan      = new SnapshotSpan(snapshotSpanLine.Start, snapshotSpanLine.End);
            var unitTestAdornment = new UnitTestAdornment.UnitTestAdornment(snapshotSpan, glyph._coveredLine,
                                                                            glyph.YPosition);

            _view.GetAdornmentLayer("PostAdornmentLayer").RemoveAllAdornments();
            if (unitTestAdornment.CoveredLine.UnitTests.Any())
            {
                manager.DisplayUnitTestSelector(unitTestAdornment);
            }
        }
コード例 #2
0
        public void DisplayUnitTestSelector(UnitTestAdornment coveredLineInfo)
        {
            SnapshotSpan span = coveredLineInfo.Span.GetSpan(this._view.TextSnapshot);
            //Geometry g = this.view.TextViewLines.GetMarkerGeometry(span);

            //if (g != null)
            //{
            //Find the rightmost coordinate of all the lines that intersect the adornment.
            double maxRight = 0.0;

            foreach (ITextViewLine line in this._view.TextViewLines.GetTextViewLinesIntersectingSpan(span))
            {
                maxRight = Math.Max(maxRight, line.Right);
            }

            var vertPos = this._view.ViewportTop + coveredLineInfo.YPosition + .5 * this._view.LineHeight;
            //Create the visualization.
            var selector = new UnitTestSelector(vertPos, coveredLineInfo, this._layer);

            //Add it to the layer.
            _layer.AddAdornment(span, coveredLineInfo, selector);
            //}
        }
コード例 #3
0
        public UnitTestSelector(double ypos, UnitTestAdornment coveredLineInfo, IAdornmentLayer layer)
        {
            _layer = layer;
            string HeavyCheckMark          = ((char)(0x2714)).ToString();
            string HeavyMultiplicationSign = ((char)(0x2716)).ToString();

            var myResourceDictionary = new ResourceDictionary();

            myResourceDictionary.Source =
                new Uri("/Testify;component/UnitTestAdornment/ResourceDictionary.xaml",
                        UriKind.RelativeOrAbsolute);

            var backgroundBrush = (Brush)myResourceDictionary["BackgroundBrush"];
            var borderBrush     = (Brush)myResourceDictionary["BorderBrush"];
            var textBrush       = (Brush)myResourceDictionary["TextBrush"];

            if (brush == null)
            {
                brush = (Brush)myResourceDictionary["BackgroundBrush"];
                //brush.Freeze();
                var penBrush = (Brush)myResourceDictionary["BorderBrush"];
                //penBrush.Freeze(); Can't be frozen because it is a Dynamic Resource
                solidPen = new Pen(penBrush, 0.5);
                //solidPen.Freeze(); Can't be frozen because it is a Dynamic Resource
                dashPen = new Pen(penBrush, 0.5);
                //dashPen.DashStyle = DashStyles.Dash;
                //dashPen.Freeze(); Can't be frozen because it is a Dynamic Resource
            }


            var tb = new TextBlock();

            tb.Text = " ";
            const int marginWidth = 20;
            var       Margin      = new Thickness(marginWidth, 0, marginWidth, 0);

            Grid postGrid = new Grid();

            postGrid.RowDefinitions.Add(new RowDefinition());
            postGrid.RowDefinitions.Add(new RowDefinition());
            var cEdge = new ColumnDefinition();

            cEdge.Width = new GridLength(1, GridUnitType.Auto);
            var cEdge2 = new ColumnDefinition {
                Width = new GridLength(19, GridUnitType.Star)
            };

            postGrid.ColumnDefinitions.Add(cEdge);
            postGrid.ColumnDefinitions.Add(new ColumnDefinition());
            postGrid.ColumnDefinitions.Add(cEdge2);
            var rect = new Rectangle();

            rect.Fill   = brush;
            rect.Stroke = (Brush)myResourceDictionary["BorderBrush"];

            var inf = new Size(double.PositiveInfinity, double.PositiveInfinity);

            tb.Measure(inf);

            Grid.SetColumn(rect, 0);
            Grid.SetRow(rect, 0);
            Grid.SetRowSpan(rect, 3);
            Grid.SetColumnSpan(rect, 3);
            postGrid.Children.Add(rect);
            double desiredSize = 0;

            var header = new Label {
                Foreground = textBrush, Background = backgroundBrush, BorderBrush = borderBrush
            };

            Grid.SetRow(header, 0);
            Grid.SetColumn(header, 1);
            Grid.SetColumnSpan(header, 3);
            header.Content = string.Format("Unit tests covering Line # {0}", coveredLineInfo.CoveredLine.LineNumber);
            postGrid.Children.Add(header);
            var unitTests       = coveredLineInfo.CoveredLine.UnitTests;
            var sortedUnitTests = unitTests.OrderByDescending(x => x.IsSuccessful ? 0 : 1).ToList();

            for (int i = 0; i < sortedUnitTests.Count; i++)
            {
                UnitTest test = sortedUnitTests.ElementAt(i);
                postGrid.RowDefinitions.Add(new RowDefinition());
                var icon = new Label {
                    Background = backgroundBrush, BorderBrush = borderBrush, FocusVisualStyle = null
                };
                if (test.IsSuccessful)
                {
                    icon.Content    = HeavyCheckMark;
                    icon.Foreground = new SolidColorBrush(Colors.Green);
                }
                else
                {
                    icon.Content    = HeavyMultiplicationSign;
                    icon.Foreground = new SolidColorBrush(Colors.Red);
                }
                //icon.DataContext = test;
                //Binding iconBinding = new Binding("IsSuccessful");
                //icon.SetBinding(TextBox.TextProperty, iconBinding);
                Grid.SetRow(icon, i + 1);
                Grid.SetColumn(icon, 0);
                postGrid.Children.Add(icon);

                var testName = new TextBox
                {
                    Foreground       = textBrush,
                    Background       = backgroundBrush,
                    BorderBrush      = borderBrush,
                    FocusVisualStyle = null,
                    DataContext      = test,
                    Text             = test.TestMethodName,
                    Margin           = Margin
                };

                var testBinding = new Binding("TestMethodName");

                testName.MouseDoubleClick += TestName_MouseDoubleClick;
                testName.SetBinding(TextBox.TextProperty, testBinding);
                Grid.SetRow(testName, i + 1);
                Grid.SetColumn(testName, 1);
                postGrid.Children.Add(testName);
                testName.Measure(inf);

                if (testName.DesiredSize.Width > desiredSize)
                {
                    desiredSize = testName.DesiredSize.Width;
                }
            }

            SetLeft(postGrid, 0);
            SetTop(postGrid, ypos);

            Focus();
            postGrid.Background           = backgroundBrush;
            postGrid.LostFocus           += postGrid_LostFocus;
            postGrid.MouseLeftButtonDown += postGrid_MouseLeftButtonDown;
            Children.Add(postGrid);
        }