-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Create public contructors for StackExchange.Redis event args for testing purpose #1326
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
Create public contructors for StackExchange.Redis event args for testing purpose #1326
Conversation
| /// <param name="hashSlot">Hash slot.</param> | ||
| /// <param name="old">Old endpoint.</param> | ||
| /// <param name="new">New endpoint.</param> | ||
| public HashSlotMovedEventArgs(EventHandler<HashSlotMovedEventArgs> handler, object sender, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is a very unusual API, for specific reasons; I don't think any external caller (for unit testing etc) would need this - or indeed could use this; I wonder if the public constructor should just be:
public HashSlotMovedEventArgs(int hashSlot, EndPoint old, EndPoint @new) : this (null, null, hashSlot, old, new) {}thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still this is a public event and someone may be interested to unit-test some scenarios. For testing purpose I don't think the c'tor should be different.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My answer to that, then: is show the scenario that needs that, ideally in a test. Adding something without a demonstrated use-case is ... not a good way to design the API usually.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mgravell this is an outdated comment. I've updated a pr. So yes, I agree with you, handler is no need for this.
| /// <param name="failureType">Redis connection failure type.</param> | ||
| /// <param name="exception">The exception occured.</param> | ||
| /// <param name="physicalName">Connection physical name.</param> | ||
| public ConnectionFailedEventArgs(EventHandler<ConnectionFailedEventArgs> handler, object sender, EndPoint endPoint, ConnectionType connectionType, ConnectionFailureType failureType, Exception exception, string physicalName) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
similar to the comment on EndPointEventArgs - I wonder if the public .ctor should not expose handler / sender
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Answer is the same.
| /// <param name="connectionType">Redis connection type.</param> | ||
| /// <param name="exception">The exception occured.</param> | ||
| /// <param name="origin">Origin.</param> | ||
| public InternalErrorEventArgs(EventHandler<InternalErrorEventArgs> handler, object sender, EndPoint endpoint, ConnectionType connectionType, Exception exception, string origin) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto
| /// <param name="sender">The source of the event.</param> | ||
| /// <param name="endpoint">Redis endpoint.</param> | ||
| /// <param name="message">Error message.</param> | ||
| public RedisErrorEventArgs( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto
|
The very unusual construction API here is because of the way that In particular, I don't want to force us to make an implementation detail part of the public API. Thoughts and discussion welcome. Also: it would really help to see these how they are intended to be used, i.e. in a unit test that uses them how you want to. |
n1l
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mgravell ok let me create some samples for example
|
Oh, mb you're talking about public ctor's without params at all? Like for testing purpose? |
no, it is just the |
|
see also: the example I gave for |
|
@mgravell But still I think I need sender becase I want to be aware of the type of the library raised the event. So only handler is not need. |
f2ff868 to
7088227
Compare
|
@mgravell I've updated please take a look. |
|
@mgravell Ahh, ok it's not a big deal. Also there are some fails on linux. |
…le to create tests scenarios based on redis events.
1091383 to
7a2314b
Compare
|
@mgravell please take a look again :) |
|
@mgravell is everything ok? :) |
|
I know you don't mean anything by it, but keep in mind that OSS maintainers aren't around 24/7 to jump on reviews - lost of plates spinning, including jobs, family, sleep, etc; I plan on taking another look as soon as I have a moment, probably later today. |
|
@mgravell Thank you! :) |
|
Minor language note here, could you please change all descriptions from "The constructor for testing purpose." to "This constructor is only for testing purposes."? |
sure! |
|
Constructors look good, but there's still nothing test-wise that indicates the intended usage. What makes me nervous is that as a general principle of API design, I usually prefer to see an example usage along with any new API (including new methods/overloads); that's usually how we discover whether the proposed API actually achieves the things we want to demonstrate. Is there any way of adding a meaningful test here? Not just "oh look, I can call a constructor" - but rather: something that actually shows why we're adding it, and that we have achieved what we wanted. If that means adding Moq or whatever to the test project, I'm fine with that... |
Yes of course, I was just a bit lazy to add them because I thought it's obvious, but ok it's not a big deal again.
Do you mean something except tests(documentation, comments samples) or only tests? |
I'm just talking about tests here; this isn't an API that needs documentation - just: you're adding this API because you want to do a thing; it would be good to see the thing happening, so we can prove that it is the right API and enables the thing. |
|
Hi, @NickCraver , @mgravell ! So the Idea is - if I have a component which can do some diagnostic for me(logging, pushing events etc) I want to tests it's handlers. But if there is no public c'tors for event args I can't invoke such handlers and test my component. |
|
Awesome. Will look!
…On Sat, 1 Feb 2020, 16:30 n1l, ***@***.***> wrote:
Hi, @NickCraver <https://github.com/NickCraver> , @mgravell
<https://github.com/mgravell> !
I've added some tests for the feature. I've removed sealed attribute
because substitute mocking framework can't create proxy for a sealed class.
Hope it's ok.
So the Idea is - if I have a component which can do some diagnostic for
me(logging, pushing events etc) I want to tests it's handlers. But if there
is no public c'tors for event args I can't invoke such handlers and test my
component.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#1326?email_source=notifications&email_token=AAAEHMBRAOQ65H3SY6MZYQ3RAWPSHA5CNFSM4KJSCLM2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEKRA53I#issuecomment-581045997>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAAEHMB2S772CCG6ECDBXP3RAWPSHANCNFSM4KJSCLMQ>
.
|
|
Merging, thanks |
Create public contructors for StackExchange.Redis event args to be able to create tests scenarios based on redis events. Add sealed attribute to other EventArgs for consistency.
Issue with details - #1325