Skip to content

Commit

Permalink
Delegates Kihon initial
Browse files Browse the repository at this point in the history
  • Loading branch information
trayburn committed Mar 16, 2013
1 parent 89ea09d commit baec73b
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 1 deletion.
103 changes: 103 additions & 0 deletions src/Squire/DelegatesKihonBase.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
using System;
using NUnit.Framework;
using Squire.Framework;
using System.Collections.Generic;
using Rhino.Mocks;
using System.Linq.Expressions;

namespace Squire
{
[TestFixture]
public class DelegatesKihon : DelegatesKihonBase
{
public override Action Return_An_Action_That_Calls_Hit_On_a(ITarget a)
{
return () => a.Hit();
}

public override Action<ITarget> Return_An_Action_That_Calls_Hit_On_Its_Parameter()
{
return a => a.Hit();
}

public override Expression<Func<bool>> Return_An_Expression_That_Is_a_or_b(bool a, bool b)
{
return () => a || b;
}
}

[TestFixture]
public abstract class DelegatesKihonBase
{
[Test]
public void _Return_An_Action_That_Calls_Hit_On_Its_Parameter()
{
// Arrange
var a = MockRepository.GenerateMock<ITarget>();

// Act
var result = Return_An_Action_That_Calls_Hit_On_Its_Parameter();
result.Invoke(a);

// Assert
a.AssertWasCalled(e => e.Hit(), mo => mo.Repeat.Once());
}

[Test]
public void Return_An_Action_That_Calls_Hit_On_a()
{
// Arrange
var a = MockRepository.GenerateMock<ITarget>();

// Act
var result = Return_An_Action_That_Calls_Hit_On_a(a);
result.Invoke();

// Assert
a.AssertWasCalled(m => m.Hit(), mo => mo.Repeat.Once());
}

[Test]
public void Return_An_Expression_That_Is_a_or_b()
{
// Arrange
var aValues = new[] { true, false };
var bValues = new[] { false, true };

// Act
foreach (bool aValue in aValues)
{
foreach (bool bValue in bValues)
{
var result = Return_An_Expression_That_Is_a_or_b(aValue, bValue);
var body = result.Body;

if (typeof(BinaryExpression).IsInstanceOfType(body) == false)
Assert.Fail("Not a binary expression");
else
{
var binaryExp = result.Body as BinaryExpression;
var left = binaryExp.Left;
if (typeof(MemberExpression).IsInstanceOfType(left) == false)
Assert.Fail("Left is not a parameter expression : " + left.GetType().BaseType.Name);
else
{
var right = binaryExp.Right;
if (typeof(MemberExpression).IsInstanceOfType(right) == false)
Assert.Fail("Right is not a parameter expression : " + right.GetType().BaseType.Name);
}
}

var boolResult = result.Compile().Invoke();
Assert.AreEqual(boolResult, aValue || bValue);
}
}
// Assert

}

public abstract Action Return_An_Action_That_Calls_Hit_On_a(ITarget a);
public abstract Action<ITarget> Return_An_Action_That_Calls_Hit_On_Its_Parameter();
public abstract Expression<Func<bool>> Return_An_Expression_That_Is_a_or_b(bool a, bool b);
}
}
1 change: 1 addition & 0 deletions src/Squire/Squire.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@
<ItemGroup>
<Compile Include="ConsoleKihon.cs" />
<Compile Include="ControlStructureKihon.cs" />
<Compile Include="DelegatesKihonBase.cs" />
<Compile Include="Framework\Abstractions\IConsoleWrapper.cs" />
<Compile Include="Framework\BaseDataKihon.cs" />
<Compile Include="Framework\BaseKihon.cs" />
Expand Down
2 changes: 1 addition & 1 deletion src/Squire/StringKihon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class StringKihon : StringKihonBase
{
protected override string Convert_To_Uppercase(string data)
{
throw new NotImplementedException();
return data.ToUpper();
}

protected override string Convert_To_Lowercase(string data)
Expand Down

0 comments on commit baec73b

Please sign in to comment.