JustMock Q2 2016 SP1 (2016.2.713.2)
I have the JustMock license. I installed JustMock (the JustMock_2016_2_713_2_Dev.msi file). Also I downloaded and extracted the `JustMock_2016_2_713_2_Help3.zip` file. Now I launch the `Install_TelerikJustMock.bat` file but I get the error message:
> Error: It isn't possible to find the specified section or parameter in the register.
> Ensuring same version not registered...
> ""\HelpLibManager.exe"" isn't internal or external
> command, runtime program or batch file.
> Registering the new version...
> ""\HelpLibManager.exe"" isn't internal or external
> command, runtime program or batch file.
> Done.
> Press any key for exit...
I have the class under test:
1.
public
class
AppManager {
2.
public
string
[] GetAppSets() => Registry.LocalMachine
3.
.OpenSubKey(@
"SOFTWARE\Autodesk\AutoCAD"
,
false
)
4.
?.GetSubKeyNames();
5.
}
Also, I have the test for `GetAppSets` method:
01.
[Test]
02.
public
void
Foo_Returns_ValidValue() {
03.
04.
const
string
subkey = @
"SOFTWARE\Autodesk\AutoCAD"
;
05.
/* The sets of applications which are based on
06.
* AutoCAD 2009-2017. */
07.
string
[] fakeSets =
new
[] {
"R17.2"
,
"R18.0"
,
08.
"R18.1"
,
"R18.2"
,
"R19.0"
,
"R19.1"
,
"R20.0"
,
09.
"R20.1"
,
"R21.0"
};
10.
11.
RegistryKey rk = Mock.Create<RegistryKey>();
12.
13.
Mock.Arrange(() => rk.GetSubKeyNames()).Returns(
14.
fakeSets);
15.
16.
Mock.Arrange(() => Registry.LocalMachine.OpenSubKey
17.
(subkey,
false
)).Returns(rk);
18.
19.
AppManager appMng =
new
AppManager();
20.
string
[] appSets = appMng.GetAppSets();
21.
22.
Assert.AreEqual(fakeSets, appSets);
23.
}
It works. But my test will be failure if `GetAppSets` method uses "Software\Autodesk\AutoCAD" or "software\autodesk\autocad" string instead of "SOFTWARE\Autodesk\AutoCAD".
So, at this case I need to handle parameter like the case insensitive string. Is it possible?
Is there any updated information on setting up elevated mocking with TFS 2015 and vNext builds? None of the documentation appears to be updated for the new build system or my googleFu is seriously failing me.
I noticed some behavior with maybe xUnit and JustMock when testing private methods. By below setup works fine and the tests run, however in my "MemberData" class, if i pass in more that one dataset for testing, then when the second time the test runs with the new set of data, the private method code never gets executed. It gets to the "CreateUpdateFavoriteFacility" code in my api class and then just "steps over" the call to my private method.
Here is my Test Setup:
[Theory]
[MemberData(
"FacilityFavorite"
,
MemberType =
typeof
(FavoriteTestData))]
[Trait(
"BusinessTests"
,
"FacilityTests"
)]
public
void
CreateUpdateFavoriteFacility_CreateUpdateFavorites(Guid employeeID, Guid favoriteFacilityID)
{
//arrange
var context = Mock.Create<jhaCommon>(Constructor.Mocked);
var api = Mock.Create<JHADirectoryServiceAPI>(context);
Mock.Arrange(() => api.CreateUpdateFavoriteFacility(Arg.AnyGuid, Arg.AnyGuid)).CallOriginal().MustBeCalled();
Mock.Arrange(() => Logger.LogError(Arg.IsAny<Exception>())).OccursNever();
Mock.Arrange(() => context.FavoriteTypes.Department()).Returns(() => FakeDataSource.FakeFavoriteTypes().Where(ft => ft.FavoriteType1.ToLower() ==
"department"
).FirstOrDefault());
Mock.Arrange(() => context.PhonelistFavorites).ReturnsCollection(FakeDataSource.FakePhoneListFavorites());
dynamic apiWrap = Mock.NonPublic.Wrap(api);
Mock.NonPublic.Arrange(apiWrap.CreateUpdateFavorite(ArgExpr.IsAny<Guid>(), ArgExpr.IsAny<Guid>(), ArgExpr.IsAny<FavoriteType>())).CallOriginal();
//act
var client =
new
JHADirectoryService(api);
client.CreateUpdateFavoriteFacility(employeeID, favoriteFacilityID);
//assert
Mock.Assert(api);
}
Here is my TestDataClass
public
static
class
FavoriteTestData
{
#region Private Members
private
static
List<
object
[]> _facilityFavorite =
new
List<
object
[]>
{
new
object
[] {
new
Guid(
"00000000-0000-0000-0000-000000000000"
) ,
new
Guid(
"00000000-0000-0000-0000-000000000000"
) },
new
object
[] {
new
Guid(
"11111111-1111-1111-1111-111111111111"
) ,
new
Guid(
"11111111-1111-1111-1111-111111111111"
) }
};
#endregion
#region Public Properties
public
static
IEnumerable<
object
[]> FacilityFavorite
{
get
{
return
_facilityFavorite; }
}
#endregion
}
Here is my code in my client class. This is the entry point of my test:
public
void
CreateUpdateFavoriteFacility(Guid employeeID, Guid favoriteEmployeeID)
{
try
{
_api.CreateUpdateFavoriteFacility(employeeID, favoriteEmployeeID);
}
catch
(Exception ex)
{
Logger.LogError(ex);
}
}
Here is my "api" Code:
public
void
CreateUpdateFavoriteFacility(Guid employeeID, Guid favoriteFacilityID)
{
CreateUpdateFavorite(employeeID, favoriteFacilityID, _context.FavoriteTypes.Department());
}
private
void
CreateUpdateFavorite(Guid employeeID, Guid favoriteObjectID, FavoriteType type)
{
//do stuff
}
I'm unable to find the ReturnsCollection in Telerik Just Mock. Here is the line that is giving me issues. I've got the following using statements, but the Telerik.JustMock.Helpers shows it isn't used.
The version of JustMock is v2016.2.421.1
using
Telerik.JustMock;
using
Telerik.JustMock.Helpers;
Mock.Arrange(() => fakeContext.Employees).ReturnsCollection(FakeDataSource.FakeEmployees());
The"fakeContext" is defined as such
public
class
jhaCommonMock : DbContext
{
public
DbSet<EmployeeDTO> Employees {
get
;
set
; }
public
DbSet<DepartmentDto> Departments {
get
;
set
; }
}
Here is a sample of my FakeDataSource
public
static
class
FakeDataSource
{
public
static
IList<EmployeeDTO> FakeEmployees()
{
List<EmployeeDTO> fakeEmpList =
new
List<EmployeeDTO>
{
new
EmployeeDTO
{
FirstName=
"Test"
,
LastName =
"Employee"
,
NetworkID =
"testEmployee"
,
Inactive =
false
}
};
return
fakeEmpList;
}
}
}
I'm unable to get JustMock working with NUnit and OpenCover. JustMock works just fine without OpenCover in the mix, and OpenCover works fine without a JustMock test involved.
I'm explicitly setting all the environment variables
JUSTMOCK_INSTANCE=1
COR_ENABLE_PROFILING=1
COR_PROFILER={B7ABE522-A68F-44F2-925B-81E7488E9EC0}
And invoking OpenCover as a Batch Command
c:\tools\OpenCover\OpenCover.Console.exe -target:"C:\tools\NUnit\nunit-console\nunit3-console.exe" -targetargs:"%WORKSPACE%\Dev\Source\<
snipped
>.dll --result:Results.xml;format=nunit2" -filter:"+[*]* -[*.Tests]*" -register:user -output:Coverage.xml -hideskipped:All -skipautoprops
Both OpenCover and JustMock are installed. The OpenCover dlls are registered and linked to JustMock (see attached screenshot). There is one unit test that uses JustMock to mock System.DateTimeOffset
I get the following when I try to run the setup.
Executing: C:\tools\NUnit\nunit-console\nunit3-console.exe
NUnit Console Runner 3.2.1
Copyright (C) 2016 Charlie Poole
Runtime Environment
OS Version: Microsoft Windows NT 6.1.7601 Service Pack 1
CLR Version: 4.0.30319.42000
Test Files
c:\workspace\Tests\bin\Debug\Tests.dll
Errors and Failures
1) Error : Tests.InitializesWithCurrentTime
Telerik.JustMock.Core.ElevatedMockingException : Cannot mock 'System.DateTimeOffset'. The profiler must be enabled to mock, arrange or execute the specified target.
Detected active third-party profilers:
* (from process environment)
Disable the profilers or link them from the JustMock configuration utility. Rest
art the test runner and, if necessary, Visual Studio after linking.
at Telerik.JustMock.Core.ProfilerInterceptor.ThrowElevatedMockingException(Me
mberInfo member)
at Telerik.JustMock.Core.MocksRepository.InterceptStatics(Type type, IEnumera
ble`1 mixins, IEnumerable`1 supplementaryBehaviors, IEnumerable`1 fallbackBehavi
ors, Boolean mockStaticConstructor)
at Telerik.JustMock.MockBuilder.InterceptStatics(MocksRepository repository,
Type type, Nullable`1 behavior, Boolean mockStaticConstructor)
at Telerik.JustMock.Core.MocksRepository.ConvertExpressionToCallPattern(Expre
ssion expr, CallPattern callPattern)
at Telerik.JustMock.Core.MocksRepository.Arrange[TMethodMock](Expression expr
, Func`1 methodMockFactory)
at Telerik.JustMock.Mock.<>c__DisplayClass8`1.<
Arrange
>b__6()
at Telerik.JustMock.Core.ProfilerInterceptor.GuardInternal[T](Func`1 guardedA
ction)
at Telerik.JustMock.Mock.Arrange[TResult](Expression`1 expression)
Versions
Hi,
We are using visual studio 2015 enterprise edition. We have selected JustMock ->Options -> Visual Studio 2015 Code Coverage\IntelliTrace option.
After running all unit test in my solution, I am not getting how to see code coverage result?
Could anyone please help on this?
Thanks,
Prasad
I have a method such as:
private bool DoAction(Type typeOfConsumer, params Object[] extraParams)
I want to assert it is called, where the public equivalent is:
Mock.Arrange(() => instanceOfClass.DoAction(Arg.IsAny<Type>()).MustBeCalled();
works for the call
instanceOfClass.DoAction(typeof(SomeType)); // No params, but does this matter?
and I would expect the non-public to be
Mock.NonPublic.Arrange(instanceOfClass, "DoAction", Arg.IsAny<Type>()).MustBeCalled();
but my (NUnit) exception is System.MissingMemberException : Method 'DoAction' with the given signature was not found on type...
It works with the public equivalent and
It does not work with the non-public whether the method is made protected or private.
I want to arrange and then assert that this method was called.