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

Mocks with Long and Int are treated as seperate Mocks.

1 Answer 11 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Joel
Top achievements
Rank 1
Joel asked on 17 Jan 2012, 01:27 AM
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);
}


1 Answer, 1 is accepted

Sort by
0
Ricky
Telerik team
answered on 19 Jan 2012, 06:06 PM
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 >>

Tags
General Discussions
Asked by
Joel
Top achievements
Rank 1
Answers by
Ricky
Telerik team
Share this question
or