Skip to content

Instantly share code, notes, and snippets.

@kmorcinek
Last active September 21, 2015 19:24
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 kmorcinek/6e33cfb91490a813b808 to your computer and use it in GitHub Desktop.
Save kmorcinek/6e33cfb91490a813b808 to your computer and use it in GitHub Desktop.
Used for integration database tests, when we want to avoid Id clashes with current DB entities. It sets long value, but every time we retrieve it we get negative value.
/// <summary>
/// Class should be used only by AutoFixture. Used for integration database tests, when we want to avoid Id clashes with current DB entities.
/// It sets long value, but every time we retrieve it we get negative value.
/// <remarks>
/// Class should be used only by <see cref="Fixture"/>, either directly by Create() method or by <see cref="AutoDataAttribute"/>.
/// </remarks>
/// </summary>
/// <example>
/// This sample shows how to use the <see cref="NegativeLongId"/> class
/// <code>
/// long accountId = new Fixture().Create&lt;NegativeLong&gt;();
/// </code>
/// </example>
public class NegativeLong
{
private readonly long _value;
public NegativeLong(long value)
{
_value = Negate(value);
}
private static long Negate(long value)
{
return -value;
}
public static implicit operator long(NegativeLong negativeLong)
{
return negativeLong._value;
}
// TODO: Another approach can be class NegativeId with backing field of type long, and implicit operators to int, short, etc.
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment