You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
I have a test case the runs successfully using MSTest, but when I try to get code coverage from it, it throws this exception:
Using Pose 1.2.1 on .NetCore 2.2 components.
The test:
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Runtime.InteropServices;
using Pose;
The unit under test:
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.
The text was updated successfully, but these errors were encountered: