Assert, Args.Ignore and Occurs.Never()

5 posts, 0 answers
  1. Isaac Abraham
    Isaac Abraham avatar
    21 posts
    Member since:
    Sep 2009

    Posted 28 Nov 2013 Link to this post

    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.
  2. Kaloyan
    Admin
    Kaloyan avatar
    872 posts

    Posted 28 Nov 2013 Link to this post

    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.
  3. DevCraft R3 2016 release webinar banner
  4. Isaac Abraham
    Isaac Abraham avatar
    21 posts
    Member since:
    Sep 2009

    Posted 28 Nov 2013 Link to this post

    Hiya

    Bizarre - I restarted VS2013 and could not reproduce the problem.

    Apologies - please close this ticket.
  5. Isaac Abraham
    Isaac Abraham avatar
    21 posts
    Member since:
    Sep 2009

    Posted 10 Dec 2013 Link to this post

    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()).
  6. Kaloyan
    Admin
    Kaloyan avatar
    872 posts

    Posted 11 Dec 2013 Link to this post

    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.
Back to Top
DevCraft R3 2016 release webinar banner