Skip to content

Commit

Permalink
Merge pull request #426 from skrysmanski/more-resharper-annotations
Browse files Browse the repository at this point in the history
Added more ReSharper contract annotations
  • Loading branch information
josephwoodward committed Aug 3, 2017
2 parents e0c2158 + d5d366b commit 0eae7a4
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,17 @@ namespace Shouldly
[ShouldlyMethods]
public static partial class ShouldBeTestExtensions
{
[ContractAnnotation("actual:null,expected:notnull => halt;actual:notnull,expected:null => halt")]
public static void ShouldBe<T>(this T actual, T expected)
{
ShouldBe(actual, expected, () => null);
}
[ContractAnnotation("actual:null,expected:notnull => halt;actual:notnull,expected:null => halt")]
public static void ShouldBe<T>(this T actual, T expected, string customMessage)
{
ShouldBe(actual, expected, () => customMessage);
}
[ContractAnnotation("actual:null,expected:notnull => halt;actual:notnull,expected:null => halt")]
public static void ShouldBe<T>(this T actual, T expected, [InstantHandle] Func<string> customMessage)
{
if (ShouldlyConfiguration.CompareAsObjectTypes.Contains(typeof(T).FullName) || typeof(T) == typeof(string))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,36 +5,42 @@ namespace Shouldly
{
public static partial class ShouldBeStringTestExtensions
{
[ContractAnnotation("actual:notnull => halt")]
public static void ShouldBeNullOrEmpty(this string actual)
{
ShouldBeNullOrEmpty(actual, () => null);
}

[ContractAnnotation("actual:notnull => halt")]
public static void ShouldBeNullOrEmpty(this string actual, string customMessage)
{
ShouldBeNullOrEmpty(actual, () => customMessage);
}

[ContractAnnotation("actual:notnull => halt")]
public static void ShouldBeNullOrEmpty(this string actual, [InstantHandle] Func<string> customMessage)
{
if (!string.IsNullOrEmpty(actual))
throw new ShouldAssertException(new ActualShouldlyMessage(actual, customMessage).ToString());
}

[ContractAnnotation("actual:null => halt")]
public static void ShouldNotBeNullOrEmpty(this string actual)
{
ShouldNotBeNullOrEmpty(actual, () => null);
}

[ContractAnnotation("actual:null => halt")]
public static void ShouldNotBeNullOrEmpty(this string actual, string customMessage)
{
ShouldNotBeNullOrEmpty(actual, () => customMessage);
}

[ContractAnnotation("actual:null => halt")]
public static void ShouldNotBeNullOrEmpty(this string actual, [InstantHandle] Func<string> customMessage)
{
if (string.IsNullOrEmpty(actual))
throw new ShouldAssertException(new ActualShouldlyMessage(actual, customMessage).ToString());
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,38 @@ namespace Shouldly
{
public static partial class ShouldBeStringTestExtensions
{
[ContractAnnotation("actual:notnull => halt")]
public static void ShouldBeNullOrWhiteSpace(this string actual)
{
ShouldBeNullOrWhiteSpace(actual, () => null);
}

[ContractAnnotation("actual:notnull => halt")]
public static void ShouldBeNullOrWhiteSpace(this string actual, string customMessage)
{
ShouldBeNullOrWhiteSpace(actual, () => customMessage);
}

[ContractAnnotation("actual:notnull => halt")]
public static void ShouldBeNullOrWhiteSpace(this string actual, [InstantHandle] Func<string> customMessage)
{
if (!actual.IsNullOrWhiteSpace())
throw new ShouldAssertException(new ActualShouldlyMessage(actual, customMessage).ToString());
}

[ContractAnnotation("actual:null => halt")]
public static void ShouldNotBeNullOrWhiteSpace(this string actual)
{
ShouldNotBeNullOrWhiteSpace(actual, () => null);
}

[ContractAnnotation("actual:null => halt")]
public static void ShouldNotBeNullOrWhiteSpace(this string actual, string customMessage)
{
ShouldNotBeNullOrWhiteSpace(actual, () => customMessage);
}

[ContractAnnotation("actual:null => halt")]
public static void ShouldNotBeNullOrWhiteSpace(this string actual, [InstantHandle] Func<string> customMessage)
{
// TODO make this an extension method (str.IsNullOrWhitespace())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,19 @@ namespace Shouldly
[ShouldlyMethods]
public static class ShouldBeNullExtensions
{
[ContractAnnotation("actual:notnull => halt")]
public static void ShouldBeNull<T>(this T actual)
{
ShouldBeNull(actual, () => null);
}

[ContractAnnotation("actual:notnull => halt")]
public static void ShouldBeNull<T>(this T actual, string customMessage)
{
ShouldBeNull(actual, () => customMessage);
}

[ContractAnnotation("actual:notnull => halt")]
public static void ShouldBeNull<T>(this T actual, [InstantHandle]Func<string> customMessage)
{
if (actual != null)
Expand Down

0 comments on commit 0eae7a4

Please sign in to comment.