Skip to content

Commit

Permalink
Implemented string-contains-not assertion mrpinkzh#12
Browse files Browse the repository at this point in the history
  • Loading branch information
mrpinkzh committed Mar 18, 2016
1 parent 705553a commit 1332048
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using ExAs.Results;
using ExAs.Utils;

namespace ExAs.Assertions.MemberAssertions.Strings
{
public class ContainsNotAssertion : IAssertValue<string>
{
private readonly string expected;

public ContainsNotAssertion(string expected)
{
this.expected = expected;
}

public ValueAssertionResult AssertValue(string actual)
{
return new ValueAssertionResult(
!actual.Contains_NullAware(expected),
actual.ToValueString(),
ComposeLog.Expected($"doesn't contain {expected.ToValueString()}"));
}
}
}
1 change: 1 addition & 0 deletions src/ExAs/ExAs.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
<Compile Include="Assertions\MemberAssertions\NullableAssertionAdapter.cs" />
<Compile Include="Assertions\MemberAssertions\OfTypeAssertion.cs" />
<Compile Include="Assertions\MemberAssertions\Strings\ContainsAssertion.cs" />
<Compile Include="Assertions\MemberAssertions\Strings\ContainsNotAssertion.cs" />
<Compile Include="Assertions\MemberAssertions\Strings\EndsNotWithAssertion.cs" />
<Compile Include="Assertions\MemberAssertions\Strings\StartsNotWithAssertion.cs" />
<Compile Include="Assertions\MemberAssertions\Strings\EndsWithAssertion.cs" />
Expand Down
5 changes: 5 additions & 0 deletions src/ExAs/StringAssertions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ public static IAssert<T> DoesntEndWith<T>(this IAssertMember<T, string> member,
public static IAssert<T> Contains<T>(this IAssertMember<T, string> member, string expected)
{
return member.SetAssertion(new ContainsAssertion(expected));
}

public static IAssert<T> DoesntContain<T>(this IAssertMember<T, string> member, string expected)
{
return member.SetAssertion(new ContainsNotAssertion(expected));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using ExAs.Utils;
using NUnit.Framework;
using static ExAs.Utils.Creation.CreateNinjas;

namespace ExAs.Api.Strings
{
public class StringAssertion_DoesntContain_Feature
{
[Test]
public void ExpectingNotAkashi_OnNaruto_ShouldPass()
{
// act
var result = Naruto().Evaluate(n => n.Member(x => x.Name).DoesntContain("akashi"));

// assert
result.ExAssert(r => r.Member(x => x.succeeded).IsTrue()
.Member(x => x.log) .IsEqualTo("Ninja: ( )Name = 'Naruto'")
.Member(x => x.expectation).IsEqualTo(ComposeLog.Expected("doesn't contain 'akashi'")));
}

[Test]
public void ExpectingNotKash_OnKakashi_ShouldFail()
{
// act
var result = Kakashi().Evaluate(n => n.Member(x => x.Name).DoesntContain("kash"));

// assert
result.ExAssert(r => r.Member(x => x.succeeded).IsFalse()
.Member(x => x.log) .IsEqualTo("Ninja: (X)Name = 'Kakashi'")
.Member(x => x.expectation).IsEqualTo(ComposeLog.Expected("doesn't contain 'kash'")));
}

[Test]
public void ExpectingNull_OnNaruto_ShouldSucceed()
{
// act
var result = Naruto().Evaluate(n => n.Member(x => x.Name).DoesntContain(null));

// assert
result.ExAssert(r => r.Member(x => x.succeeded).IsTrue()
.Member(x => x.expectation).IsEqualTo(ComposeLog.Expected("doesn't contain null")));
}
}
}
1 change: 1 addition & 0 deletions tests/ExAs.Tests/ExAs.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
<Compile Include="Api\ShortAssertionFeature.cs" />
<Compile Include="Api\SimpleAssertionFeature.cs" />
<Compile Include="Api\Strings\StringAssertion_Contains_Feature.cs" />
<Compile Include="Api\Strings\StringAssertion_DoesntContain_Feature.cs" />
<Compile Include="Api\Strings\StringAssertion_DoesntEndWith_Feature.cs" />
<Compile Include="Api\Strings\StringAssertion_EndsWith_Feature.cs" />
<Compile Include="Api\Strings\StringAssertion_HasLength_Feature.cs" />
Expand Down

0 comments on commit 1332048

Please sign in to comment.