Skip to content

Instantly share code, notes, and snippets.

@ghuntley
Created February 12, 2014 22:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ghuntley/8965605 to your computer and use it in GitHub Desktop.
Save ghuntley/8965605 to your computer and use it in GitHub Desktop.
public interface IMessageGateway
{
// will throw exception if sending fails
void SendSMS(SMS sms);
}
-------------------------------------------------
public class MessageDispatcher
{
private static readonly Logger Log = LogManager.GetCurrentClassLogger();
public IMessageGateway MessageGateway { get; private set; }
public MessageDispatcher(IMessageGateway gateway)
{
MessageGateway = gateway;
}
public void SendSMS(SMS sms)
{
Log.Info("Sending SMS to message gateway: {0}", sms.ToJson());
MessageGateway.SendSMS(sms);
}
}
@ghuntley
Copy link
Author

[13/02/2014 9:14:41 am]  so you have callbacks in NSubstitute where you can hide state like that
[13/02/2014 9:14:41 am]  http://nsubstitute.github.io/help/callbacks/
[13/02/2014 9:15:08 am]  but, how that mixes with throwing exceptions, i haven't tried
[13/02/2014 9:15:34 am]  ha, well look at that http://nsubstitute.github.io/help/throwing-exceptions/
[13/02/2014 9:15:47 am]  just throwing an exception inside the .Do seems to be all you need
[13/02/2014 9:16:51 am]  messageGateWay.WhenForAnyArgs(x => x.SendSms(null)).Do(x => if (++i < 2) { throw new Exception() });

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment