or
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
>
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
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 ?
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;
}
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; }
}
}
mockSet.Setup(t => t.FindAsync(It.IsAny<
int
>())).Returns(Task.FromResult(chks));