Telerik Forums
JustMock Forum
3 answers
152 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
110 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
140 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
161 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
104 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
152 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
348 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
112 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
1 answer
444 views

So I'm trying to test out a function and it requires the use of a FindAsync function. i've boiled the code down to this example. When I run it, I get a NullReferenceExcetption from the FindAsync method. I believe that this is caused by an internal error in the arrangement of the MockSet.

[TestMethod()]
public async Task _ShipmentController_DetailsReturnsHttpNotFoundOnNullShipments()
{
    //Arrange
    var shipments = new List<ShipmentPlayer>
    {
        new ShipmentPlayer(){ShipmentID = 0},
    }.AsQueryable();
    var mockSet = createMockShipmentPlayerDB(shipments);
    var mockContext = Mock.Create<ExportAttempt4Entities>();
    Mock.Arrange(() => mockContext.ShipmentPlayersGroup).Returns(mockSet);
    //Act
    ShipmentPlayer query = await mockContext.FindAsync(0);
    //Assert
    Assert.IsNotNull(query);
 
}

Async set creation method:
private DbSet<ShipmentPlayer> createMockShipmentPlayerDB(IQueryable<ShipmentPlayer> chks)
{
    /*
     * This function is a helper to create ASync databases.
     * To modify this for your DB, change the Generics (<T>)
     * to your prefferend generic
     */
    var mockSet = Mock.Create<DbSet<ShipmentPlayer>>();
 
    Mock.Arrange(() => ((IDbAsyncEnumerable<ShipmentPlayer>)mockSet).GetAsyncEnumerator())
        .Returns(new TestDbAsyncEnumerator<ShipmentPlayer>(chks.GetEnumerator()));
 
    Mock.Arrange(() => ((IQueryable<ShipmentPlayer>)mockSet).Provider)
        .Returns(new TestDbAsyncQueryProvider<ShipmentPlayer>(chks.Provider));
 
    Mock.Arrange(() => ((IQueryable<ShipmentPlayer>)mockSet).Expression).Returns(chks.Expression);
    Mock.Arrange(() => ((IQueryable<ShipmentPlayer>)mockSet).ElementType).Returns(chks.ElementType);
    Mock.Arrange(() => ((IQueryable<ShipmentPlayer>)mockSet).GetEnumerator()).Returns(chks.GetEnumerator());
    return mockSet;
}

Async Database info:
internal class TestDbAsyncQueryProvider<TEntity> : IDbAsyncQueryProvider
    {
        private readonly IQueryProvider _inner;
 
        internal TestDbAsyncQueryProvider(IQueryProvider inner)
        {
            _inner = inner;
        }
 
        public IQueryable CreateQuery(Expression expression)
        {
            return new TestDbAsyncEnumerable<TEntity>(expression);
        }
 
        public IQueryable<TElement> CreateQuery<TElement>(Expression expression)
        {
            return new TestDbAsyncEnumerable<TElement>(expression);
        }
 
        public object Execute(Expression expression)
        {
            return _inner.Execute(expression);
        }
 
        public TResult Execute<TResult>(Expression expression)
        {
            return _inner.Execute<TResult>(expression);
        }
 
        public Task<object> ExecuteAsync(Expression expression, CancellationToken cancellationToken)
        {
            return Task.FromResult(Execute(expression));
        }
 
        public Task<TResult> ExecuteAsync<TResult>(Expression expression, CancellationToken cancellationToken)
        {
            return Task.FromResult(Execute<TResult>(expression));
        }
    }
 
    internal class TestDbAsyncEnumerable<T> : EnumerableQuery<T>, IDbAsyncEnumerable<T>, IQueryable<T>
    {
        public TestDbAsyncEnumerable(IEnumerable<T> enumerable)
            : base(enumerable)
        { }
 
        public TestDbAsyncEnumerable(Expression expression)
            : base(expression)
        { }
 
        public IDbAsyncEnumerator<T> GetAsyncEnumerator()
        {
            return new TestDbAsyncEnumerator<T>(this.AsEnumerable().GetEnumerator());
        }
 
        IDbAsyncEnumerator IDbAsyncEnumerable.GetAsyncEnumerator()
        {
            return GetAsyncEnumerator();
        }
 
        IQueryProvider IQueryable.Provider
        {
            get { return new TestDbAsyncQueryProvider<T>(this); }
        }
    }
 
    internal class TestDbAsyncEnumerator<T> : IDbAsyncEnumerator<T>
    {
        private readonly IEnumerator<T> _inner;
 
        public TestDbAsyncEnumerator(IEnumerator<T> inner)
        {
            _inner = inner;
        }
 
        public void Dispose()
        {
            _inner.Dispose();
        }
 
        public Task<bool> MoveNextAsync(CancellationToken cancellationToken)
        {
            return Task.FromResult(_inner.MoveNext());
        }
 
        public T Current
        {
            get { return _inner.Current; }
        }
 
        object IDbAsyncEnumerator.Current
        {
            get { return Current; }
        }
    }

I found a possible solution in the Moq framework but I can't really translate to Just Mock. The idea is that you would place the following block of code in the set creation function:
mockSet.Setup(t => t.FindAsync(It.IsAny<int>())).Returns(Task.FromResult(chks));

I've only been using Just Mock for a few days now, so it might just a be a fundamental issue that I'm missing.
Kaloyan
Telerik team
 answered on 12 Jun 2014
12 answers
261 views
Has there been any reported instability with JustMock installed with Visual Studio 2012 Ultimate Update 1 on WIndows 7 x64?  I have installed the evaluation version of JustMock on two separate installations of VS 2012 and continuously get IntelliTrace.exe errors, causing Visual Studio to lock up and become unusable.

Please advise of any workarounds.
Kaloyan
Telerik team
 answered on 09 Jun 2014
Narrow your results
Selected tags
Tags
+? more
Top users last month
Anislav
Top achievements
Rank 6
Silver
Bronze
Bronze
Jianxian
Top achievements
Rank 1
Iron
Marco
Top achievements
Rank 3
Iron
Iron
Iron
Jim
Top achievements
Rank 2
Iron
Iron
Nurik
Top achievements
Rank 2
Iron
Iron
Want to show your ninja superpower to fellow developers?
Top users last month
Anislav
Top achievements
Rank 6
Silver
Bronze
Bronze
Jianxian
Top achievements
Rank 1
Iron
Marco
Top achievements
Rank 3
Iron
Iron
Iron
Jim
Top achievements
Rank 2
Iron
Iron
Nurik
Top achievements
Rank 2
Iron
Iron
Want to show your ninja superpower to fellow developers?
Want to show your ninja superpower to fellow developers?