-
Notifications
You must be signed in to change notification settings - Fork 57
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
Extend expect method to allow additional testing #104
Comments
Some of the promise libraries out there have an so maybe:
Keep in mind that you can inherit from
Just hesitant of adding more flow related stuff to NSpec. Don't want it to get too complex. |
Not ultra-strictly related to this request:
|
@amirrajan public Action expectCheck<T>(Action action) where T : Exception
{
var expect = expect<T>();
return () =>
{
expect();
action();
};
} This works, but doesn't allow access to the actual exception (which I really didn't need for my case). I wanted to write a modified version of nspec.cs expect(string message), but the void describe_saving()
{
// define variables used by all tests
beforeEach = () => { /* initial setup for all contexts */ };
act = () => { /* single action for all nested contexts */ };
context["a null aggregate"] = () =>
{
beforeEach = () => { /* do context setup */ };
it["will throw an ArgumentNullException"] = expect<ArgumentNullException>();
};
context["an aggregate with a null Id"] = () =>
{
beforeEach = () => { /* do context setup */ };
it["will throw an ArgumentNullException"] = expect<ArgumentNullException>();
};
context["a new aggregate"] = () =>
{
// define variables used by this context
beforeEach = () => { /* do context setup */ };
it["will add the events to the stream"] = () => { /* do checks */ };
it["will mark the changes as committed"] = () => { /* do checks */ };
};
context["an existing aggregate with new changes"] = () =>
{
// define variables used by this context
beforeEach = () => { /* do context setup */ };
it["will add the events to the stream"] = () => { /* do checks */ };
it["will mark the changes as committed"] = () => { /* do checks */ };
context["and a new version has been saved in the background"] = () =>
{
// define variables used by this context
beforeEach = () => { /* do context setup */ };
it["will throw a ConcurrencyException"] = expect<ConcurrencyException>();
it["will not mark the changes as committed"] = expectCheck<ConcurrencyException>(() =>
{
// check that something didn't happen
});
};
};
} Down at the very bottom, the On a side note, is there an attribute or something I can use where I identify the method and set its name to a single word? Like @BrainCrumbz |
I'm fine with adding additional stuff if needed, just wanted show the inheritance technique and see if that would suffice. As long as the wiki entry is updated, I'm good with better exception handling changes. |
There is not currently a way to do additional testing after an exception is thrown in an
act
block. Theexpect<T>()
will detect that the exception was thrown, but does not allow for additional testing. Theexpect<T>(Action action)
takes a delegate, but it is expecting the delegate to throw the exception, not theact
block.I would like to have a third option that detects the exception was thrown by
act
, but allows me to add additional testing. Since the method signatureexpect<T>(Action action)
is already taken, perhaps a signature ofexpect<T>(Action<T> action)
. This would allow code like the following:The text was updated successfully, but these errors were encountered: