Problem Statement
I'm doing assertions on wrapper Value Objects, i.e. single-valued Value Objects wrapping a primitive. For example, we might have a ProductCode wrapping string. These have an implicit conversion to the primitive, and an explicit conversion to the wrapper.
Before 1.39.0, the following worked for string wrappers:
await Assert.That(updatedStockItem.ProductCode).IsEqualTo("Example");
As of 1.39.0, the string overload is gone, and a ProductCode is required. Since the conversion in that direction is (rightfully) explicit, we have to make it manually, or resolve ProductCode.Value.
I considered filing a bug, but realized that the wrapper scenario only worked with string wrappers. An int wrapper, for example, already did not benefit. As such, a feature request seems more suitable.
Proposed Solution
await Assert.That(updatedStockItem.ProductCode).IsEqualTo("Example"); // T = ProductCode
await Assert.That(updatedStockItem.SomeWrappedNumber).IsEqualTo(1); // T = MyIntWrapper
Could such equality checks (and perhaps also other comparisons) be made flexible enough to work, for wrappers?
For example, if the T in Assert.That(T) has an implicit conversion operator to some type X, it would be fantastic if IsEqualTo and other comparison overloads were made available accepting an X. In that case, the left hand would be converted to X and the result compared to the right hand's X.
Alternatives Considered
await Assert.That(updatedStockItem.ProductCode.Value).IsEqualTo("Example");
await Assert.That(updatedStockItem.ProductCode).IsEqualTo((ProductCode)"Example");
Since we type these very often, the simplification has merit.
Feature Category
Assertions
How important is this feature to you?
Nice to have - would improve my experience
Additional Context
No response
Contribution
Problem Statement
I'm doing assertions on wrapper Value Objects, i.e. single-valued Value Objects wrapping a primitive. For example, we might have a
ProductCodewrappingstring. These have an implicit conversion to the primitive, and an explicit conversion to the wrapper.Before 1.39.0, the following worked for string wrappers:
As of 1.39.0, the
stringoverload is gone, and aProductCodeis required. Since the conversion in that direction is (rightfully) explicit, we have to make it manually, or resolveProductCode.Value.I considered filing a bug, but realized that the wrapper scenario only worked with
stringwrappers. Anintwrapper, for example, already did not benefit. As such, a feature request seems more suitable.Proposed Solution
Could such equality checks (and perhaps also other comparisons) be made flexible enough to work, for wrappers?
For example, if the
TinAssert.That(T)has an implicit conversion operator to some typeX, it would be fantastic ifIsEqualToand other comparison overloads were made available accepting anX. In that case, the left hand would be converted toXand the result compared to the right hand'sX.Alternatives Considered
Since we type these very often, the simplification has merit.
Feature Category
Assertions
How important is this feature to you?
Nice to have - would improve my experience
Additional Context
No response
Contribution