common property value not being applied to base interfaces

3 posts, 0 answers
  1. Sainath
    Sainath avatar
    2 posts
    Member since:
    May 2017

    Posted 24 May 2017 Link to this post

    Hi,

     

    I have 2 interfaces (I1 and I2) that have a property called FileName. Another interface is inheriting these two interfaces. Let us call it I3.In I3, I am using new modifier (this is C#) so that in my code I do not get FileName property displayed twice and prevent compiler ambiguity errors.

    When I mock interface I3 and set the FileName value, this value does not propagate to interfaces I1 and I2. This is not an issue in my actual code. 

    I have attached a sample pictures of the code. The first assert works. Second and third fail.

    Assert.IsTrue(toTest.FileName == @"test file name", "FileName missing"); //1
    Assert.IsTrue((toTest as Interface1).FileName== @"test file name","FileName missing"); //2
    Assert.IsTrue((toTest as Interface2).FileName == @"test file name", "FileName missing"); //3

    Am I doing something wrong OR is this a bug with the lite version of JustMock?

    Thank you for time taken to read and any direction to resolve my challenge.

    Sainath

     

  2. Kamen Ivanov
    Admin
    Kamen Ivanov avatar
    80 posts

    Posted 29 May 2017 Link to this post

    Hi Sainath,

    Thank you for your interest in JustMock.

    The behavior that you experience is expected because mocked instances act differently from the real instances.

    JustMock creates a proxy object of the type that you are mocking and then uses the specified expressions to substitute them with the mocked behavior. In your case only thing that is mocked is calling FileName from the created proxy that's why it could only substitute it with the mocked value. The other two expressions "(toTest as Interface1).FileName" and "(toTest as Interface2).FileName" are obscure and cannot be substituted.
    Adding them to the mock object will fix the failing test.
    Mock.Arrange(() => (toTest as Interface1).FileName).Returns("test file name");
    Mock.Arrange(() => (toTest as Interface2).FileName).Returns("test file name");

    Regards,
    Kamen Ivanov
    Progress Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. Sainath
    Sainath avatar
    2 posts
    Member since:
    May 2017

    Posted 31 May 2017 Link to this post

    Thank you for the clarification Kamen. What you suggested did work out. 
Back to Top