Telerik Forums
JustMock Forum
1 answer
153 views
I'm using Visual Studio 2013 MSTest
JustMock Lite 2014.2.609.3 (via NuGet)

I'm trying to move the "MustBeCalled" expectations to TestCleanup.
Here is an example of code.

01.[TestClass]
02.public class TestFixture
03.{
04.  private ICloneable _svc;
05. 
06.  [TestInitialize]
07.  public void TestSetup() { _svc = Mock.Create<ICloneable>(); }
08. 
09.  [TestCleanup]
10.  public void TestCleanup() { Mock.Assert(_svc); }
11. 
12.  [TestMethod]
13.  public void TryStuff()
14.  {
15.    // arrange
16.    _svc = Mock.Create<ICloneable>();
17.    Mock.Arrange(()=> _svc.Clone()).MustBeCalled();
18. 
19.    // act
20.    //_svc.Clone();
21. 
22.    // assert
23.  }
24.}

If I run the code as is, the test will pass (regardless if line 20 is commented or not).

This can be fixed by moving the Mock.Assert to line 22+ but ideally I would like to "auto call" Mock.Assert at the end of every test.  I thought that adding it to TestCleanup would work but it doesn't appear to do so.

It appears that prior to TestCleanup running, JustMock will clear out the expectations prior to running TestCleanup.
Is there anyway around this?

Why am I doing this?
Because I'd actually like to write tests like this.

01.public class TestFixture
02.{
03.  private List<object> _assertList = new List<object>();
04. 
05.  [TestCleanup]
06.  public void TestCleanup() { foreach (var svc in _assertList) { Mock.Assert(svc); } }
07.   
08.  private void CloneableMustBeCalled()
09.  {
10.    Mock.Arrange(() => _svc.Clone()).MustBeCalled();
11.    if (!_assertList.Contains(_svc)) { _assertList.Add(_svc); }
12.  }
13.}

Of course my actual test classes will be more complex. But this approach allows me to Mock out MustBeCalled expectations in a more readable manner.  Currently, the test author will have to remember to call Assert the _svc class (or _assertList) at the end of every TestMethod, but was hoping for a more maintainable solution.

Thanks
Stefan
Telerik team
 answered on 10 Jul 2014
3 answers
3.0K+ views
If this has been answered already you can just direct me there...

In the method i am working on I am trying to mock a "checkpoint".

the line of code is this....    if (File.Exists(filePath)){
rest of code is here
}
I need to mock this so the program just moves on regardless of if there is a file there or not.

Any suggestions?
Matthew
Top achievements
Rank 1
 answered on 10 Jul 2014
3 answers
157 views
Hi, i bought justmock, and reading JustMock  documents  i dont find how to mock web 
services, i need create a mock web services(Request,response etc..) anybody have a example?
Kaloyan
Telerik team
 answered on 10 Jul 2014
4 answers
120 views
In some of my unit tests I run the "unhappy path" to show a failure result as another test. My question is when using a fluent Assert such as:

        [TestMethod]
        public void U05WILLFAILShouldOccursNever()
        {
            var alpha = Mock.Create<IStingPatrol>();

            alpha.Submit();

            Mock.Assert(() => alpha.Submit(), Occurs.Never());
            
        }

how do I pass this failure? I know it will fail, that is the purpose of this. but how do I make it so it does not come up as a failure when I run my tests? 
Kaloyan
Telerik team
 answered on 07 Jul 2014
3 answers
149 views
Using VS 2012 update 4 w/ the latest version of JustMock (verified in the Telerik Control Panel).

I have the following lines in my test:

            jobLogEntries = new List<job_log>();
            jobLogEntries.Add(new job_log
            {
                job_log_ky = 27,
            });
            Mock.Arrange(() => this.Entities.job_log).IgnoreInstance().ReturnsCollection(jobLogEntries);

I have the following lines inside the code being tested:
                jobLog = new job_log
                {
                    job_schedule_ky = this.JobScheduleRecord.job_schedule_ky,
                    job_name = this.JobScheduleRecord.job_name,
                    start_dt_tm = DateTime.Now,
                };
                ctx.job_log.Add(jobLog);

During debugging I can see the job_log record that was added into the collection by the test, however the jobLog entity is not being added to the collection, causing the overall test to fail.

Stefan
Telerik team
 answered on 02 Jul 2014
2 answers
172 views
When I try to use a mock to mock a nonpublic I get a ElevatedMockingException. I believe it is because I do not have the elevated mode on, How do I do that?
Kaloyan
Telerik team
 answered on 30 Jun 2014
1 answer
111 views
Hi Everyone,

From this link http://www.telerik.com/help/justmock/advanced-usage-private-accessor.html I understood that we can call private methods and properties but by using JustMock. Can I give some value to private variable in class
Example:
Class JustMock
{
       private string name="Testing"
       Private string ReturnSomeValue()
        {
            return name;
         }

}

Here my question is can I assign my own value to name variable with JustMock

Regards,
Rajendar.



Kaloyan
Telerik team
 answered on 26 Jun 2014
7 answers
162 views
Hello,

when a test with a nonPublic mock fails, following gets written to the stacktrace of the .trx file:

