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

Issue with JustMock Ignoreinstance()

3 Answers 155 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Scott
Top achievements
Rank 1
Scott asked on 18 Jun 2012, 09:02 PM

I'm looking to see what is wrong with this code.  Looking at the samples it should work with the Telerik.JustMock.DLL referenced, but is throwing a build error instead:

using System;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Telerik.JustMock;

namespace JustMock_Example
{
    public class ClassUnderTest
    {
        public bool ReturnsFalse()
        {
            return false;
        }
    }

    [TestClass]
    public class IgnoreInstanceTest
    {
        [TestMethod]
        public void ExampleTest()
        {
            var fake = Mock.Create<ClassUnderTest>();
            Mock.Arrange(() => fake.ReturnsFalse()).Returns(true).IgnoreInstance();

            Assert.IsTrue(new ClassUnderTest().ReturnsFalse());
        }
    }
}

///Throws the following:
Error 1 'Telerik.JustMock.Expectations.Abstraction.IAssertable' does not contain a definition for 'IgnoreInstance' and no extension method 'IgnoreInstance' accepting a first argument of type 'Telerik.JustMock.Expectations.Abstraction.IAssertable' could be found (are you missing a using directive or an assembly reference?) c:\~\~\documents\visual studio 2010\Projects\JustMock Example\Class1.cs 23 67 JustMock Example

This is with the most recent build, and hopefully I'm missing something small.
Thanks!

3 Answers, 1 is accepted

Sort by
0
Ricky
Telerik team
answered on 20 Jun 2012, 03:21 PM
Hi Scott,

Thanks again for sharing the sample. It's the ordering of IgnoreInstance that should be corrected. I wrote the test in the following way and now it works as expected:


public class ClassUnderTest
{
    public bool ReturnsFalse()
    {
        return false;
    }
}
 
[TestClass]
public class IgnoreInstanceTest
{
    [TestMethod]
    public void ExampleTest()
    {
        var fake = Mock.Create<ClassUnderTest>();
        Mock.Arrange(() => fake.ReturnsFalse()).IgnoreInstance().Returns(true);
        Assert.IsTrue(new ClassUnderTest().ReturnsFalse());
    }
}

 

Kind Regards,
Ricky
the Telerik team

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

0
Scott
Top achievements
Rank 1
answered on 20 Jun 2012, 03:35 PM
Thanks for the reply Ricky.  The example I got the order of the call from is in the JustMock documentation in the following section: Advanced Usages -> Future Mocking


var fakeUsed = Mock.Create<UserData>();
Mock.Arrange(() => fakeUsed.ReturnFive()).Returns(7).IgnoreInstance();

Assert.AreEqual(7, fakeUsed.ReturnFive());
Assert.AreEqual(7, new UserData().ReturnFive());  


Did I find a bug in the documentation?  ;o)


Thanks again!
0
Ricky
Telerik team
answered on 21 Jun 2012, 05:20 PM
Hi Scott,

Thanks again for pointing the issue to us. I have already notified the team and changes will be applied to the documentation as early as possible.

I am also adding some points to your telerik account for reporting the same.

Kind Regards
Ricky
the Telerik team

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

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