Reputation: 1891
What is the best way to change behavior between DEV, TEST, and RELEASE builds?
I have an application that sends emails to recipients stored in a database. When developing and testing I would like to override the desired behavior and send the email to the person using the application (e.g. the developer or tester).
When we go to production, I would like to of course send it to the email coming from the database.
I considered adding a RELEASE constant as discussed here
Does anyone have some advice on the best way to achieve this or a suggestion as to a better way to approach the problem?
Upvotes: 1
Views: 148
Reputation: 6193
I'm using XmlPreprocess tool for config files manipulation. It is using one mapping file for multiple environments. You can edit mapping file by Excel. It is very easy to use.
Upvotes: 1
Reputation: 476
In our projects we add keys like "Environment" and "EmailsToInTestEnvironment" to config file. In "Environment" we specify either "production" or "test" and if it is "test", the application replaces original email with the ones listed in "EmailsToInTestEnvironment".
To make it simple and realistic, the replacement occurs in the method sending email, not in methods calling it. Original address gets replaced right before the email goes out, and once once the email is sent, original email address is being returned back.
Upvotes: 1
Reputation: 43097
If you're using ASP.NET, you could have web.config settings that change based on the current publish configuration.
http://msdn.microsoft.com/en-us/library/dd465318.aspx
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<connectionStrings>
<add name="MyDB"
connectionString="ReleaseSQLServer"
xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
</connectionStrings>
</configuration>
Upvotes: 1
Reputation: 1087
This should be done by using separate config files for your application. Visual studio already provides debug and release separation for you. If by test you mean unit test, then the test project that's loading your app will be able to use its own config file there.
Upvotes: 0
Reputation: 100358
Wrap email send functionality with an interface, say INotifier.Send()
. Implement it in several ways:
EmailNotifier : INotifier
for release (send email)
LocalNotifier : INotifier
for debug (write into console)
MockNotifier : INotifier
for test (assert some conditions)
Put class's type into configuration-specific config and read and invoke it by notification send module. See Web.config transform.
Upvotes: 4