This is a migrated thread and some comments may be shown as answers.

Assert, Args.Ignore and Occurs.Never()

4 Answers 219 Views
JustMock Free Edition
This is a migrated thread and some comments may be shown as answers.
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.

// 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

Sort by
0
Kaloyan
Telerik team
answered on 28 Nov 2013, 12:42 PM
Hi Isaac,

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
Share what you think about JustTrace & JustMock with us, so we can become even better! You can use the built-in feedback tool inside JustTrace, our forums, or our JustTrace or JustMock portals.
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.
0
Isaac Abraham
Top achievements
Rank 1
answered on 10 Dec 2013, 03:19 PM
I've repro'd it now: -

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: -

  1. Change the return type of Foo to void.
  2. Removing the Occurs.Once() condition.
  3. Passing in 123 instead of new object()).
0
Kaloyan
Telerik team
answered on 11 Dec 2013, 10:12 AM
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
Share what you think about JustTrace & JustMock with us, so we can become even better! You can use the built-in feedback tool inside JustTrace, our forums, or our JustTrace or JustMock portals.
Tags
JustMock Free Edition
Asked by
Isaac Abraham
Top achievements
Rank 1
Answers by
Kaloyan
Telerik team
Isaac Abraham
Top achievements
Rank 1
Share this question
or