01.<Message>Test method test threw exception:
02.System.ArgumentException: Method 'test' not found on type test</Message>
03.          <StackTrace>    at Telerik.JustMock.Expectations.NonPublicExpectation.™(Type ‹, Type ‘, String , Object[] €)
04.   at Telerik.JustMock.Expectations.NonPublicExpectation..›()
05.   at “•.’•.Š•[–](Func`1 ‹•)
06.   at Telerik.JustMock.Expectations.NonPublicExpectation.Arrange[TReturn](Object target, String memberName, Object[] args)
07.   at Common.Test.MockData`1.NonPublicMockData.Arrange[TReturn](String memberName, String exprName, Object[] args) in c:\jenkins\workspace\Tests\Mock\MockData.cs:line 167
08....
09....
10.truncated here
11.</StackTrace>


the &#x characters let the build fail, because they cannot be transformed.

see:
01.Processing tests results in file(s) Test\TestResults\testResults.trx
02. Test\TestResults\testResults.trx
03.ERROR: Publisher hudson.plugins.mstest.MSTestPublisher aborted due to exception
04.java.io.IOException: remote file operation failed: c:\jenkins\workspace\Build - Tests at hudson.remoting.Channel@69bf0fd8:build3
05.    at hudson.FilePath.act(FilePath.java:916)
06.    at hudson.FilePath.act(FilePath.java:893)
07.    at hudson.plugins.mstest.MSTestPublisher.perform(MSTestPublisher.java:73)
08.    at hudson.tasks.BuildStepMonitor$1.perform(BuildStepMonitor.java:20)
09.    at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:745)
10.    at hudson.model.AbstractBuild$AbstractBuildExecution.performAllBuildSteps(AbstractBuild.java:709)
11.    at hudson.model.Build$BuildExecution.post2(Build.java:182)
12.    at hudson.model.AbstractBuild$AbstractBuildExecution.post(AbstractBuild.java:658)
13.    at hudson.model.Run.execute(Run.java:1735)
14.    at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
15.    at hudson.model.ResourceController.execute(ResourceController.java:88)
16.    at hudson.model.Executor.run(Executor.java:231)
17.Caused by: hudson.util.IOException2: Could not transform the MSTest report. Please report this issue to the plugin author
18.    at hudson.plugins.mstest.MSTestTransformer.invoke(MSTestTransformer.java:66)
19.    at hudson.plugins.mstest.MSTestTransformer.invoke(MSTestTransformer.java:28)
20.    at hudson.FilePath$FileCallableWrapper.call(FilePath.java:2474)
21.    at hudson.remoting.UserRequest.perform(UserRequest.java:118)
22.    at hudson.remoting.UserRequest.perform(UserRequest.java:48)
23.    at hudson.remoting.Request$2.run(Request.java:328)
24.    at hudson.remoting.InterceptingExecutorService$1.call(InterceptingExecutorService.java:72)
25.    at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
26.    at java.util.concurrent.FutureTask.run(Unknown Source)
27.    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
28.    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
29.    at hudson.remoting.Engine$1$1.run(Engine.java:63)
30.    at java.lang.Thread.run(Unknown Source)
31.Caused by: javax.xml.transform.TransformerException: javax.xml.transform.TransformerException: com.sun.org.apache.xml.internal.utils.WrappedRuntimeException: Character reference "&#
32.    at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(Unknown Source)
33.    at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(Unknown Source)
34.    at hudson.plugins.mstest.MSTestReportConverter.transform(MSTestReportConverter.java:63)
35.    at hudson.plugins.mstest.MSTestTransformer.invoke(MSTestTransformer.java:64)
36.    ... 12 more
37.Caused by: javax.xml.transform.TransformerException: com.sun.org.apache.xml.internal.utils.WrappedRuntimeException: Character reference "&#
38.    at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.getDOM(Unknown Source)
39.    ... 16 more
40.Caused by: com.sun.org.apache.xml.internal.utils.WrappedRuntimeException: Character reference "&#
41.    at com.sun.org.apache.xalan.internal.xsltc.dom.XSLTCDTMManager.getDTM(Unknown Source)
42.    at com.sun.org.apache.xalan.internal.xsltc.dom.XSLTCDTMManager.getDTM(Unknown Source)
43.    ... 17 more

already created an issue for the plugin author (https://issues.jenkins-ci.org/browse/JENKINS-23531)


Is there a way to prevent this errors or to change the encoding of justmocks exception messages?

kind regards
peter
Kaloyan
Telerik team
 answered on 26 Jun 2014
6 answers
369 views
I am stuck to mock Entity Framework 6 asynchronous methods using JustMock. I searched in Google a lot but did not get any sufficient result. At last I got an example a testing with async queries but it is used Moq.

I am try to convert this into JustMock but i can not find anything like .As<TInterface>() in JustMock. Please tell me what is equivalent of moq.As in JustMock ?

I already spend more than 1 week for it. Please response as soon as possible.
Thanks.  
 
Kaloyan
Telerik team
 answered on 25 Jun 2014
1 answer
119 views
Visual Studio 2013
Just Mock 2014.1.1623.1
NCrunch 2.7.0.5

Currently, NCrunch is running with the Just Mock Profiler as seen here: http://snag.gy/04kqj.jpg

The instructions found here (http://www.telerik.com/help/justmock/integration-ncrunch.html) state that in order to have this work I need to setup a "Proxy process file path" in NCrunch.  However, I currently do not have that set on any of my NCrunch projects, e.g., http://snag.gy/mPQCc.jpg

I would like to disable the Just Mock Profiler for some of my NCrunch projects but I am not sure how Just Mock Runner is being executed so I don't know what to change to make it stop executing using Just Mock Runner.

I am aware that I can programmatically disable the runner, but I am looking for a configuration based solution that doesn't require code changes to my tests.
Stefan
Telerik team
 answered on 20 Jun 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?