I have logging class which are using everywhere.
I want to Mock this class for all tests. And i tried to use AssemblyInitialize but got problem. I have simulated this problem with JustMock.ElevatedExamples.AdvancedUsage examples:
1) Add BaseTest class
[TestClass]
public class BaseTest
{
[AssemblyInitialize()]
public static void AssemblyInit(TestContext context)
{
Mock.SetupStatic(typeof(Common1), StaticConstructor.Mocked);
// Arranging: When the static(Foo.FooProp_GET) property is called, it should return expected.
var fakeUsed = Mock.Create<LogWriter1>(Constructor.Mocked);
Mock.Arrange(() => Common1.Log).Returns(fakeUsed);
}
[AssemblyCleanup]
public static void Cleanup()
{
//clean up stuff here
}
}
public static class Common1
{
static Common1()
{
Log = new LogWriter1();
}
public static LogWriter1 Log { get; set; }
}
public class LogWriter1
{
}
2) When run test from VS - all ok
3) When run from command line it is not working. Show Message box "Process Starts Now".
SET JUSTMOCK_INSTANCE=1
SET COR_ENABLE_PROFILING=1
SET COR_PROFILER={B7ABE522-A68F-44F2-925B-81E7488E9EC0}
"C:\Program Files (x86)\Telerik\JustMock\Libraries\JustMockRunner.exe" "C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\MSTest.exe" /testcontainer:"D:\test\CSExamples\JustMock.ElevatedExamples\bin\Debug\JustMock.ElevatedExamples.dll"
How i can mock logger for all test? It is static public property.
I use MS Test + VS 2015.