Last active
September 21, 2015 19:24
-
-
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.
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
/// <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<NegativeLong>(); | |
/// </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