-
Notifications
You must be signed in to change notification settings - Fork 179
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
Raise Non-EventArgs events #30
Comments
+1 for that feature. I just ported an application from using Rhino.Mocks to FakeItEasy. That the only feature I am missing so far. With that kind of implementation, will it be possible to Raise an |
With my current understanding of FakeItEasy internals it is not that easy to implement this feature without breaking existing stuff. I definitely need to take a deeper look inside, but I'm lacking spare time at the moment :-( |
Duplicate of issue #26 |
Just to say: |
I'll be happy to help if there is a consensus on how that feature should be On Thu, Jan 10, 2013 at 4:59 PM, Philipp Dolder notifications@github.comwrote:
|
I still have to think about the best syntax and details how it should be done yet. I think it should just be possible to raise any kind of delegate. Thanks, msevestre. I will come back to you when I know more |
How is this done in NSub? I think they did borrow the Raise-syntax but I haven't really looked at it. |
I'm starting to spike this one |
Awesome!!
|
great |
from what I've found out so far it's not possible (with my knowledge and understanding) to use the same approach as we use to raise normal events to implement the raising of delegates (and actions). The problem is the Now method in the Raise which I cannot rebuild when I want to have any delegate instead of EventHandler. thoughts? |
NSub doesn't use the I'm currently having an issue (see above) with the |
@philippdolder if you push your changes onto a branch in your fork I'll take a look. |
Could we do something like Raise.NonEventDelegateWith()? Maybe we could even hide that from intellisense (EditorBrowsableAttribute) so that it can be used but it's not discoverable so that we don't promote this worst practice. |
@patrik-hagne I wouldn't hide it away. If people don't see it, they won't find it. But maybe that feature should be part of a kind of additional package, because we don't want to encourage people to do it that way? @FakeItEasy/owners do we agree that using events with custom delegates that are not (object sender, EventArgs e) are bad practice? I'm personally not strongly opinionated on that. |
I think it is bad practice but sometimes you just need to fake that nasty third party dependency... Whilst I sympathise with the motivation to hide it from Intellisense, for most people !Intellisense == !Exists. No one will ever know about it and I bet we'll just get same issue raised again :-) |
So. What do you think about creating a separate package then? We should not do it in "Core" and then remove it later. I'd prefer having a 2nd nuget package where we put "things you shouldn't do, but sometimes have to" (see also #90). FakeItEasy.LegacyExtensions comes to my mind for a name. Or something more general where we can put everything that is not part of the core framework? |
Hi all, I do not agree that this is bad practice. In my opinion, the fact that an There are so many use cases where the code looks easier to read when you I truly think it belongs into the core package. Why should we deal with yet On Tue, Apr 30, 2013 at 2:08 PM, Philipp Dolder notifications@github.comwrote:
|
I would argue that that would make it even less discoverable. I'd say it'd be better for it to be hidden but when discovered (through the wonders of Google) it'd be accessible directly rather than having to download something. Can we change the syntax to be exactly what NSub does? |
@msevestre It goes against the coding guidlines for the framework and expectations of "consumers" so it is bad practice. You can always use whatever delegate for callbacks, just don't tag it with the event keyword since that will break in so many scenarios. I do agree that the guidlines shouldn't have been that way, but they are. |
I haven't seen anything break because the event does not respect the On Tue, Apr 30, 2013 at 2:21 PM, Patrik Hägne notifications@github.comwrote:
|
At the moment my view is that we should add a new method group in the main package, visible to Intellisense, just like NSub do. NSub has method groups:
FIE has:
I think we can just add |
Great idea! +1
|
I think really I just formalised what @patrik-hagne suggested ;-) |
@adamralph sounds reasonable to me. |
Sounds good, what would be the exact signature of |
In NSub it's public static DelegateEventWrapper<THandler> Event<THandler>(params object[] arguments) I guess FIE could do something very similar, e.g. public static DelegateRaise<THandler> Event<THandler>(params object[] arguments) where NSub's If we feel that this is getting too messy with |
We could even think about deprecating the |
Now planning for 2.0.0 release. We will remove |
An additional breaking change that I think we should consider: having |
Agree. |
This issue has been fixed in release 2.0.0. |
The
Raise<>.With
syntax is typed to events with theEventArgs
convention.There are many cases where I use events with custom delegate types, like such
Unfortunately I cannot raise such an event on a Fake with the given
Raise<>
API.A way to raise any type of delegate/cargo would be very useful; meaning if
Raise<>
took a custom/generic delegate signature and didn't force the(sender,EventArgs)
pattern.The use case I imagine (or, really, expected at first) was this (continuing the above delegate example):
or maybe
where, in the latter case, Raise would expose an
Action<TCargo>
or similar.Not sure how much of this is really possible, but depending on how desperate I get I might try to hack it up myself in a fork.
However, I'm sure you guys know what to do in this case much better than I do :-)
Thanks for the great tool!
The text was updated successfully, but these errors were encountered: