Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions src/ThirdDrawer.UnitTests/StringExtensionTests/StringExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
using System;
using System.Text;
using NUnit.Framework;
using Shouldly;
using ThirdDrawer.Extensions.StringExtensionMethods;

namespace ThirdDrawer.UnitTests.StringExtensionTests
{
[TestFixture]
public class StringExtensions
{
[Test]
public void TheResultShouldBeCorrect()
{
var testcase1Result = "foo".EqualCaseInsensitive("foO");
testcase1Result.ShouldBe(true);

var testcase2Result = "Foo".EqualCaseInsensitive("foO");
testcase2Result.ShouldBe(true);

var testcase3Result = "Fo0".EqualCaseInsensitive("foO");
testcase3Result.ShouldBe(false);

}

[Test]
public void EqualCaseInsensitiveShouldReturnTrueWhenPassingEmptryString()
{
var testcase1Result = string.Empty.EqualCaseInsensitive("");
testcase1Result.ShouldBe(true);
}

[Test]
public void HasValShouldReturnFalseWhenPassingEmptryString()
{
var testcase1Result = string.Empty.HasVal();
testcase1Result.ShouldBe(false);
}

[Test]
public void HasValShouldReturnFalseWhenPassingNull()
{
string param = null;
var testcase1Result = param.HasVal();
testcase1Result.ShouldBe(false);
}

[Test]
public void NoValShouldReturnTrueWhenPassingEmptryString()
{
var testcase1Result = string.Empty.NoVal();
testcase1Result.ShouldBe(true);
}

[Test]
public void NoValShouldReturnTrueWhenPassingNull()
{
string param = null;
var testcase1Result = param.NoVal();
testcase1Result.ShouldBe(true);
}

}
}
1 change: 1 addition & 0 deletions src/ThirdDrawer.UnitTests/ThirdDrawer.UnitTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
<Compile Include="Base64Tests\WhenEncodingFoo.cs" />
<Compile Include="Base64Tests\WhenEncodingThenDecodingAString.cs" />
<Compile Include="CollectionExtensionTests\WhenPartitioningACollectionOfNumbersByParity.cs" />
<Compile Include="StringExtensionTests\StringExtensions.cs" />
<Compile Include="TypeExtensionTests\WhenLookingForClosedTypesOfAnOpenGeneric.cs" />
<Compile Include="WhenTheTestHarnessRuns.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public static string FormatWith(this string s, params object[] args)
{
return string.Format(CultureInfo.CurrentUICulture, s, args);
}

public static string GenerateRandomString(int length)
{
var characters = new List<char>();
Expand Down Expand Up @@ -81,5 +81,20 @@ public static string RemoveCharacters(this string s, string toRemove)

return working;
}

public static bool NoVal(this string src)
{
return string.IsNullOrWhiteSpace(src);
}

public static bool HasVal(this string src)
{
return !src.NoVal();
}

public static bool EqualCaseInsensitive(this string src, string compareWith)
{
return (string.Equals(src, compareWith, StringComparison.OrdinalIgnoreCase));
}
}
}