No description, website, or topics provided.
C# Smalltalk
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
ValueTypeAssertions.Tests
ValueTypeAssertions
.gitattributes
.gitignore
InspectCodeBaseline.xml
LICENSE.md
README.md
TODO.md
ValueTypeAssertions.sln
ValueTypeAssertions.sln.DotSettings
ValueTypeAssertions.v2.ncrunchsolution
VisualStudioCSharpOptions.vssettings
appveyor-official.yml
appveyor.yml

README.md

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.