Determining Development/Testing Mode in .Net
One of the things I’m trying to do with amplify is attempt to force as little configuration upon the developer as possible. However one does need to know what time of environment the code is currently executing in order to do specific things, like using different databases for testing, development, and production. One of the problems to solve with this is having amplify compiled in a non-debug mode and still determine if the developer is in a "development" mode or even "test" mode. Testing is generally going to have its own testing project, so this can be manually set in something like an "AssemblyFixture". testing.
That being said, when a developer is debugging, it should be in ‘development’ mode since you need that extra debug information as well an application is usually debugged when being developed. The ‘test’ mode should be when a developer is running automated unit tests that should go hand in hand with some kind of data fixtures being loaded for those tests. An example of what I’m currently doing in the "Amplify.ApplicationContext" class is currently below.
static Constructor
{
IsWebsite = (System.Web.HttpContext.Current != null);
System.Web.Configuration.CompilationSection section
= (System.Web.Configuration.CompilationSection)
ConfigurationManager.GetSection("system.web/compilation");
IsDevelopment = (section != null && section.Debug);
if(!IsDevelopment)
IsDevelopment = System.Diagnostics.Debugger.IsAttached;
}
public static bool IsWebsite { get; internal set; }
public static bool IsDevelopment { get; set; }
public static bool IsTesting { get; set; }
[FixtureSetUp]
public void InvokeOnStartUp()
{
try
{
ApplicationContext.IsTesting = true;
}
catch (Exception ex)
{
Console.WriteLine(ex);
Assert.Fail(ex.ToString() + "\n stack trace: " + ex.StackTrace);
}
}
Of course there might be a better solution as always, but for now this will do and I’m definitely open to suggestions.