Skip to main content

Version

Describes the possible expectations for Version.

ExpectationNegatedSummary
IsEqualToIsNotEqualToequal to the expected version
IsOneOfIsNotOneOfequal to one of the expected versions
IsGreaterThanIsNotGreaterThangreater than the expected version
IsGreaterThanOrEqualToIsNotGreaterThanOrEqualTogreater than or equal to the expected version
IsLessThanIsNotLessThanless than the expected version
IsLessThanOrEqualToIsNotLessThanOrEqualToless than or equal to the expected version
IsBetweenIsNotBetweenbetween two versions, both bounds included
HasMajornegated comparisonhas the expected major component
HasMinornegated comparisonhas the expected minor component
HasBuildnegated comparisonhas the expected build component
HasRevisionnegated comparisonhas the expected revision component

Equality​

You can verify that the Version is equal to another one or not:

Version release = new(1, 2);

await That(release).IsEqualTo(new Version(1, 2));
await That(release).IsNotEqualTo(new Version(1, 2, 0));

An unspecified component is -1, not 0, so 1.2 is not equal to 1.2.0 and, following Version.CompareTo, less than it.

One of​

You can verify that the Version is one of many alternatives:

Version release = new(1, 2);

await That(release).IsOneOf(new Version(1, 2), new Version(1, 3));
await That(release).IsNotOneOf(new Version(2, 0), new Version(3, 0));

Greater than / less than​

You can verify that the Version is greater than or less than (or equal to) another one, or that it is not:

Version release = new(1, 5);

await That(release).IsGreaterThan(new Version(1, 2));
await That(release).IsGreaterThanOrEqualTo(new Version(1, 5));
await That(release).IsLessThan(new Version(2, 0));
await That(release).IsLessThanOrEqualTo(new Version(1, 5));
await That(release).IsNotGreaterThan(new Version(2, 0));
await That(release).IsNotLessThan(new Version(1, 2));

Between​

You can verify that the Version is between two values, with both bounds included:

Version release = new(1, 5);

await That(release).IsBetween(new Version(1, 2)).And(new Version(2, 0));
await That(release).IsNotBetween(new Version(2, 0)).And(new Version(3, 0));

Components​

You can verify the individual components of the Version:

Version release = new(1, 2, 3, 4);

await That(release).HasMajor(1);
await That(release).HasMinor().GreaterThan(1);
await That(release).HasBuild().LessThanOrEqualTo(3);
await That(release).HasRevision().NotEqualTo(5);

An unspecified build or revision is -1, not 0:

Version release = new(1, 2);

await That(release).HasBuild(-1);
await That(release).HasRevision(-1);

The Has… expectations whose value is a number or a TimeSpan, e.g. HasLength(), HasCount(), HasYear() or HasMajor(), continue with one of the following comparisons, each with a negated counterpart:

ComparisonNegatedSucceeds when the value is
EqualTo(x)NotEqualTo(x)equal to x
GreaterThan(x)NotGreaterThan(x)greater than x
GreaterThanOrEqualTo(x)NotGreaterThanOrEqualTo(x)greater than or equal to x
LessThan(x)NotLessThan(x)less than x
LessThanOrEqualTo(x)NotLessThanOrEqualTo(x)less than or equal to x
Between(min).And(max)NotBetween(min).And(max)between min and max, both bounds included

Passing the value directly, e.g. HasMajor(1), is a shorthand for EqualTo.

Comparing with null

The expected value is nullable, e.g. to pass a value mapped from a property. As the actual value is never null, EqualTo(null) fails and NotEqualTo(null) succeeds, while a comparison of order against null, such as GreaterThan(null) or Between(null).And(3), fails even when negated.