MOQ 4.0: type initializer for "Moq.Mock`1" threw an exception

I get an exception

The type initializer for "Moq.Mock`1" threw an exception.

using Moq 4.0 I checked on several forums and they link to the version of Moq-NoCastle. I tried both this and the version in the Moq folder. Both with the same result.

I have a solution with two projects, one for my interface, one for my tests. My main project has 2 files:

IMyInterface.cs:

using System;

namespace Prototype
{
    public interface IMyInterface
    {
        int Value { get; set; }
        void ProcessValue();
        int GetValue();
    }
}

In my program.cs file there is only the default code generated by the project.

In my test project there is one file for my dummy test - TestProgram.cs

using System;
using NUnit.Framework;
using Moq;

namespace Prototype.UnitTests
{
    [TestFixture]
    public class TestProgram
    {
        Mock<IMyInterface> mock;

        [TestFixtureSetUp]
        void TestSetup()
        {
            mock = new Mock<IMyInterface>();
            mock.Setup(x => x.GetValue()).Returns(2);
        }

        [Test]
        public void RunTest()
        {
            IMyInterface obj = mock.Object; /* This line fails */
            int val = obj.GetValue();
            Assert.True(val == 2);
        }
    }
}

, . , . , , :

"Moq.Mock`1" .

, , - ?

+6
4

:

  • TestSetup()
  • RunTest, int val = obj.Value int val = obj.GetValue() - , Assert.

NUnit ( xUnit), , TestSetup() . , NUnit :

Prototype.UnitTests.TestProgram.RunTest:
Invalid signature for SetUp or TearDown method: TestSetup

, NUnit, - ( 2.5.7.10213).

+4

, Castle.Core NuGet 4.0.0. - , (v4.5.30).

, Castle.Core 3.3.3.

+8

Moq ( ).

NuGet Moq , . Moq NuGet NuGet.

+2

Moq, .

.

: System.TypeInitializationException: 'Moq.Mock'1' . ---- System.IO.FileNotFoundException: 'Microsoft.AspNetCore.Razor.Runtime, = 2.1.1.0, = , PublicKeyToken = adb9793829ddae60'.

Mock, . , . , , . .

0

All Articles