[4d948b]: test / TestCasesDialog.cs Maximize Restore History

Download this file

TestCasesDialog.cs    120 lines (105 with data), 3.9 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.Common;
namespace test
{
public partial class TestCasesDialog : Form
{
private TestCases _test;
private TestCases _testitems;
public TestCasesDialog()
{
InitializeComponent();
using (DataTable tbl = DbProviderFactories.GetFactoryClasses())
{
foreach (DataRow row in tbl.Rows)
{
string prov = row[2].ToString();
if (prov.IndexOf("SQLite", 0, StringComparison.OrdinalIgnoreCase) != -1
|| prov.IndexOf("SqlClient", 0, StringComparison.OrdinalIgnoreCase) != -1
)
_provider.Items.Add(prov);
if (prov == "System.Data.SQLite") _provider.SelectedItem = prov;
}
}
_connectionString.Items.Add("Data Source=Test.db3;Pooling=true;FailIfMissing=false");
_connectionString.Items.Add("Data Source=(local);Initial Catalog=sqlite;Integrated Security=True;Max Pool Size=10");
_connectionString.SelectedIndex = 0;
_testitems = new TestCases();
foreach (KeyValuePair<string, bool> pair in _testitems.Tests)
{
ToolStripMenuItem item = (ToolStripMenuItem)testMenu.DropDownItems.Add(pair.Key, null, new EventHandler(_tests_Clicked));
item.Checked = true;
item.CheckOnClick = true;
}
}
void _tests_Clicked(object sender, EventArgs e)
{
ToolStripMenuItem item = sender as ToolStripMenuItem;
if (item != null)
_testitems.Tests[item.Text] = item.Checked;
}
private void runButton_Click(object sender, EventArgs e)
{
DbProviderFactory factory = DbProviderFactories.GetFactory(_provider.SelectedItem.ToString());
_test = new TestCases(factory, _connectionString.Text);
_test.Tests = _testitems.Tests;
_test.OnTestStarting += new TestStartingEvent(_test_OnTestStarting);
_test.OnTestFinished += new TestCompletedEvent(_test_OnTestFinished);
_test.OnAllTestsDone += new EventHandler(_test_OnAllTestsDone);
_grid.Rows.Clear();
runButton.Enabled = false;
System.Threading.Thread t = new System.Threading.Thread(new System.Threading.ThreadStart(_threadFunc));
t.IsBackground = true;
t.Start();
}
void _test_OnAllTestsDone(object sender, EventArgs e)
{
if (InvokeRequired)
Invoke(new EventHandler(_test_OnAllTestsDone), sender, e);
else
runButton.Enabled = true;
}
void _threadFunc()
{
_test.Run();
}
void _test_OnTestFinished(object sender, TestEventArgs args)
{
if (InvokeRequired)
Invoke(new TestCompletedEvent(_test_OnTestFinished), sender, args);
else
{
_grid.Rows[_grid.Rows.Count - 1].SetValues(args.TestName, args.Result, args.Duration, (args.Exception == null) ? args.Message : args.Exception.Message);
if (args.Result == TestResultEnum.Failed)
{
_grid.Rows[_grid.Rows.Count - 1].Cells[1].Style.BackColor = Color.Red;
}
else if (args.Result == TestResultEnum.Inconclusive)
{
_grid.Rows[_grid.Rows.Count - 1].Cells[1].Style.BackColor = Color.LightBlue;
}
//_grid.Rows[_grid.Rows.Count - 1].Height = _grid.Rows[_grid.Rows.Count - 1].GetPreferredHeight(_grid.Rows.Count - 1, DataGridViewAutoSizeRowMode.AllCells, true);
}
}
void _test_OnTestStarting(object sender, TestEventArgs args)
{
if (InvokeRequired)
Invoke(new TestStartingEvent(_test_OnTestStarting), sender, args);
else
{
_grid.Rows.Add(args.TestName, "Starting", null, null);
_grid.FirstDisplayedScrollingRowIndex = _grid.Rows.Count - 1;
}
}
private void closeButton_Click(object sender, EventArgs e)
{
Close();
}
}
}