Skip to content

Instantly share code, notes, and snippets.

View SergioLuis's full-sized avatar
:bowtie:

Sergio Luis Para SergioLuis

:bowtie:
  • Valladolid, SPAIN
View GitHub Profile
@SergioLuis
SergioLuis / Program-3.cs
Created January 28, 2019 16:55
Initialization code to do different exception trapping depending on the testing flag
public static void Main(string[] args)
{
ApplicationArgs appArgs = ApplicationArgs.Parse(args);
SetExceptionHandlers(appArgs.IsTestingMode);
}
public void SetExceptionHandlers(bool bIsTestingMode)
{
if (!bIsTestingMode)
{
@SergioLuis
SergioLuis / Program-2.cs
Created January 28, 2019 16:54
Typicall initialization code for exception handling
public static void Main(string[] args)
{
// Initialization code
Application.ThreadException += ThreadExceptionHandler;
AppDomain.CurrentDomain.UnhandledException += AppDomainExceptionHandler;
}
static void ThreadExceptionHandler(object sender, ThreadExceptionEventArgs e)
{
// Some logging of the exception
@SergioLuis
SergioLuis / ITesteableInputDialog-4.cs
Created January 28, 2019 16:52
A (bad) example of a ITestableInputDialog
public interface ITestableInputDialog()
{
void SendInput(string text);
void CancelAction();
}
@SergioLuis
SergioLuis / GuiTestImplementation-4.cs
Created January 28, 2019 16:48
Modified the previous test's logic once again.
/* (...) */
testableDialog.ChangeEntryText(“Sergio”);
testableDialog.ClickOkButton();
Assert.IsFalse(testableDialog.IsOkButtonEnabled());
Assert.IsFalse(testableDialog.IsCancelButtonEnabled());
Assert.IsFalse(testableDialog.IsEntryEnabled());
WaitingAssert.IsNullOrWhitespace(
@SergioLuis
SergioLuis / GuiTestImplementation-3.cs
Created January 28, 2019 16:46
Modified the previous test's logic
/*(...)*/
testableDialog.ChangeEntryText(“Sergio”);
testableDialog.ClickOkButton();
WaitingAssert.IsNullOrWhitespace(
testableDialog.GetEntryText,
“The entry text was not cleared in a reasonable time.”);
Assert.IsTrue(testableDialog.IsOkButtonEnabled());
@SergioLuis
SergioLuis / WaitingAssert-2.cs
Created January 28, 2019 16:45
New method to the WaitingAssert class
/*(...)*/
public static void IsNullOrWhitespace(Func<string> stringFunc, string message)
{
int waitTime = 0;
while (waitTime <= MAX_WAIT_TIME)
{
if (string.IsNullOrWhitespace(stringFunc()))
break;
@SergioLuis
SergioLuis / GuiTestImplementation-2.cs
Created January 28, 2019 16:43
Modified the previous test to use the WaitingAssert and the control enablement status
testebleAppWindow.ClickInputButton();
WaitingAssert.IsNotNull(
testableWindow.GetInputDialog,
"The InputDialog was not ready in a reasonable time.");
ITestableInputDialog testableDialog =
testableWindow.GetInputDialog();
testableDialog.ChangeEntryText(“Sergio”);
@SergioLuis
SergioLuis / ITesteableInputDialog-3.cs
Created January 28, 2019 16:42
New methods added to the ITesteableInputDialog definition
public interface ITestableInputDialog
{
// Other methods
bool IsOkButtonEnabled();
bool IsCancelButtonEnabled();
bool IsEntryEnabled();
}
@SergioLuis
SergioLuis / TestHelper-2.cs
Created January 28, 2019 16:40
Some updates to the TestHelper class we had before.
/* (...) */
public bool IsEnabled(Control control)
{
bool result = false;
mControl.Invoke((MethodInvoker)delegate
{ result = control.Enabled; }
return result;
}
/* (...) */
@SergioLuis
SergioLuis / WaitingAssert.cs
Created January 28, 2019 16:39
A class that waits for conditions to be true before firing an exception
public static class WaitingAssert
{
public static void IsTrue(Func<bool> boolFunc, string message)
{
int waitTime = 0;
while (waitTime <= MAX_WAIT_TIME)
{
if (boolFunc())
break;