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
Assign an id to each fake, and add it to the fake's string representation #1905
Comments
We should consider whether this is breaking. We don't make any logical decisions based on the name, but the Fake's |
Good point. Not sure it's reason enough to not do it, though... I doubt many people are doing this, and there are obvious benefits to having the id. I guess we could have a flag to restore the original behavior, using runtime config settings and |
Actually, now that I think about it, ASP.NET Core uses a different mechanism. But .NET itself uses this (see the examples on the docs page). It could also be a static property somewhere, but it raises the question of when to initialize it, since there's no obvious entry point in unit tests (a module initializer would be appropriate, but it's only available since C# 9) |
Oh, man. You got fancy. I was just thinking to do it for 8.0.0 is all. |
We need to consider how it should work out with named fakes. Do we write the name and id? |
internal string FakeObjectDisplayName =>
string.IsNullOrEmpty(this.FakeObjectName)
? "Faked " + this.FakeObjectType
: this.FakeObjectName!; This is how
Here's what I suggest we do:
|
Thanks for collating this, @thomaslevesque. I'm going to need to mull. For example, I'm not sure why we use My knee-jerk reaction to (part of) your latest comments is that if Fakes are named, then we use that and forget about a numeric ID. But I'm not set on that… |
I think it would be useful to include the ID anyway. This could be helpful if the user accidentally created several fakes with the same name (or maybe created a fake that is accidentally reused across multiple tests). |
I am confused about why we use |
Yeah, I was confused too.
Instead of
"faked object Faked IFoo" is a bit of a mouthful, but it probably wouldn't hurt to be more explicit here. We could change the behavior to have "Faked {FakeObjectType}" as the default name (so we would always have a name), and always write the fakes as "{name} #{id}". At least it would be consistent... |
These are remarkably similar…
Yeah. I think seeing "Any call made to Faked IFoo" or similar would be an improvement.
Agreed. And the issue of "what type should we show on the left of that dot?" came up recently as well. I was wondering whether we couldn't get away with "[Faked IFoo].Bar()" or similar. Not married to the "[]"s, but figure we might need some way to delimit the Fake's name, especially since we have a space in it…
I am interested in exploring this. It may not transform users' experience, but consistency is nice both inside and outside the codebase. |
Oops! Fixed it
But that could be misleading. For instance, if the fake also implements another interface that has a |
Uninformative rather than misleading, I'd say. I see your point, but am not convinced we're reporting "the right one" all the time anyhow. Sigh. But we're reporting something, which I think is not a lie. You're probably right that it's better to keep a type there. |
e.g.
Faked IFoo #1
The goal is to make it easier, when debugging, to tell whether the expected Fake is the one that's being exercised by the production code.
The id would be a global counter for all fakes (no need to have a counter per type)
The text was updated successfully, but these errors were encountered: