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

Pose not compatible with Code Coverage tools? #58

Open
jwdonahue opened this issue Mar 6, 2020 · 0 comments
Open

Pose not compatible with Code Coverage tools? #58

jwdonahue opened this issue Mar 6, 2020 · 0 comments

Comments

@jwdonahue
Copy link

I have a test case the runs successfully using MSTest, but when I try to get code coverage from it, it throws this exception:

    Test method SharperHacks.Diagnostics.UnitTests.RuntimePlatformSmokeTests.FakeLinuxRuntime threw exception: 
    System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.NotSupportedException: Specified method is not supported.
        at Pose.IL.MethodRewriter.Rewrite()
       at stub_JetBrains.Profiler.Windows.Core.Instrumentation.DataOnStack_JetBrains_Profiler_Windows_Core_Instrumentation_Begin(DataOnStack& , RuntimeMethodHandle , RuntimeTypeHandle )
       at dynamic_SharperHacks.Diagnostics.RuntimePlatform_get_PlatformId()
       at stub_SharperHacks.Diagnostics.RuntimePlatform_get_PlatformId(RuntimeMethodHandle , RuntimeTypeHandle )
       at dynamic_SharperHacks.Diagnostics.UnitTests.RuntimePlatformSmokeTests+<>c__DisplayClass0_0_<FakeLinuxRuntime>b__2(<>c__DisplayClass0_0 )
    --- End of inner exception stack trace ---
        at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)
       at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
       at System.Delegate.DynamicInvokeImpl(Object[] args)
       at Pose.PoseContext.Isolate(Action entryPoint, Shim[] shims)
       at SharperHacks.Diagnostics.UnitTests.RuntimePlatformSmokeTests.FakeLinuxRuntime() in D:\Repo\SharperHacks\src\C#\Diagnostics\UnitTests\RuntimePlatformSmokeTests.cs:line 25

Using Pose 1.2.1 on .NetCore 2.2 components.

The test:

using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Runtime.InteropServices;
using Pose;

namespace SharperHacks.Diagnostics.UnitTests
{
    [TestClass]
    public class RuntimePlatformSmokeTests
    {
        [TestMethod]
        public void FakeLinuxRuntime()
        {
            Shim fakeLinuxRuntimeInformation = Shim.Replace(() => RuntimeInformation.IsOSPlatform(Is.A<OSPlatform>()))
                .With(delegate(OSPlatform p) { return (p == OSPlatform.Linux); } );

            bool result = false;
            PoseContext.Isolate(
                () => { result = RuntimePlatform.PlatformId == OSId.eLinux; },
                fakeLinuxRuntimeInformation);

            Assert.IsTrue(result);
        }
    }
}

The unit under test:

namespace SharperHacks.Diagnostics
{
    using System.Runtime.InteropServices;

    public static class RuntimePlatform
    {
        public static OSId PlatformId
        {
            get
            {
                if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
                    return OSId.eLinux;
                if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
                    return OSId.eOSX;
                if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
                    return OSId.eWindows;
                return OSId.eUnknown;
            }
        }
    }
}

The whole point of the exercise of trying to find something to shim/mock static methods, was to reach 100% code coverage for all unit tests.

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

1 participant