Reputation: 11205
I am a windows forms programmer. We generally programme functionality into a user control. And many time functionality requires to send an email.
I want to do some thing like :- if i set up the flag "This application is running in testing mode". Then all mail sent form the application (from any of the user control) should be blocked.
Remember i dont want to do any changes in my existing user controls. or the mail sending lib. I want this to be done only in the container or rather in the Program.cs file.
Thanks
Upvotes: 1
Views: 139
Reputation: 3837
If you are wanting to turn it off for local debugging then you can do this.
#if DEBUG
CallMethod();
#endif
Otherwise, Matthew Flaschen's answer works well.
Upvotes: 0
Reputation: 284836
You can use Inversion of Control. Have, e.g. a IMailer interface, implemented by RealMailer and TestingMailer. RealMailer will actually send an email, while TestingMailer will silently drop mails. Configure a Production configuration that injects RealMailer, and Testing configuration that injects TestingMailer.
Upvotes: 4
Reputation: 12414
Those kind of setting should go in your app.config file, in this case smtp server address. then simply change that value to empty for test environment so your mail is going nowhere.
Upvotes: 0