Skip to content

Commit

Permalink
Add DispIds, implement InputBox fake, remove dead TestRunner code.
Browse files Browse the repository at this point in the history
  • Loading branch information
comintern committed Mar 19, 2017
1 parent fb4a835 commit e88704b
Show file tree
Hide file tree
Showing 11 changed files with 96 additions and 114 deletions.
3 changes: 1 addition & 2 deletions RetailCoder.VBE/Rubberduck.csproj
Expand Up @@ -504,6 +504,7 @@
<Compile Include="UnitTesting\Fakes\FakesProviderFactory.cs" />
<Compile Include="UnitTesting\Fakes\IFake.cs" />
<Compile Include="UnitTesting\Fakes\IFakesProvider.cs" />
<Compile Include="UnitTesting\Fakes\InputBox.cs" />
<Compile Include="UnitTesting\Fakes\IVerify.cs" />
<Compile Include="UnitTesting\Fakes\MsgBox.cs" />
<Compile Include="UnitTesting\Fakes\ReturnTypeConverter.cs" />
Expand Down Expand Up @@ -1051,15 +1052,13 @@
<Compile Include="UnitTesting\UnitTestUtils.cs" />
<Compile Include="UnitTesting\IAssert.cs" />
<Compile Include="UnitTesting\ITestEngine.cs" />
<Compile Include="UnitTesting\ITestRunner.cs" />
<Compile Include="UnitTesting\ProjectTestExtensions.cs" />
<Compile Include="UnitTesting\TestEngine.cs" />
<Compile Include="UnitTesting\TestMethod.cs" />
<Compile Include="UnitTesting\TestOutcome.cs" />
<Compile Include="UI\UnitTesting\TestOutcomeImageSourceConverter.cs" />
<Compile Include="UnitTesting\TestResult.cs" />
<Compile Include="UI\UnitTesting\TestResultToOutcomeTextConverter.cs" />
<Compile Include="UnitTesting\TestRunner.cs" />
<Compile Include="UnitTesting\PermissiveAssertClass.cs" />
<Compile Include="UI\Command\Refactorings\RefactorCommandBase.cs" />
<Compile Include="UI\Command\Refactorings\RefactorExtractMethodCommand.cs" />
Expand Down
9 changes: 9 additions & 0 deletions RetailCoder.VBE/UnitTesting/Fakes/FakeBase.cs
Expand Up @@ -33,6 +33,15 @@ public virtual void Dispose()
_hook.Dispose();
}

protected void OnCallBack()
{
InvocationCount++;
if (Throws)
{
AssertHandler.RaiseVbaError(ErrorNumber, ErrorDescription);
}
}

protected void TrackUsage(string parameter, object value)
{
// TODO: Resolve TypeName.
Expand Down
1 change: 1 addition & 0 deletions RetailCoder.VBE/UnitTesting/Fakes/FakesProvider.cs
Expand Up @@ -48,6 +48,7 @@ private IFake RetrieveOrCreateFake(Type type)
#region Function Overrides

public IFake MsgBox => RetrieveOrCreateFake(typeof(MsgBox));
public IFake InputBox => RetrieveOrCreateFake(typeof(InputBox));

#endregion
}
Expand Down
4 changes: 4 additions & 0 deletions RetailCoder.VBE/UnitTesting/Fakes/IFake.cs
Expand Up @@ -12,9 +12,13 @@ namespace Rubberduck.UnitTesting
[EditorBrowsable(EditorBrowsableState.Always)]
public interface IFake
{
[DispId(1)]
void Returns(object Value);
[DispId(2)]
void AssignsByRef(string Parameter, object Value);
[DispId(3)]
void RaisesError(int Number = 0, string Description = "");
[DispId(4)]
IVerify Verify { get; }
}
}
3 changes: 3 additions & 0 deletions RetailCoder.VBE/UnitTesting/Fakes/IFakesProvider.cs
Expand Up @@ -8,6 +8,9 @@ namespace Rubberduck.UnitTesting
[EditorBrowsable(EditorBrowsableState.Always)]
public interface IFakesProvider
{
[DispId(1)]
IFake MsgBox { get; }
[DispId(2)]
IFake InputBox { get; }
}
}
12 changes: 12 additions & 0 deletions RetailCoder.VBE/UnitTesting/Fakes/IVerify.cs
Expand Up @@ -17,25 +17,29 @@ public interface IVerify
/// </summary>
/// <param name="Invocations">Expected minimum invocations.</param>
/// <param name="Message">An optional message to display if the verification fails.</param>
[DispId(1)]
void AtLeast(int Invocations, string Message = "");

/// <summary>
/// Verifies that the faked procedure was called one or more times.
/// </summary>
/// <param name="Message">An optional message to display if the verification fails.</param>
[DispId(2)]
void AtLeastOnce(string Message = "");

/// <summary>
/// Verifies that the faked procedure was called a maximum number of times.
/// </summary>
/// <param name="Invocations">Expected maximum invocations.</param>
/// <param name="Message">An optional message to display if the verification fails.</param>
[DispId(3)]
void AtMost(int Invocations, string Message = "");

/// <summary>
/// Verifies that the faked procedure was not called or was only called once.
/// </summary>
/// <param name="Message">An optional message to display if the verification fails.</param>
[DispId(4)]
void AtMostOnce(string Message = "");

/// <summary>
Expand All @@ -44,25 +48,29 @@ public interface IVerify
/// <param name="Minimum">Expected minimum invocations.</param>
/// <param name="Maximum">Expected maximum invocations.</param>
/// <param name="Message">An optional message to display if the verification fails.</param>
[DispId(5)]
void Between(int Minimum, int Maximum, string Message = "");

/// <summary>
/// Verifies that the faked procedure was called a specific number of times.
/// </summary>
/// <param name="Invocations">Expected invocations.</param>
/// <param name="Message">An optional message to display if the verification fails.</param>
[DispId(6)]
void Exactly(int Invocations, string Message = "");

/// <summary>
/// Verifies that the faked procedure is never called.
/// </summary>
/// <param name="Message">An optional message to display if the verification fails.</param>
[DispId(7)]
void Never(string Message = "");

/// <summary>
/// Verifies that the faked procedure is called exactly one time.
/// </summary>
/// <param name="Message">An optional message to display if the verification fails.</param>
[DispId(8)]
void Once(string Message = "");

/// <summary>
Expand All @@ -72,6 +80,7 @@ public interface IVerify
/// <param name="Value">The expected value of the parameter.</param>
/// <param name="Invocation">The invocation to test against. Optional - defaults to the first invocation.</param>
/// <param name="Message">An optional message to display if the verification fails.</param>
[DispId(9)]
void Parameter(string Parameter, object Value, int Invocation = 1, string Message = "");

/// <summary>
Expand All @@ -82,6 +91,7 @@ public interface IVerify
/// <param name="Maximum">Expected maximum value.</param>
/// <param name="Invocation">The invocation to test against. Optional - defaults to the first invocation.</param>
/// <param name="Message">An optional message to display if the verification fails.</param>
[DispId(10)]
void ParameterInRange(string Parameter, double Minimum, double Maximum, int Invocation = 1, string Message = "");

/// <summary>
Expand All @@ -90,6 +100,7 @@ public interface IVerify
/// <param name="Parameter">The name of the parameter to verify. Case insensitive.</param>
/// <param name="Invocation">The invocation to test against. Optional - defaults to the first invocation.</param>
/// <param name="Message">An optional message to display if the verification fails.</param>
[DispId(11)]
void ParameterIsPassed(string Parameter, int Invocation = 1, string Message = "");

/// <summary>
Expand All @@ -99,6 +110,7 @@ public interface IVerify
/// <param name="TypeName">The expected type as it would be returned by VBA.TypeName. Case insensitive.</param>
/// <param name="Invocation">The invocation to test against. Optional - defaults to the first invocation.</param>
/// <param name="Message">An optional message to display if the verification fails.</param>
[DispId(12)]
void ParameterIsType(string Parameter, string TypeName, int Invocation = 1, string Message = "");
}
}
35 changes: 35 additions & 0 deletions RetailCoder.VBE/UnitTesting/Fakes/InputBox.cs
@@ -0,0 +1,35 @@
using System;
using System.Runtime.InteropServices;
using Rubberduck.Parsing.ComReflection;

namespace Rubberduck.UnitTesting
{
internal class InputBox : FakeBase
{
private static readonly IntPtr ProcessAddress = EasyHook.LocalHook.GetProcAddress(TargetLibrary, "rtcInputBox");

public InputBox() : base (ProcessAddress)
{
InjectDelegate(new InputBoxDelegate(InputBoxCallback));
}

[UnmanagedFunctionPointer(CallingConvention.StdCall, SetLastError = true)]
[return: MarshalAs(UnmanagedType.BStr)]
private delegate string InputBoxDelegate(IntPtr prompt, IntPtr title, IntPtr Default, IntPtr xpos, IntPtr ypos, IntPtr helpfile, IntPtr context);

public string InputBoxCallback(IntPtr prompt, IntPtr title, IntPtr Default, IntPtr xpos, IntPtr ypos, IntPtr helpfile, IntPtr context)
{
OnCallBack();

TrackUsage("prompt", new ComVariant(prompt));
TrackUsage("title", new ComVariant(title));
TrackUsage("default", new ComVariant(Default));
TrackUsage("xpos", new ComVariant(xpos));
TrackUsage("ypos", new ComVariant(ypos));
TrackUsage("helpfile", new ComVariant(helpfile));
TrackUsage("context", new ComVariant(context));

return ReturnValue?.ToString() ?? string.Empty;
}
}
}
7 changes: 1 addition & 6 deletions RetailCoder.VBE/UnitTesting/Fakes/MsgBox.cs
Expand Up @@ -25,19 +25,14 @@ public override void Returns(object value)

