-
-
Notifications
You must be signed in to change notification settings - Fork 540
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
718 additions
and
211 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
using System; | ||
using System.Diagnostics; | ||
using System.Diagnostics.Contracts; | ||
using FluentAssertions.Primitives; | ||
|
||
namespace FluentAssertions | ||
{ | ||
/// <summary> | ||
/// Contains an extension method for custom assertions in unit tests related to Enum objects. | ||
/// </summary> | ||
[DebuggerNonUserCode] | ||
public static class EnumAssertionsExtensions | ||
{ | ||
/// <summary> | ||
/// Returns an <see cref="EnumAssertions{TEnum, TAssertions}"/> object that can be used to assert the | ||
/// current <typeparamref name="TEnum"/>. | ||
/// </summary> | ||
[Pure] | ||
public static EnumAssertions<TEnum> Should<TEnum>(this TEnum @enum) | ||
where TEnum : struct, Enum | ||
{ | ||
return new EnumAssertions<TEnum>(@enum); | ||
} | ||
|
||
/// <summary> | ||
/// Returns an <see cref="EnumAssertions{TEnum, TAssertions}"/> object that can be used to assert the | ||
/// current <typeparamref name="TEnum"/>. | ||
/// </summary> | ||
[Pure] | ||
public static NullableEnumAssertions<TEnum> Should<TEnum>(this TEnum? @enum) | ||
where TEnum : struct, Enum | ||
{ | ||
return new NullableEnumAssertions<TEnum>(@enum); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
102 changes: 102 additions & 0 deletions
102
Src/FluentAssertions/Primitives/NullableEnumAssertions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
using System; | ||
using FluentAssertions.Execution; | ||
|
||
namespace FluentAssertions.Primitives | ||
{ | ||
/// <summary> | ||
/// Contains a number of methods to assert that a nullable <typeparamref name="TEnum"/> is in the expected state. | ||
/// </summary> | ||
public class NullableEnumAssertions<TEnum> : NullableEnumAssertions<TEnum, NullableEnumAssertions<TEnum>> | ||
where TEnum : struct, Enum | ||
{ | ||
public NullableEnumAssertions(TEnum? subject) | ||
: base(subject) | ||
{ | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Contains a number of methods to assert that a nullable <typeparamref name="TEnum"/> is in the expected state. | ||
/// </summary> | ||
public class NullableEnumAssertions<TEnum, TAssertions> : EnumAssertions<TEnum, TAssertions> | ||
where TEnum : struct, Enum | ||
where TAssertions : NullableEnumAssertions<TEnum, TAssertions> | ||
{ | ||
public NullableEnumAssertions(TEnum? subject) | ||
: base(subject) | ||
{ | ||
} | ||
|
||
public new TEnum? Subject => SubjectInternal; | ||
|
||
/// <summary> | ||
/// Asserts that a nullable <typeparamref name="TEnum"/> value is not <c>null</c>. | ||
/// </summary> | ||
/// <param name="because"> | ||
/// A formatted phrase as is supported by <see cref="string.Format(string,object[])"/> explaining why the assertion | ||
/// is needed. If the phrase does not start with the word <i>because</i>, it is prepended automatically. | ||
/// </param> | ||
/// <param name="becauseArgs"> | ||
/// Zero or more objects to format using the placeholders in <paramref name="because" />. | ||
/// </param> | ||
public AndWhichConstraint<TAssertions, TEnum> HaveValue(string because = "", params object[] becauseArgs) | ||
{ | ||
Execute.Assertion | ||
.ForCondition(SubjectInternal.HasValue) | ||
.BecauseOf(because, becauseArgs) | ||
.FailWith("Expected {context:nullable date and time} to have a value{reason}, but found {0}.", SubjectInternal); | ||
|
||
return new AndWhichConstraint<TAssertions, TEnum>((TAssertions)this, SubjectInternal.GetValueOrDefault()); | ||
} | ||
|
||
/// <summary> | ||
/// Asserts that a nullable <typeparamref name="TEnum"/> is not <c>null</c>. | ||
/// </summary> | ||
/// <param name="because"> | ||
/// A formatted phrase as is supported by <see cref="string.Format(string,object[])"/> explaining why the assertion | ||
/// is needed. If the phrase does not start with the word <i>because</i>, it is prepended automatically. | ||
/// </param> | ||
/// <param name="becauseArgs"> | ||
/// Zero or more objects to format using the placeholders in <paramref name="because" />. | ||
/// </param> | ||
public AndWhichConstraint<TAssertions, TEnum> NotBeNull(string because = "", params object[] becauseArgs) | ||
{ | ||
return HaveValue(because, becauseArgs); | ||
} | ||
|
||
/// <summary> | ||
/// Asserts that a nullable <typeparamref name="TEnum"/> value is <c>null</c>. | ||
/// </summary> | ||
/// <param name="because"> | ||
/// A formatted phrase as is supported by <see cref="string.Format(string,object[])"/> explaining why the assertion | ||
/// is needed. If the phrase does not start with the word <i>because</i>, it is prepended automatically. | ||
/// </param> | ||
/// <param name="becauseArgs"> | ||
/// Zero or more objects to format using the placeholders in <paramref name="because" />. | ||
/// </param> | ||
public AndConstraint<TAssertions> NotHaveValue(string because = "", params object[] becauseArgs) | ||
{ | ||
Execute.Assertion | ||
.ForCondition(!SubjectInternal.HasValue) | ||
.BecauseOf(because, becauseArgs) | ||
.FailWith("Did not expect {context:nullable date and time} to have a value{reason}, but found {0}.", SubjectInternal); | ||
|
||
return new AndConstraint<TAssertions>((TAssertions)this); | ||
} | ||
|
||
/// <summary> | ||
/// Asserts that a nullable <typeparamref name="TEnum"/> value is <c>null</c>. | ||
/// </summary> | ||
/// <param name="because"> | ||
/// A formatted phrase as is supported by <see cref="string.Format(string,object[])"/> explaining why the assertion | ||
/// is needed. If the phrase does not start with the word <i>because</i>, it is prepended automatically. | ||
/// </param> | ||
/// <param name="becauseArgs"> | ||
/// Zero or more objects to format using the placeholders in <paramref name="because" />. | ||
/// </param> | ||
public AndConstraint<TAssertions> BeNull(string because = "", params object[] becauseArgs) | ||
{ | ||
return NotHaveValue(because, becauseArgs); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.