-
Notifications
You must be signed in to change notification settings - Fork 40
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Granular control of which field are included in VerifiableTree expectation #343
Comments
Although Consider the following proposed interface: public interface IExpectationBuilder<T>
{
IExpectationBuilder<T> EquivalentTo(T? value);
IExpectationBuilder<T> Excluding<TResult>(Expression<Func<T, TResult>> o);
IExpectationBuilder<T> Expecting<TResult>(Expression<Func<T, TResult>> o, Func<IExpectationComposer, IExpectation<TResult>> to);
} and a proposed companion static public static class Tree
{
//...
public static VerifiableTree Expect<T>(Action<IExpectationBuilder<T>> expect)
// ...
} This might be used in a scenario as follows: await Runner.RunScenario(
_ => _.Then_the_thing_should_look_like(Tree.Expect<MyType>(value => value
.EquivalentTo(new MyType { Z = "test" })
.Excluding(p => p.X)
.Expecting(p => p.Y, to => to.BeGreaterThan(7f))))); where public class MyType
{
public int X { get; set; }
public float Y { get; set; }
public string Z { get; set; }
} This has the benefit of being reasonably terse, type safe, and legible. What do you think @Suremaker ? |
Hi @goldsam , Currently the LightBDD does not offer property level mapping (include / exclude) as with the potentially complex structure of the object trees, it seems to quickly become difficult to maintain / write. Having said that, I do not mind exploring this further if there is a good use case for it, as the underlying logic should be relatively easy to add this. Before I go with this further, I wanted to ask if you check the Example test:
|
In my case, my types are generated protocol buffers. The types are generally about 3 levels deep and pretty wide with quite a few properties. I just needed to apply an exclusion or inequality comparison to only a handful of properties, but sometimes at multiple levels in the object tree. Currently, I am just using a bunch of expectation expression - I did not realize you could mix with other objects with expectations (makes sense though now that I reflect on it). This will come in handy, so thank you! I'm inspired by the code fragments in your last response. I was envisioning a system where you could override operations (e.g. "these two objects are equivalent EXCEPT for this property") . As you pointed out, a good general purpose solution is non-trivial (and might yield unexpected results). Despite these shortcomings, this approach would definitely keep the code base much smaller and I would argue easier to read (at least for my use case). Originally, I was thinking it would be necessary to construct a customized Also, I have to compliment you on this library - I think its simply amazing. It forces patterns which lead to much higher quality tests. I find in practice that tests are easier to maintain since intent is clearly communicated, while details are kept out-of-the-way unless you need to dive into them. The only gripe I get from my teammates is that the cost of writing tests is higher - I just retorted that the costs of writing useful tests is always higher - but the cost of low quality tests is a small fortune. Great project! Thank you. |
Hi @goldsam , Thank you for the kind words on the project - I am glad that you are finding it useful for you and your team! Feel free to experiment with the extension methods that I have presented above. You can also use NodeMapper as mentioned and create a specific mapper for your types. The mapper can be then registered on You can also take a look on how json objects are mapped with JsonElementObjectMapper. If you end up in building something of general purpose that you would be keen to share with the community, please feel free to let me know - I will be happy to incorporate it to LightBDD Framework. |
Description
Is there a mechanism to fine-tune expectations on
VerifiableTree
and friends? While theExcpectXXX
methods ofTree
are fine most of the time, it would be useful to have more control over which properties of an object are included in the expectation comparison.It looks like the tree is immutable, so I guess this would have to be accomplished using a builder. Would this have to be addressed through a new feature or am I missing something?
Progress
The text was updated successfully, but these errors were encountered: