Telerik Forums
JustMock Forum
1 answer
129 views
Hello,

I have unit tests that are working fine locally in Visual Studio 2013, but when the build runs on TFS and attempts to run the Unit Tests it fails with the following:

Test method WingsServicesTests.Unit.LoanIntegrationServiceTests.AddressNeedsUpdating_GetSingleValueFromField threw exception:
Telerik.JustMock.Core.ElevatedMockingException: Cannot mock 'Boolean IsHostUp()'. The profiler must be enabled to mock, arrange or execute the specified target

I searched the forums and found referneces to this article: http://www.telerik.com/help/justmock/integration-msbuild-tasks.html

I was not sure where the items referenced in that article should be placed, so I put them in all 3 project files in the solution, including the test project, but it still doesn't work.I have set both "Perform Code Analysis" and "Analyze Test Impact" to false in the build definition, thinking that those might be the problem if they try to do code coverage.Any help would be appreciated.

Thanks,
Andrew

Kaloyan
Telerik team
 answered on 15 Jan 2015
1 answer
108 views
Hi All,

I am trying to write a Test method using NUnit and JustMock for Mocking.
Our application used Microsofy Identity

When I try to invoke the testmethod, I get an error saying WIF is enabled.

Can anyone please suggest how to bypass the Identity Framework using JustMock.
Kaloyan
Telerik team
 answered on 07 Jan 2015
4 answers
191 views
Hi,
I am trying to mock db access using JustMock. I do have an interface defined and created a mock object from the interface. I then arranged a method to return false for any argument. After arranging the mock object on the second call with unique arguments a null reference exception is thrown. The code snippet below shows what I am trying to do:

IDBAccess fakeDBAccess = Mock.Create<IDBAccess>();
List<ModelType1> fakeModelType1 = GetFakeModelModelType1();
Mock.Arrange(()=> fakeDBAccess.GetModelType1ForPrimaryKey(Arg.Is<long>(1))).Returns(fakeModelType1[0]);
Mock.Arrange(() => fakeDBAccess.GetModelType1ForPrimaryKey(Arg.Is<long>(2))).Returns(fakeModelType1[1]);
List<fakeModelType2> fakeModelType2 = new List<fakeModelType2>();
Mock.Arrange(() => fakeDBAccess.GetModelType2ForPrimaryKey(Arg.IsAny<long>())).Returns(fakeModelType2);
Mock.Arrange(() => fakeDBAccess.GetModelType1Status(Arg.IsAny<ModelType1>())).Returns(false);
ClassUnderTest OUT = new ClassUnderTest(fakeDBAccess );

On debugging the above code try to call fakeDBAccess.GetModelType1Status() with two different values say fakeModelType[0] and fakeModelType[1] (in the watch window) the first call succeeds and returns false but the second call fails with a null reference exception. The order of calls do not matter. It is always  the second call that throws the null reference exception. Can you please confirm whether this is a bug or not. If this is a bug can you please suggest a work around?
Freddy
Top achievements
Rank 1
 answered on 24 Dec 2014
1 answer
179 views
How to Test Protected Static method in Abstract Class using JustMock 
Stefan
Telerik team
 answered on 24 Dec 2014
1 answer
117 views
Trying to write tests for some legacy code and I have a question about mocking fields or other references inside a mock. In the code below, "Assert.IsNotNull(member.Rsa)" will fail because the mocked constructor of member hasn't created anything. Currently I've solved the problem by creating a separate mock and assigning to it, but is this really the best way to do this?
var testChallengeData = new ChallengeData();
testChallengeData.responseList = new Response[] {new Response(), new Response(), new Response()};
 
var member = Mock.Create<Member>(Constructor.Mocked);
var rsa = Mock.Create<Vendors.RSA>(Constructor.Mocked);
 
Mock.SetupStatic(typeof (Settings), StaticConstructor.Mocked);
Mock.Arrange(() => Settings.getBool(Arg.AnyString)).IgnoreInstance().Returns(false);
Mock.Arrange(() => Settings.getInt(Arg.AnyString)).IgnoreInstance().Returns(3);
 
Mock.Arrange(() => rsa.CurrUserStatus).IgnoreInstance().Returns(Vendors.AdaptiveAuthRef.UserStatus.UNVERIFIED).OccursOnce();
Mock.Arrange(() => rsa.HasChallengeQuestions).IgnoreInstance().Returns(true).OccursNever();
 
Mock.Arrange(() => member.challengeQuestions).IgnoreInstance().Returns(testChallengeData);
Mock.Arrange(() => member.hasChallengeQuestions).CallOriginal();
member.Rsa = rsa;
 
Assert.IsNotNull(member.Rsa);
Assert.IsTrue(member.hasChallengeQuestions);
rsa.Assert();
Mock.Assert(() => Settings.getBool(Arg.AnyString), Occurs.Once());

Stefan
Telerik team
 answered on 24 Dec 2014
1 answer
158 views
Hi All, We have a requirement where we have to use NUnit to write test methods and JustMock for mocking the application.
Our application is exposing WCF services and the unit tests will be written to test the WCF Operations. We are using VS 2013.In our application we are using Dependency injection while calling the Constructor i.e. the parameters to the Constuctor are created using Dependency injection. Please refer below sample
 
 public NetworkService(IDbContextFactory<NetworkDbContext> contextFactory, IEventBus eventBus, HostService hostService, UserManagementService userManagementService)
         {
             _contextFactory = contextFactory.ThrowIfNull("contextFactory");
             _eventBus = eventBus.ThrowIfNull("eventBus");
             _hostService = hostService.ThrowIfNull("hostService");
             _userManagementService = userManagementService.ThrowIfNull("userManagementService");
       } 

I tried mocking using Telerik Justmock to create the objects of ContextFactory, EventBus etc. but the object created using mocking was of type Proxy of actual object rather than the object itself i.e. Proxy of IEventBus rather than IEventBus.The _contextFactory object is used to create a context like below

 using (var ctx = _contextFactory.Create()) 

But as the object is of type Proxy(Object) I am unable to create the context ctx in above scenario. Hence the controls goes to the Service but
when it tries to use context object ctx, it throws an "Null Reference exception" and hence the testing fails. 

Can anyone please suggest if there is any issue with the above and suggest on alternate solution using NUnit and JustMock. 

Any help will be highly appreciated. Thanks in advance.
Stefan
Telerik team
 answered on 17 Dec 2014
1 answer
174 views
Hi All,We have a requirement where we have to use NUnit to write test methods and JustMock for mocking the application. Dep injOur application is exposing WCF services and the unit tests will be written to test the WCF Operations.We are using VS 2013.In our application we are using Dependency injection while calling the Constructor i.e. the parameters to the Constuctor are created

using Dependency injection.Pls refer below
public NetworkService(IDbContextFactory<NetworkDbContext> contextFactory, IEventBus eventBus, HostService hostService, UserManagementService userManagementService)
        {
            _contextFactory = contextFactory.ThrowIfNull("contextFactory");
            _eventBus = eventBus.ThrowIfNull("eventBus");
            _hostService = hostService.ThrowIfNull("hostService");
            _userManagementService = userManagementService.ThrowIfNull("userManagementService");
      }

I tried mocking using Telerik Justmock to create the objects of ContextFactory/EventBus etc but the object create using mocking was of type Proxy of actual object rather than the object itself i.e. Proxy of IEventBus rather than IEventBus.The issue with this is, the _contextFactory object is used to create a context like below
using (var ctx = _contextFactory.Create())

But as the object is of type Proxy(Object) I am unable to create the context ctx in above scenario and hence the testing fails.

Can anyone please help me with the mocking.

Any help will be highly appreciated.

Thanks in advance.
Stefan
Telerik team
 answered on 17 Dec 2014
1 answer
292 views
I am using CallMethod to call a private method and it works great, but I need to call a method that has some ref parameters, Is it possible to do that
Also i would like to compare the values in the ref after the method execution finishes, basically instead of returning one value method is manipulating multiple values and i need to Assert all of them

Thanks
vikas
Stefan
Telerik team
 answered on 27 Nov 2014
8 answers
209 views
I have enabled the code activity workflow in a TFS build that runs unit tests.  My understanding is that JustMockTestRunner uses MSTest.exe to execute them.  Is it possible to use VSTest.Console.exe instead?
Kaloyan
Telerik team
 answered on 29 Oct 2014
1 answer
86 views
I have a mocked class which has a bool property BoolProperty.
I have a class under test with a method under test which first sets BoolProperty to true, and then to false.
I wish to set up an arrangement which tests that these two calls are made in the correct order, which I have done as follows:

    mockedClass.ArrangeSet(x => x.BoolProperty = true).InSequence();
    mockedClass.ArrangeSet(x => x.BoolProperty = false).InSequence();

This passes the test fine. However, if I reverse the order:

    mockedClass.ArrangeSet(x => x.BoolProperty = false).InSequence();
    mockedClass.ArrangeSet(x => x.BoolProperty = true).InSequence();

this *also* passes.
Shouldn't this second arrangement cause the test to fail?

I am using JustMock 2014.1.1424.1
Dave
Top achievements
Rank 1
 answered on 02 Oct 2014
Narrow your results
Selected tags
Tags
+? more
Top users last month
Rob
Top achievements
Rank 3
Iron
Iron
Iron
Atul
Top achievements
Rank 1
Iron
Iron
Iron
Alexander
Top achievements
Rank 1
Veteran
Iron
Serkan
Top achievements
Rank 1
Iron
Shawn
Top achievements
Rank 1
Iron
Iron
Want to show your ninja superpower to fellow developers?
Top users last month
Rob
Top achievements
Rank 3
Iron
Iron
Iron
Atul
Top achievements
Rank 1
Iron
Iron
Iron
Alexander
Top achievements
Rank 1
Veteran
Iron
Serkan
Top achievements
Rank 1
Iron
Shawn
Top achievements
Rank 1
Iron
Iron
Want to show your ninja superpower to fellow developers?
Want to show your ninja superpower to fellow developers?