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

Upgrade to latest version causing exceptions

4 Answers 88 Views
JustMock Free Edition
This is a migrated thread and some comments may be shown as answers.
paullinville@hotmail.com
Top achievements
Rank 1
paullinville@hotmail.com asked on 17 Aug 2012, 08:11 PM
I am mocking interface IRule and set it up as follows

public static IRule MakeMockRule(string description, string rulename, string propname, RuleSeverity severity, bool isbroke)
    {
        IRule mockRule = Mock.Create<IRule>();
        Mock.Arrange(() => mockRule.PropertyName).Returns(propname);
        Mock.Arrange(() => mockRule.RuleName).Returns(rulename);
        Mock.Arrange(() => mockRule.Severity).Returns(severity);
        Mock.Arrange(() => mockRule.IsBroken).Returns(isbroke);
        Mock.Arrange(() => mockRule.HandlesProperty(propname)).Returns(true);
        Mock.Arrange(() => mockRule.Description).Returns(description);
        return mockRule;
    }
And using version  2011.2.713.2 all tests using the above works.

I just upgraded to version 2012.2.813.9 and now when I call a method that uses the mocks .Equals method (for example List.Contains(rule)) it throws the following exception.

Test method Baseclass_Tests.BusinessRules_Test.IsBroken_Test threw exception: 
Telerik.JustMock.MockException: Could not call base for abstract Equals. Either remove the Behavior.CallOriginal specifier or add a setup for the expected call.

What do I need to do?

4 Answers, 1 is accepted

Sort by
0
Ricky
Telerik team
answered on 22 Aug 2012, 05:15 PM
Hi Paul,
Thanks again for contacting us. In order to reproduce the issue I wrote the following test , however it is working as expected:


IRule mockRules = Mock.Create<IRule>();
 
IList<IRule> rules = new List<IRule>();
 
rules.Add(mockRules);
 
Assert.IsTrue(rules.Contains(mockRules));

Is there something else that I am missing in here? Please also send me a sample project (if possible) so that I can quickly address the issue in that regard.


Kind Regards
Mehfuz
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
paullinville@hotmail.com
Top achievements
Rank 1
answered on 22 Aug 2012, 06:53 PM
I have a solution that shows the failure but I cannot submit those files.

But here is the raw code. If you need the project just let me know and I can email it.


Public Interface IRule
    Property AllowedValue() As Object
    Function Equals(ByVal obj As Object) As Boolean
    Function HandlesProperty(ByVal propName As String) As Boolean
    Property RuleName() As String
    Property PropertyValue() As Object
    Property Description() As String
    Property DescriptionVerbose() As String
    Property ShortDescription() As String
    Property PropertyName() As String
    Property IsBroken() As Boolean
    Property Severity() As RuleSeverity
    Property BusinessObject As IRuledItem
End Interface
 
Public Interface IRuledItem
    Inherits IBusinessData
    Sub AddBrokenRule(ByVal rule As IRule)
    Sub AddDeleteBrokenRule(ByVal rule As IRule)
    ReadOnly Property BrokenRuleList() As IEnumerable(Of IRule)
    ReadOnly Property BrokenRulesString() As String
    ReadOnly Property IsValid() As Boolean
    Sub AddRule(rule As IRule)
    Function RuleList(IncludeDeleteRules As Boolean) As IEnumerable(Of IRule)
End Interface
 
Public Enum RuleSeverity
    Critical = 0
    Warning = 1
    Information = 2
End Enum
 
Public Interface IBusinessData
    Inherits IIdentifiable
    ReadOnly Property Editable As Boolean
    Sub SetPropertyValue(PropertyName As String, setTo As Object)
    Function PropertyNames() As IEnumerable(Of String)
    Function PropertyValue(ByVal PropertyName As String) As Object
End Interface
 
Public Interface IIdentifiable
    ReadOnly Property BOID() As Guid
    Function FriendlyName() As String
    ReadOnly Property IsNull() As Boolean
End Interface


[TestClass]
   public class DemoTestFail
   {
       private TestContext testContextInstance;
 
       /// <summary>
       ///Gets or sets the test context which provides
       ///information about and functionality for the current test run.
       ///</summary>
       public TestContext TestContext
       {
           get
           {
               return testContextInstance;
           }
           set
           {
               testContextInstance = value;
           }
       }
 
 
       [TestMethod]
       public void RuleListTest()
       {
           IRule mockRule1 = MakeMockRule("desc", "name", "prop", RuleSeverity.Critical, true);
           IRule mockRule2 = MakeMockRule("desc2", "name2", "prop", RuleSeverity.Critical, false);
 
           List<IRule> ruleList = new List<IRule>();
 
           Assert.IsFalse(ruleList.Contains(mockRule1));
           Assert.IsFalse(ruleList.Contains(mockRule2));
           ruleList.Add(mockRule1);
 
           Assert.IsTrue(ruleList.Contains(mockRule1)); //Fails
           Assert.IsFalse(ruleList.Contains(mockRule2));
 
           ruleList.Add(mockRule2);
 
           Assert.IsTrue(ruleList.Contains(mockRule1));
           Assert.IsTrue(ruleList.Contains(mockRule2));
 
       }
 
       public static IRule MakeMockRule(string description, string rulename, string propname, RuleSeverity severity, bool isbroke)
       {
 
           IRule mockRule = Mock.Create<IRule>();
           Mock.Arrange(() => mockRule.PropertyName).Returns(propname);
           Mock.Arrange(() => mockRule.RuleName).Returns(rulename);
           Mock.Arrange(() => mockRule.Severity).Returns(severity);
           Mock.Arrange(() => mockRule.IsBroken).Returns(isbroke);
           Mock.Arrange(() => mockRule.HandlesProperty(propname)).Returns(true);
           Mock.Arrange(() => mockRule.Description).Returns(description);
           return mockRule;
 
       }
   }
0
paullinville@hotmail.com
Top achievements
Rank 1
answered on 22 Aug 2012, 08:39 PM

FYI The following Test also fails

[TestMethod]
public void RuleEqualsTest()
{
    IRule mockRule1 = MakeMockRule("desc", "name", "prop", RuleSeverity.Critical, true);
    IRule mockRule2 = MakeMockRule("desc2", "name2", "prop", RuleSeverity.Critical, false);
 
    Assert.IsFalse(mockRule1.Equals(mockRule2)); //Fails
 
}
0
Accepted
Ricky
Telerik team
answered on 24 Aug 2012, 08:45 PM
Hi Paul,

Thanks again for contacting us. 

I was able to reproduce the issue. In case you need the fix urgently, I would request you to create a support ticket where I will send you the latest build.


Kind Regards
Mehfuz
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Tags
JustMock Free Edition
Asked by
paullinville@hotmail.com
Top achievements
Rank 1
Answers by
Ricky
Telerik team
paullinville@hotmail.com
Top achievements
Rank 1
Share this question
or