Skip to content

JayBazuzi/ValueTypeAssertions

Repository files navigation

Build status

Available on NuGet

ValueTypeAssertions

By "value type", I mean "a type that represents a value in some domain." Two of these objects are equal if they have the same value.

To correctly implement this in .Net is tricky. There's object.Equals() and operator == and GetHashCode() and more. These are assertions that ensure that you have checked all the checkboxes in implementing equality.

You can use it like this:

class NtfsPath
{
  // implementation here
}

[Test]
public void NtfsPathHasValueEquality()
{
  ValueTypeAssertions.HasValueEquality(new NtfsPath("foo.txt"), new NtfsPath("foo.txt"));
  ValueTypeAssertions.HasValueInequality(new NtfsPath("foo.txt"), new NtfsPath("bar.txt"));
}

[Test]
public void NtfsPathIsCaseInsensitive()
{
  ValueTypeAssertions.HasValueEquality(new NtfsPath("foo.txt"), new NtfsPath("FOO.TXT"));
}

Acknowledgements

99% of the ideas in this project came from other people. A big chunk came from Brian Geihsler.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published