miniSql

创建
zgc123@gmail.com authored at 11/19/2023 1:40:15 AM
6136600
Tree
0 Parent(s)
Summary: 1 changed files with 79 additions and 0 deletions.
Added +79 -0
Added +79 -0
diff --git a/minisqlquery-master/src/MiniSqlQuery.Tests/Gui/QueryFormTester.cs b/minisqlquery-master/src/MiniSqlQuery.Tests/Gui/QueryFormTester.cs
new file mode 100644
index 0000000..ca32e56
--- /dev/null
+++ b/minisqlquery-master/src/MiniSqlQuery.Tests/Gui/QueryFormTester.cs
@@ -0,0 +1,79 @@
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using System.Linq;
+using System.Windows.Forms;
+using MiniSqlQuery.Core;
+using NUnit.Extensions.Forms;
+using Rhino.Mocks;
+
+namespace MiniSqlQuery.Tests.Gui
+{
+	/// <summary>
+	/// Query Form Tester class for use with NUnitForms.
+	/// Inherit from this class in standard unit tests.
+	/// </summary>
+	public class QueryFormTester : NUnitFormTest
+	{
+		protected IApplicationServices StubAppServices;
+		protected IApplicationSettings StubAppSettings;
+		protected IHostWindow StubHostWindow;
+		protected IQueryEditor QueryEditor;
+		protected QueryForm QueryForm;
+
+		public QueryFormTester()
+		{
+		}
+
+		/// <summary>
+		/// Sets up various mock object required for the form to run (does not cover query execution).
+		/// </summary>
+		public override void Setup()
+		{
+			SetUpApplicationServicesMock();
+			SetUpApplicationSettingsMock();
+			SetUpHostWindowMock();
+			base.Setup();
+		}
+
+		/// <summary>
+		/// Sets up an empty <see cref="IApplicationServices"/> mock object.
+		/// </summary>
+		public virtual void SetUpApplicationServicesMock()
+		{
+			StubAppServices = MockRepository.GenerateStub<IApplicationServices>();
+		}
+
+		/// <summary>
+		/// Sets up an empty <see cref="IApplicationSettings"/> mock object.
+		/// </summary>
+		public virtual void SetUpApplicationSettingsMock()
+		{
+			StubAppSettings = MockRepository.GenerateStub<IApplicationSettings>();
+		}
+
+		/// <summary>
+		/// Sets up a basic <see cref="IHostWindow"/> mock assigning it to <see cref="ApplicationServices"/>.
+		/// </summary>
+		/// <remarks>
+		/// The SetStaus method just takes any parameters.
+		/// </remarks>
+		public virtual void SetUpHostWindowMock()
+		{
+			StubHostWindow = MockRepository.GenerateStub<IHostWindow>();
+			StubAppServices.Expect(services => services.HostWindow).Return(StubHostWindow).Repeat.Any();
+		}
+
+		/// <summary>
+		/// Displays an basic query editor form with the relevent dependency injection applied.
+		/// </summary>
+		public virtual void ShowBasicForm()
+		{
+			QueryForm = new QueryForm(StubAppServices, StubAppSettings);
+			QueryEditor = QueryForm; // for reference by interface 
+
+			QueryForm.Show();
+			Application.DoEvents(); // ensure fully displayed
+		}
+	}
+}
\ No newline at end of file