Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save reidev275/6798353 to your computer and use it in GitHub Desktop.
Save reidev275/6798353 to your computer and use it in GitHub Desktop.
test helper method
using NUnit.Framework;
[TestFixture]
public class Given_we_are_creating_an_object_with_a_single_string_parameter
{
[Test]
public void We_sould_test_for_null_or_whitespace_parameters()
{
TestHelpers.NullOrWhitespaceTest((s) => new ObjectWithStringParameter(s));
}
}
using NUnit.Framework;
[TestFixture]
public class Given_we_are_creating_an_object_with_multiple_parameters
{
[Test]
public void We_sould_test_for_null_or_whitespace_parameters()
{
TestHelpers.NullOrWhitespaceTest((s) => new ObjectWithMultipleParameters(new MyMockObject(), s));
}
}
using NUnit.Framework;
using System;
public class TestHelpers
{
public static void NullOrWhitespaceTest(Action<string> action)
{
Assert.Throws<ArgumentException>(() => action(""));
Assert.Throws<ArgumentNullException>(() => action(null));
Assert.Throws<ArgumentException>(() => action(" "));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment