Declined
Last Updated: 01 Feb 2021 09:56 by ADMIN
Maxim
Created on: 19 Apr 2017 08:19
Type: Bug Report
0
AssemblyInitialize Mock.SetupStatic
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.
1 comment
ADMIN
Ivo
Posted on: 01 Feb 2021 09:54

MsTest is a legacy tool replaced nowadays by VsTest.Console. The same applies to JustMockRunner and its successor JustMock.Console, please refer to this article for more details. Based on those facts, we are closing this issue as nonapplicable.

Regards,
Ivo
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.