public int MsgBoxCallback(IntPtr prompt, int buttons, IntPtr title, IntPtr helpfile, IntPtr context)
{
InvocationCount++;
OnCallBack();

TrackUsage("prompt", new ComVariant(prompt));
TrackUsage("buttons", buttons);
TrackUsage("title", new ComVariant(title));
TrackUsage("helpfile", new ComVariant(helpfile));
TrackUsage("context", new ComVariant(context));

if (Throws)
{
AssertHandler.RaiseVbaError(ErrorNumber, ErrorDescription);

}
return (int)_converter.Value;
}
}
Expand Down
31 changes: 30 additions & 1 deletion RetailCoder.VBE/UnitTesting/IAssert.cs
Expand Up @@ -15,44 +15,51 @@ public interface IAssert
/// </summary>
/// <param name="Condition">Any Boolean value or expression.</param>
/// <param name="Message">An optional message to display if the assertion fails.</param>
[DispId(1)]
void IsTrue(bool Condition, string Message = "");

/// <summary>
/// Verifies that the specified condition is <c>false</c>. The assertion fails if the condition is <c>true</c>.
/// </summary>
/// <param name="Condition">Any Boolean value or expression.</param>
/// <param name="Message">An optional message to display if the assertion fails.</param>
[DispId(2)]
void IsFalse(bool Condition, string Message = "");

/// <summary>
/// Indicates that the assertion cannot be verified.
/// </summary>
/// <param name="Message">An optional message to display.</param>
[DispId(3)]
void Inconclusive(string Message = "");

/// <summary>
/// Fails the assertion without checking any conditions.
/// </summary>
/// <param name="Message">An optional message to display.</param>
[DispId(4)]
void Fail(string Message = "");

/// <summary>
/// Passes the assertion without checking any conditions.
/// </summary>
[DispId(5)]
void Succeed();

/// <summary>
/// Verifies that the specified object is <c>Nothing</c>. The assertion fails if it is not <c>Nothing</c>.
/// </summary>
/// <param name="Value">The object to verify.</param>
/// <param name="Message">An optional message to display if the assertion fails.</param>
[DispId(6)]
void IsNothing(object Value, string Message = "");

/// <summary>
/// Verifies that the specified object is not <c>Nothing</c>. The assertion fails if it is <c>Nothing</c>.
/// </summary>
/// <param name="Value">The object to verify.</param>
/// <param name="Message">An optional message to display if the assertion fails.</param>
[DispId(7)]
void IsNotNothing(object Value, string Message = "");

/// <summary>
Expand All @@ -64,6 +71,7 @@ public interface IAssert
/// <remarks>
/// <paramref name="Expected"/> and <paramref name="Actual"/> must be the same type.
/// </remarks>
[DispId(8)]
void AreEqual(object Expected, object Actual, string Message = "");

/// <summary>
Expand All @@ -75,6 +83,7 @@ public interface IAssert
/// <remarks>
/// <paramref name="Expected"/> and <paramref name="Actual"/> must be the same type.
/// </remarks>
[DispId(9)]
void AreNotEqual(object Expected, object Actual, string Message = "");

/// <summary>
Expand All @@ -83,6 +92,7 @@ public interface IAssert
/// <param name="Expected">The expected reference.</param>
/// <param name="Actual">The actual reference.</param>
/// <param name="Message">An optional message to display if the assertion fails.</param>
[DispId(10)]
void AreSame(object Expected, object Actual, string Message = "");

/// <summary>
Expand All @@ -91,10 +101,29 @@ public interface IAssert
/// <param name="Expected">The expected reference.</param>
/// <param name="Actual">The actual reference.</param>
/// <param name="Message">An optional message to display if the assertion fails.</param>
[DispId(11)]
void AreNotSame(object Expected, object Actual, string Message = "");


/// <summary>
/// Verifies that all of the items in 2 arrays are equal. The assertion fails if any items is different, if either the lower
/// bounds or upper bounds are different, or if the ranks (number of dimensions) differ. This can be used for arrays of arbitrary
/// dimensions and arbitrary bounds.
/// </summary>
/// <param name="Expected">The expected sequence.</param>
/// <param name="Actual">The actual sequence.</param>
/// <param name="Message">An optional message to display if the assertion fails.</param>
[DispId(12)]
void SequenceEquals(object Expected, object Actual, string Message = "");

/// <summary>
/// Verifies that at least one of the items in 2 arrays differs at any give index. The assertion fails if all of the items are the same, if
/// the lower bounds and upper bounds are the same, and the ranks (number of dimensions) are the same. This can be used for arrays of arbitrary
/// dimensions and arbitrary bounds.
/// </summary>
/// <param name="Expected">The expected sequence.</param>
/// <param name="Actual">The actual sequence.</param>
/// <param name="Message">An optional message to display if the assertion fails.</param>
[DispId(13)]
void NotSequenceEquals(object Expected, object Actual, string Message = "");
}
}
17 changes: 0 additions & 17 deletions RetailCoder.VBE/UnitTesting/ITestRunner.cs

This file was deleted.

0 comments on commit e88704b

Please sign in to comment.