Isaac Abraham
Top achievements
Rank 1
Isaac Abraham
asked on 28 Nov 2013, 11:47 AM
An assertion on a mock where you use Args.Ignore() seems to ignore the extra "Occurs.Never()" condition i.e.
If you remove the Args.Ignore() and explicitly specify the arguments, Occurs.Never() starts to actually be evaluated.
// Both of these pass
Mock.Assert(() => mock.Foo(
null
,
null
), Args.Ignore(), Occurs.Never());
Mock.Assert(() => mock.Foo(
null
,
null
), Args.Ignore());
If you remove the Args.Ignore() and explicitly specify the arguments, Occurs.Never() starts to actually be evaluated.
4 Answers, 1 is accepted
0
Hi Isaac,
I was not able to reproduce this on my side. I wrote the following test, which fails as expected:
Can you provide a sample of the failing scenario?
Thanks in advance.
Regards,
Kaloyan
Telerik
I was not able to reproduce this on my side. I wrote the following test, which fails as expected:
public
class
Bar
{
public
virtual
void
Foo(
string
str1,
string
str2)
{
}
}
[TestMethod]
public
void
TestMethod1()
{
var mock = Mock.Create<Bar>();
mock.Foo(
"t"
,
"v"
);
Mock.Assert(() => mock.Foo(
null
,
null
), Args.Ignore(), Occurs.Never());
}
Can you provide a sample of the failing scenario?
Thanks in advance.
Regards,
Kaloyan
Telerik
0
Isaac Abraham
Top achievements
Rank 1
answered on 28 Nov 2013, 01:22 PM
Hiya
Bizarre - I restarted VS2013 and could not reproduce the problem.
Apologies - please close this ticket.
Bizarre - I restarted VS2013 and could not reproduce the problem.
Apologies - please close this ticket.
0
Isaac Abraham
Top achievements
Rank 1
answered on 10 Dec 2013, 03:19 PM
I've repro'd it now: -
You can get the test to pass by doing any of three things: -
public
class
TestClass
{
[Fact]
public
void
TestMethod()
{
var thing = Mock.Create<IMyInterface>();
thing.Foo(123);
Mock.Assert(() => thing.Foo(
new
object
()), Args.Ignore(), Occurs.Once());
}
}
public
interface
IMyInterface
{
int
Foo(
object
stuff);
}
You can get the test to pass by doing any of three things: -
- Change the return type of Foo to void.
- Removing the Occurs.Once() condition.
- Passing in 123 instead of new object()).
0
Hi Isaac,
Thank you for the sample. It reproduces on our side too.
I have added the bug in our backlog in order to be fixed in the near future.
P.S. For reporting a bug I have granted you some Telerik points.
Regards,
Kaloyan
Telerik
Thank you for the sample. It reproduces on our side too.
I have added the bug in our backlog in order to be fixed in the near future.
P.S. For reporting a bug I have granted you some Telerik points.
Regards,
Kaloyan
Telerik