Summary

Class:SampleAppPlus.MainWindow
Assembly:SampleAppPlus
File(s):C:\SampleAppPlus\SampleAppPlus\MainWindow.xaml
C:\SampleAppPlus\SampleAppPlus\MainWindow.xaml.cs
Covered lines:70
Uncovered lines:7
Coverable lines:77
Total lines:165
Line coverage:90.9%
Branch coverage:75%

Metrics

MethodCyclomatic ComplexitySequence CoverageBranch Coverage
.ctor()1100100
buttonBrowse_Click(...)37260
buttonAdd_Click(...)2100100
buttonEdit_Click(...)2100100
.cctor()1100100
InitializeComponent()2100100
System.Windows.Markup.IComponentConnector.Connect(...)9100100

File(s)

C:\SampleAppPlus\SampleAppPlus\MainWindow.xaml

#LineLine coverage
 21<Window x:Class="SampleAppPlus.MainWindow"
 2        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
 3        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
 4        xmlns:wf="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms"
 5        xmlns:my="clr-namespace:SampleAppPlus"
 6        Title="MainWindow" Height="500" Width="550">
 7    <Grid x:Name="mainGrid">
 8        <Button Content="Browse"
 9                Height="30"
 10                Width="140"
 11                HorizontalAlignment="Left"
 12                VerticalAlignment="Top"
 213                Click="buttonBrowse_Click"
 14                Name="buttonBrowse"
 15                Margin="20,20,0,0" />
 16        <Image Name="MyImage"
 17               Width="230"
 18               Height="230"
 19               HorizontalAlignment="Left"
 20               VerticalAlignment="Top"
 21               Stretch="Fill"
 22               Margin="20,70,0,0" />
 23        <Grid Width="230"
 24              Height="230"
 25              HorizontalAlignment="Right"
 26              VerticalAlignment="Top"
 27              Margin="0,70,20,0">
 28            <WindowsFormsHost x:Name="myHost" />
 29        </Grid>
 30        <Polyline Stroke="Black"
 31                  StrokeThickness="2"
 32                  Points="20,320,530,320" />
 33        <my:CustomControl x:Name="CustomControl"
 34                          Width="510"
 35                          Height="50"
 36                          HorizontalAlignment="Left"
 37                          VerticalAlignment="Bottom"
 38                          Margin="20,20,20,70" />
 39        <Button Content="Add Text"
 40                Height="30"
 41                Width="140"
 42                HorizontalAlignment="Left"
 43                VerticalAlignment="Bottom"
 244                Click="buttonAdd_Click"
 45                Name="buttonAdd"
 46                Margin="20,0,0,20" />
 47        <Button Content="Edit Text"
 48                Height="30"
 49                Width="140"
 50                HorizontalAlignment="Right"
 51                VerticalAlignment="Bottom"
 252                Click="buttonEdit_Click"
 53                Name="buttonEdit"
 54                Margin="0,0,20,20" />
 55    </Grid>
 56</Window>

C:\SampleAppPlus\SampleAppPlus\MainWindow.xaml.cs

#LineLine coverage
 1using System;
 2using System.IO;
 3using System.Windows;
 4using System.Windows.Forms;
 5using System.Windows.Forms.Integration;
 6using System.Windows.Media.Imaging;
 7
 8namespace SampleAppPlus
 9{
 10    /// <summary>
 11    /// Interaction logic for MainWindow.xaml
 12    /// </summary>
 13    public partial class MainWindow : Window
 14    {
 215        private static Action EmptyDelegate = delegate() { };
 16        private DataGridView dataGridView;
 17
 218        public MainWindow()
 219        {
 220            InitializeComponent();
 21            // Initialize host
 222            myHost = new WindowsFormsHost();
 223            myHost.Width = 230;
 224            myHost.Height = 230;
 225            myHost.HorizontalAlignment = System.Windows.HorizontalAlignment.Right;
 226            myHost.VerticalAlignment = System.Windows.VerticalAlignment.Top;
 227            myHost.Margin = new Thickness(0, 70, 20, 0);
 28            // Initialize grid
 229            dataGridView = new DataGridView();
 230            dataGridView.ReadOnly = true;
 231            dataGridView.AllowUserToAddRows = false;
 232            dataGridView.RowHeadersVisible = false;
 33            // Add columnt to grid
 34            DataGridViewColumn col;
 235            col = new DataGridViewColumn();
 236            col.CellTemplate = new DataGridViewTextBoxCell();
 237            col.Name = "File Name";
 238            col.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
 239            dataGridView.Columns.Add(col);
 40            // Add grid to host
 241            myHost.Child = dataGridView;
 42            // Add host to window main grid
 243            mainGrid.Children.Add(myHost);
 44            // Redraw window
 245            WindowStyle = WindowStyle.ThreeDBorderWindow;
 46            // Initialise custom control
 247            CustomControl.Message = "No file...";
 248        }
 49
 50        private void buttonBrowse_Click(object sender, RoutedEventArgs e)
 251        {
 252            Stream checkStream = null;
 253            Microsoft.Win32.OpenFileDialog openFileDialog = new Microsoft.Win32.OpenFileDialog();
 254            openFileDialog.Multiselect = false;
 255            openFileDialog.Filter = "All Image Files | *.*";
 56
 257             if ((bool)openFileDialog.ShowDialog())
 258            {
 59                try
 260                {
 261                     if ((checkStream = openFileDialog.OpenFile()) != null)
 262                    {
 263                        MyImage.Source = new BitmapImage(new Uri(openFileDialog.FileName, UriKind.Absolute));
 264                        CustomControl.Message = openFileDialog.FileName;
 265                        dataGridView.Rows.Add(new object[] { openFileDialog.FileName });
 266                        System.Windows.MessageBox.Show("Successfully done");
 267                    }
 268                }
 069                catch (Exception ex)
 070                {
 071                    System.Windows.MessageBox.Show("Error: Could not read file from disk. Original error: " + ex.Message
 072                }
 73
 274            }
 75            else
 076            {
 077                System.Windows.MessageBox.Show("Problem occured, try again later");
 078            }
 279        }
 80
 81        private void buttonAdd_Click(object sender, RoutedEventArgs e)
 382        {
 383            AddText form = new AddText();
 384            form.text.Focus();
 385            bool? result = form.ShowDialog();
 386             if (result.Value)
 287            {
 288                CustomControl.Message = form.text.Text;
 289                dataGridView.Rows.Add(new object[] { form.text.Text });
 290                dataGridView.ClearSelection();
 291            }
 392        }
 93
 94        private void buttonEdit_Click(object sender, RoutedEventArgs e)
 395        {
 396            EditText form = new EditText();
 397            form.text.Focus();
 398            form.text.Text = dataGridView.Rows[dataGridView.CurrentCell.RowIndex].Cells[0].Value as string;
 399            form.currentText.Text = CustomControl.Message;
 3100            bool? result = form.ShowDialog();
 3101             if (result.Value)
 2102            {
 2103                CustomControl.Message = form.text.Text;
 2104                dataGridView.Rows[dataGridView.CurrentCell.RowIndex].SetValues(form.text.Text);
 2105                dataGridView.ClearSelection();
 2106            }
 3107        }
 108    }
 109}