Upgrade to latest version causing exceptions

5 posts, 1 answers
  1. paullinville@hotmail.com
    paullinville@hotmail.com avatar
    6 posts
    Member since:
    Jun 2007

    Posted 17 Aug 2012 Link to this post

    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?
  2. Ricky
    Admin
    Ricky avatar
    467 posts

    Posted 22 Aug 2012 Link to this post

    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.

  3. DevCraft R3 2016 release webinar banner
  4. paullinville@hotmail.com
    paullinville@hotmail.com avatar
    6 posts
    Member since:
    Jun 2007

    Posted 22 Aug 2012 Link to this post

    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;
     
           }
       }
  5. paullinville@hotmail.com
    paullinville@hotmail.com avatar
    6 posts
    Member since:
    Jun 2007

    Posted 22 Aug 2012 Link to this post

    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
     
    }
  6. Answer
    Ricky
    Admin
    Ricky avatar
    467 posts

    Posted 24 Aug 2012 Link to this post

    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.

Back to Top
DevCraft R3 2016 release webinar banner