Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

It.IsAny<decimal> throws "System.decimal is not a supported constant type" #265

Closed
dinismvcorreia opened this issue May 30, 2016 · 14 comments

Comments

@dinismvcorreia
Copy link

dinismvcorreia commented May 30, 2016

I was using Moq 4.5.3. and decided to update Moq Nuget package to the latest version, which is 4.5.8.
Suddenly, a lot of my tests started to fail. I found that the issue occurs when using It.IsAny<decimal> on decimal optional arguments. It throws "System.decimal is not a supported constant type". It also happens in version 4.5.7.
Simple, silly test:

public interface IFoo { bool Method(decimal decimalArg = 0m); }

public class Some
{
    public int SomeMethod(IFoo foo) => foo.Method(10m) ? 1 : 0;
}

[TestFixture]
public class SomeTests
{
    [Test]
    public void SampleTest()
    {
        var fooMock = new Mock<IFoo>();
        fooMock.Setup(m => m.Method(It.IsAny<decimal>())).Returns(true);

        var sut = new Some();
        var actual = sut.SomeMethod(fooMock.Object);

        Assert.That(actual, Is.EqualTo(1));
    }
}
@kzu
Copy link
Contributor

kzu commented May 30, 2016

Closed? Why?

@dinismvcorreia
Copy link
Author

Sorry, kzu, my bad. Pressed the wrong button. Anyway, I've edited the initial issue. Now, with the code sample I've supplied, it's easier to reproduce the issue.

@richardlawley
Copy link

The bug actually occurs when the object is constructed, therefore a much simpler repro is:

public interface IFoo { bool Method(decimal decimalArg = 0m); }

[TestClass]
public class SomeTests
{
    [TestMethod]
    public void SampleTest()
    {
        var fooMock = new Mock<IFoo>();
        var sut = fooMock.Object;
    }
}

@richardlawley
Copy link

As mentioned in this SO post, this is related to a Castle Core bug: castleproject/Core#87

@kzu
Copy link
Contributor

kzu commented Jun 1, 2016

So what are we missing? A dependency bump only? PR? ;)

@MichaelLogutov
Copy link

Any news on that? We're facing false negatives all around :)

@dampee
Copy link

dampee commented Jul 7, 2016

Has anyone found a solution for this?

@i4004
Copy link

i4004 commented Jul 8, 2016

@dampee You can use alpha version of Moq (4.6.25-alpha).

@dampee
Copy link

dampee commented Jul 8, 2016

@i4004 thanks. I have reverted to 4.2 yesterday. Can't upgrade to prerelease versions currently. Looking forward to the release.

@brianbegy
Copy link

Any update on this issue?

@tidusjar
Copy link

tidusjar commented Sep 8, 2016

I've just run into this issue. 😢

@pipelf
Copy link

pipelf commented Oct 11, 2016

same problem here.

@jaredpar
Copy link

I hit what I believe is a similar issue trying to mock some Visual Studio Interfaces:

System.Runtime.InteropServices.DispatchWrapper is not a supported constant type.

It does appear to be a dupe of the castle bug: castleproject/Core#87

In my tests I was able to work around this by upgrading the Castle NuGet package to 4.0.0-beta002.

jaredpar added a commit to VsVim/VsVim that referenced this issue Nov 18, 2016
This is a necessary pre-req for adopting Application Insights.  It is supported on 4.0 but it brings along too many
dependencies with it for my comfort.  Once 4.5 is targeted it brings down a single DLL which is managable.

The only downside of moving to 4.0 is losing easy support for VS 2010.  That release only required 4.0 be installed.  But that is lost anyways by virtue of moving to VSIX V3.

This change also forced me to upgrade to a new versiont of Moq.  It itself not an issue but I did run into the following bug:

- devlooped/moq#265

Worked around it by moving Castle forward to a newer version.
jaredpar added a commit to VsVim/VsVim that referenced this issue Nov 20, 2016
This is a necessary pre-req for adopting Application Insights.  It is supported on 4.0 but it brings along too many
dependencies with it for my comfort.  Once 4.5 is targeted it brings down a single DLL which is managable.

The only downside of moving to 4.0 is losing easy support for VS 2010.  That release only required 4.0 be installed.  But that is lost anyways by virtue of moving to VSIX V3.

This change also forced me to upgrade to a new versiont of Moq.  It itself not an issue but I did run into the following bug:

- devlooped/moq#265

Worked around it by moving Castle forward to a newer version.
@kzu
Copy link
Contributor

kzu commented Feb 21, 2017

We've now bumped to Castle 4.0 stable, so it should be fixed

@kzu kzu closed this as completed Feb 21, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants