We use the commercial version of JustMock and are working on a new prototype. Along the way, somehow, my Mock.Arranges for one test class have stopped working.
These are tests for our Azure KeyVault Wrapper and are super simple.
IKeyVault keyVault;
[SetUp]
public void SetUp()
{
var keyVaultClient = Mock.Create<IKeyVaultClient>();
Mock.Arrange(() => keyVaultClient.GetSecretAsync("http://www.myKeyStore.com/Key1", new CancellationToken()))
.Returns(Task.FromResult(new SecretBundle { Value = "Secret1" }));
Mock.Arrange(() => keyVaultClient.GetSecretAsync("http://www.myKeyStore.com/Key2", new CancellationToken()))
.Returns(Task.FromResult(default(SecretBundle)));
keyVault = new KeyVault(keyVaultClient);
}
[Test]
public async Task NewSecret_ShouldSucceed()
{
var secret = await keyVault.GetSecretAsync("Key1");
Assert.AreEqual("Secret1", secret);
}
[Test]
public async Task ShouldReturnNull_GetSecretAsync()
{
var secret = await keyVault.GetSecretAsync("Key2");
Assert.AreEqual(null, secret);
}
Both tests are returning SecretBundle objects with all default fields which seems to be an implementation from JustMock (not default(SecretBundle)). Neither have the correct values. The Arrange is simply not working.
I suspect this has something to do with references no longer being updated from Lite to Commercial, but I have no idea how to update them. The Update Reference button in the JustMock menu doesn't seem to do anything.
Any help on how to troubleshoot would be much appreciated. We plan to depend heavily on JustMock for testing this project. Note that these tests, in their current form, were working just fine and the underlying code hasn't changed.
-Geoff
Not sure if this is an XUnit.Net or JustMock (or both) issue. I have several tests on a solution that run and show passed but grayed out after a test run or build. VS2017 shows "Unexpected error detected. Check the Tests Output Pane for details. The Test Output pane has a dump (see below). The tests when run individually seem to pass and generate no errors, only when "Run All Tests" or as a result of a Build (run all tests after build set) do you see several tests grayed out. It's always the same four tests. Three have JustMock objects, one does not.
VS2017 Enterprise 15.2 (26430.12)
JustMock 2017.2.5303.3 (internal build to fix the 2017 profiler item)
This might be an internal build issue which is why I'm not logging it as a ticket, but thought I'd throw this in here to let you know about it.
------ Run test started ------
[xUnit.net 00:00:00.2643557] Discovering: UnitTests
[xUnit.net 00:00:01.0713800] Discovered: UnitTests
[xUnit.net 00:00:01.4834782] Starting: UnitTests
[xUnit.net 00:00:03.0127894] [FATAL ERROR] System.ArgumentException
[xUnit.net 00:00:03.0171999] System.ArgumentException :
'this'
type cannot be an
interface
itself.
[xUnit.net 00:00:03.0198958] Stack Trace:
[xUnit.net 00:00:03.0207009]
[xUnit.net 00:00:03.0214322] Server stack trace:
[xUnit.net 00:00:03.0221175] at System.RuntimeTypeHandle.VerifyInterfaceIsImplemented(RuntimeTypeHandle handle, RuntimeTypeHandle interfaceHandle)
[xUnit.net 00:00:03.0227770] at System.RuntimeTypeHandle.VerifyInterfaceIsImplemented(RuntimeTypeHandle interfaceHandle)
[xUnit.net 00:00:03.0232817] at System.RuntimeType.GetInterfaceMap(Type ifaceType)
[xUnit.net 00:00:03.0239207] at Telerik.JustMock.Core.MockingUtil.IsImplementedBy(MethodInfo interfaceMethod, MethodBase implMethod)
[xUnit.net 00:00:03.0243577] at Telerik.JustMock.Core.Context.HierarchicalTestFrameworkContextResolver.MatchTestClassDispose(MethodBase method, String[] testMethodAttributes)
[xUnit.net 00:00:03.0249418] at Telerik.JustMock.Core.Context.HierarchicalTestFrameworkContextResolver.<>c__DisplayClass31.<SetupStandardHierarchicalTestStructure>b__1f(MethodBase method)
[xUnit.net 00:00:03.0255662] at Telerik.JustMock.Core.Context.HierarchicalTestFrameworkContextResolver.<>c__DisplayClassa.<FindTestMethod>b__9(RepositoryOperationsBase repo)
[xUnit.net 00:00:03.0261179] at System.Linq.Enumerable.Any[TSource](IEnumerable`1 source, Func`2 predicate)
[xUnit.net 00:00:03.0266557] at Telerik.JustMock.Core.Context.HierarchicalTestFrameworkContextResolver.<FindTestMethod>b__8(MethodBase method)
[xUnit.net 00:00:03.0271733] at System.Linq.Enumerable.WhereEnumerableIterator`1.MoveNext()
[xUnit.net 00:00:03.0276714] at System.Linq.Enumerable.<DistinctIterator>d__63`1.MoveNext()
[xUnit.net 00:00:03.0281930] at System.Linq.Buffer`1..ctor(IEnumerable`1 source)
[xUnit.net 00:00:03.0286994] at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
[xUnit.net 00:00:03.0292425] at Telerik.JustMock.Core.Context.HierarchicalTestFrameworkContextResolver.FindTestMethod(Int32& repoIdx, RepositoryOperationsBase& entryOps)
[xUnit.net 00:00:03.0297270] at Telerik.JustMock.Core.Context.HierarchicalTestFrameworkContextResolver.ResolveRepository(UnresolvedContextBehavior unresolvedContextBehavior)
[xUnit.net 00:00:03.0301511] at Telerik.JustMock.Core.Context.MockingContext.ResolveRepository(UnresolvedContextBehavior unresolvedContextBehavior)
[xUnit.net 00:00:03.0305562] at Telerik.JustMock.Core.MocksRepository.GetMockMixin(Object obj, Type objType)
[xUnit.net 00:00:03.0309488] at Telerik.JustMock.Core.Invocation..ctor(Object instance, MethodBase method, Object[] args)
[xUnit.net 00:00:03.0313652] at Telerik.JustMock.Core.ProfilerInterceptor.InterceptCall(RuntimeTypeHandle typeHandle, RuntimeMethodHandle methodHandle, Object[] data)
[xUnit.net 00:00:03.0318462] at System.MarshalByRefObject.GetIdentity(MarshalByRefObject obj, Boolean& fServer)
[xUnit.net 00:00:03.0323720] at System.Runtime.Remoting.IdentityHolder.FindOrCreateServerIdentity(MarshalByRefObject obj, String objURI, Int32 flags)
[xUnit.net 00:00:03.0328321] at System.Runtime.Remoting.RemotingServices.GetOrCreateIdentity(MarshalByRefObject Obj, String ObjURI, Boolean isInitializing)
[xUnit.net 00:00:03.0363414] at System.Runtime.Remoting.RemotingServices.MarshalInternal(MarshalByRefObject Obj, String ObjURI, Type RequestedType, Boolean updateChannelData, Boolean isInitializing)
[xUnit.net 00:00:03.0369562] at System.Runtime.Remoting.RemotingServices.MarshalInternal(MarshalByRefObject Obj, String ObjURI, Type RequestedType, Boolean updateChannelData)
[xUnit.net 00:00:03.0375367] at System.Runtime.Remoting.RemotingServices.MarshalInternal(MarshalByRefObject Obj, String ObjURI, Type RequestedType)
[xUnit.net 00:00:03.0381086] at System.Runtime.Remoting.Messaging.MessageSmuggler.FixupArg(Object arg, ArrayList& argsToSerialize)
[xUnit.net 00:00:03.0386417] at System.Runtime.Remoting.Messaging.MessageSmuggler.FixupArgs(Object[] args, ArrayList& argsToSerialize)
[xUnit.net 00:00:03.0390906] at System.Runtime.Remoting.Messaging.SmuggledMethodCallMessage..ctor(IMethodCallMessage mcm)
[xUnit.net 00:00:03.0395394] at System.Runtime.Remoting.Messaging.SmuggledMethodCallMessage.SmuggleIfPossible(IMessage msg)
[xUnit.net 00:00:03.0400477] at System.Runtime.Remoting.Channels.CrossAppDomainSink.SyncProcessMessage(IMessage reqMsg)
[xUnit.net 00:00:03.0404910]
[xUnit.net 00:00:03.0408806] Exception rethrown at [0]:
[xUnit.net 00:00:03.0412930] at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
[xUnit.net 00:00:03.0417710] at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
[xUnit.net 00:00:03.0623429] [FATAL ERROR] System.ArgumentException
[xUnit.net 00:00:03.0998317] [FATAL ERROR] System.ArgumentException
[xUnit.net 00:00:04.3804395] Finished: UnitTests
========== Run test finished: 35 run (0:00:04.5228864) ==========
Hi,
I'm trying to generate a code coverage report using JetBrains dotCover and the JustMockRunner. I have the following batch file, which I plan to run on a schedule, which links dotCover, runs the coverage, and then unlinks dotCover.
1.
start /wait
""
"C:\Program Files (x86)\Telerik\JustMock\Libraries\Telerik.JustMock.Configuration.exe"
/link
"dotCover"
2.
"dotCover.exe"
cover
"C:\Temp\Settings.xml"
3.
start /wait
""
"C:\Program Files (x86)\Telerik\JustMock\Libraries\Telerik.JustMock.Configuration.exe"
/unlink
"dotCover"
The dotCover settings file has the following settings.
01.
<?
xml
version
=
"1.0"
encoding
=
"utf-8"
?>
02.
<
AnalyseParams
>
03.
<
TargetExecutable
>C:\JustMock\JustMockRunner.exe</
TargetExecutable
>
04.
<
TargetArguments
>"C:\Program Files (x86)\NUnit 2.6.4\bin\nunit-console.exe" "C:\Temp\Release64\JustMock.Tests.dll" /noshadow /xml="C:\Temp\Coverage JustMock Test Results.xml"</
TargetArguments
>
05.
<
Output
>C:\Temp\Coverage Snapshot JustMock.dcvr</
Output
>
06.
<
Scope
>
07.
<
ScopeEntry
>C:\Temp\Release64\TestClass.dll</
ScopeEntry
>
08.
</
Scope
>
09.
</
AnalyseParams
>
Everything seems to work correctly, with all tests passing, but I don't get any code coverage.
Have I missed something?
I'm attempting to update (not add) a record in a mocked DB and am not succeeding. I have a FakeDbEntries that is an IList<LogEntry>. I have Mocked my DbContext as
_mockLogRepo = Mock.Create<ILogRepo>();
_mockLogRepo.Arrange(m => m.LogEntries).ReturnsCollection(FakeDbEntries());
When I run the unit under test that calls the ILogRepo and does the update, the SaveChanges() never sticks.
There is one interface where when I try to mock it it throws an exceptions
System.IO.FileLoadException : Could not load file or assembly 'MyFramework, Version=2017.12.12.1, Culture=neutral, PublicKeyToken=null' or one of its dependencies. A strongly-named assembly is required.
None of our projects are strong named, and my best guess is that it has something to do with the nature of the interface we're trying to mock. For simplicity sake I'll describe our project like this:
One of the methods in the IMessageLogger interface has an argument where the type is defined in the MyFramework project.
When I call Mock.Create<IMessageLogger>() I get the error above. My only thought is that because the Telerik.JustMock assembly is strong named, it is for some reason having trouble loading the MyFramework assemble even though it can miraculously load the MyFramework.Lib assembly.
I was wondering if there is any workaround I might be able to try so that I can mock this piece. I can live without mocking this specific interface, but I may not be so lucky with others...
Hello,
I'm trying to write a powershell script to run my tests, create code coverage using OpenCover and then generate a report using ReportGenerator. However I'm running into the Profiler error:
The profiler must be enabled to mock, arrange or execute the specified target.
Detected active third-party profilers:
* (from process environment)
This only happens when run from the powershell, if I run it from command line the tests run fine. The command I am using is:
packages\OpenCover.4.6.519\tools\OpenCover.Console.exe -mergebyhash -target:"%VS140COMNTOOLS%\..\IDE\CommonExtensions\Microsoft\TestWindow\vstest.console.exe" -targetargs:"JustMockUnitTests\bin\x64\Debug\JustMockUnitTests.dll /InIsolation /platform:x64 /logger:trx /Parallel" -output:"OpenCover.xml"
Any thoughts would be much appreciated.
Thanks
-Steve
Is there any way to enable profiler in JetBrains Rider?
I have a scenario that I cannot seem to get working just like i would like.
I have been able to successfully write a test method against my private method just fine.
Now, I'm trying to write a test against my public method. In the public method, i want to the call to the private method to be mocked and return a mocked value so the remainder code in my public method will handle that result.
However, when it comes time to execute the line of code in the public method that would call the private method, all that comes back is NULL. I don't get my mocked value.
Here is my current test
var mockedClass = Mock.Create<JHADirectoryServiceAPI>(Constructor.Mocked);
var autoFix =
new
Fixture();
var otherPhoneDtoCollection_AM = autoFix.Create<IEnumerable<OtherPhoneDto>>();
var inst =
new
PrivateAccessor(mockedClass);
Mock.NonPublic.Arrange<IEnumerable<OtherPhoneDto>>(mockedClass,
"GetOtherPhonesByOfficeID"
, Arg.AnyGuid)
.DoInstead(()=> inst.CallMethod(
"GetOtherPhonesByOfficeID"
, Arg.AnyGuid)).ReturnsCollection(otherPhoneDtoCollection_AM);
Assume the below code...
Public
IEnumerable<Object>
GetDetails(Guid value)
{
//do some local stuff
var result = GetOtherPhonesByOfficeID(value);
//eval result
return
myList
}
private
IEnumerable<OtherPhoneDto>
GetOtherPhonesByOfficeID(Guid value)
{
//Do some Stuff
return
myList
;
}