Description
I'm building a user like var antUser = new UserBuilder().WithUniqueName("ant");
and its failing a test. When I add the explicit build eg var antUser = new UserBuilder().WithUniqueName("ant").Build();
the test passes.
What I think is happening is a combination of two things:
- The automagic value assignment of my
Id
field, and - The implicit operator which is calling
BuildObject()
internally
The failure is due to the same antUser
being used twice in the test setup and I'm expecting the identity of said User to be the same with both usages of the instance, only it's not! The Id
is different every time the implicit cast happens.
This is a pretty big deal and I think most devs would expect the identity/equality to behave the same way I am.
The implicit operator is misleading in that it allows the dev to think they don't really need to call .Build()
explicitly (yay! saved banging a few keys) and so they don't. It's not obvious that the fix is to call .Build()
. And then when you figure it out it seems smelly that you need to be aware of this peculiar detail.
Thoughts?