Is there an easy way to determine if you are working in the context of a Visual Studio test, and not debugging or release?
Here's the scenario - we have a factory class that we use heavily in the entire existing code base, and I decided to reorganize it in each class instead, so that we can replace the standard factory with one that returns mock / fake objects, I could add something in the factory class to return these layouts if it detects that it is in test mode.
I don’t think it’s nice to mix test code with domain code.
factory mocks .
, , RhinoMocks.
mcabral ( , ), ...
Visual Studio , "Debug" "Release", , . , "" , , Debug. "" , factory.
"". "" : "".
#if TESTING // build stubs #else // build real implementations #endif
Injection Dependency IOC? .
, IOC , factory. , factory IOC.
- ( ), .
You can test the current executable file of the process. It is not very elegant, but it works.
if (Process.GetCurrentProcess().ProcessName.ToLower().Contains("vstest.executionengine")) { // we are in a ms unit test } else { // normal programm execution }
Source: https://habr.com/ru/post/1740022/More articles:Jasper Report: how to configure JasperViewer so that it can export in only one format? - javaКак вы регистрируете анонимные функции? - javaConfiguring ProcessStartInfo.WorkingDirectory on a UNC path - c #Import IIS Log in SQL Server 2008 - sql-serverError starting Eclipse when copying and pasting - eclipseWhat is the maximum allowed URL size for a GET request in IE8? - internet-explorerIs mspec better with or without nunit? - nunitwpf: getting combobox value - wpfSpring MVC works with web designers - javahttps://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1740027/can-i-use-monos-aot-feature-to-natively-pre-compile-net-dllsexes-to-make-them-harder-to-reverse-engineer&usg=ALkJrhjted3wrRr1de1QtzpG1zNEZTljNQAll Articles