Version
Describes the possible expectations for Version.
| Expectation | Negated | Summary |
|---|---|---|
IsEqualTo | IsNotEqualTo | equal to the expected version |
IsOneOf | IsNotOneOf | equal to one of the expected versions |
IsGreaterThan | IsNotGreaterThan | greater than the expected version |
IsGreaterThanOrEqualTo | IsNotGreaterThanOrEqualTo | greater than or equal to the expected version |
IsLessThan | IsNotLessThan | less than the expected version |
IsLessThanOrEqualTo | IsNotLessThanOrEqualTo | less than or equal to the expected version |
IsBetween | IsNotBetween | between two versions, both bounds included |
HasMajor | negated comparison | has the expected major component |
HasMinor | negated comparison | has the expected minor component |
HasBuild | negated comparison | has the expected build component |
HasRevision | negated comparison | has the expected revision component |
A null subject fails every expectation on this page except equality and one of, as the
rule for null subjects says. Reference equality and null checks come
from the object expectations.
Equality
You can verify that the Version is equal to another one or not:
Version release = new(1, 2);
await Expect.That(release).IsEqualTo(new Version(1, 2));
await Expect.That(release).IsNotEqualTo(new Version(1, 2, 0));
This uses the equality of Version, where an unspecified component is not treated as zero, so 1.2 is not equal
to 1.2.0.
One of
You can verify that the Version is one of many alternatives:
Version release = new(1, 2);
await Expect.That(release).IsOneOf(new Version(1, 2), new Version(1, 3));
await Expect.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 Expect.That(release).IsGreaterThan(new Version(1, 2));
await Expect.That(release).IsGreaterThanOrEqualTo(new Version(1, 5));
await Expect.That(release).IsLessThan(new Version(2, 0));
await Expect.That(release).IsLessThanOrEqualTo(new Version(1, 5));
await Expect.That(release).IsNotGreaterThan(new Version(2, 0));
await Expect.That(release).IsNotLessThan(new Version(1, 2));
All comparisons follow
Version.CompareTo, which treats an
unspecified component as less than an explicit zero, so 1.2 is less than 1.2.0.
Between
You can verify that the Version is between two values, with both bounds included:
Version release = new(1, 5);
await Expect.That(release).IsBetween(new Version(1, 2)).And(new Version(2, 0));
await Expect.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 Expect.That(release).HasMajor(1);
await Expect.That(release).HasMinor().GreaterThan(1);
await Expect.That(release).HasBuild().LessThanOrEqualTo(3);
await Expect.That(release).HasRevision().NotEqualTo(5);
An unspecified build or revision is -1, not 0:
Version release = new(1, 2);
await Expect.That(release).HasBuild(-1);
await Expect.That(release).HasRevision(-1);
The Has… expectations for a number or a TimeSpan, e.g. HasLength(), HasCount(), HasYear() or HasMajor(),
continue with one of the following comparisons, each with a negated counterpart:
| Comparison | Negated | Succeeds 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. HasLength(10), is a shorthand for EqualTo.
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.