Mocks with Long and Int are treated as seperate Mocks.

2 posts, 0 answers
  1. Joel
    Joel avatar
    19 posts
    Member since:
    Dec 2011

    Posted 16 Jan 2012 Link to this post

    I found an issue with Long's and Int's being treated as different objects in the Mocks.

    Here's my test class:

    public class MyClass
    {
        public long AddOne(long number)
        {
            return number + 1;
        }
    }

    Here's my test that fails:

    [TestMethod]
    public void MyClass_AddOne_mock_test_int()
    {
        // Arrange
        int number = 5;
        int expectedResult = 42;
     
        var myClass = Mock.Create<MyClass>();
     
        Mock.Arrange(() => myClass.AddOne(number))
            .Returns(expectedResult);
     
        // Act
        var result = myClass.AddOne(number);
     
        // Assert
        Assert.AreEqual(expectedResult, result); // result = 0
    }

    If I change "number" to a long the test passes.

    This also holds true for this:

    Mock.Assert(() => myClass.AddOne(number), Occurs.Once());


    My expectations were for int and long to produce the same result since they are "equal" and there is no way to actually pass a true int into that method.

    [TestMethod]
    public void Assert_int_vs_long()
    {
        int intNumber = 5;
        long longNumber = 5;
     
        Assert.AreEqual(intNumber, longNumber);
    }


  2. Ricky
    Admin
    Ricky avatar
    467 posts

    Posted 19 Jan 2012 Link to this post

    Hi Joel,

    Thanks again for reporting the issue. Yes you are right about it and expect a fix in the upcoming service pack release. However, I am also creating a task in PITS and you can further follow it here for progress:

    http://www.telerik.com/support/pits.aspx#/public/justmock/9420

    Kind Regards,
    Mehfuz
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  3. DevCraft R3 2016 release webinar banner
Back to Top