r2-2018-short-banner

Telerik JustMock

Release History

Q3 2010

November 10, 2010

Q3 2010 (version 2010.3.1109)

NEW
  • JustMock menu now resides under the root Telerik menu-item in Visual Studio
  • Support for Mock.Initialize() for setting up all framework methods during test initialization
    [TestFixtureSetUp]
    public void Initialize()
    {
    Mock.Initialize(typeof(Environment));
    }

    [TestMethod]
    public void ShouldMockMembersFromEnviroment()
    {
    string expected = "ping";
    Mock.Arrange(() => Environment.GetFolderPath(Arg.IsAny())).Returns(expected);
    Assert.Equal(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), expected);
    }

  • Ability to raise mocked event via Mock.Raise
    [TestMethod]
    public void ShouldRaiseEventWithCustomEventArgs()
    {
    var foo = Mock.Create();
    string expected = "ping";
    string acutal = string.Empty;

    foo.CustomEvent += delegate(string s)
    {
    acutal = s;
    };

    Mock.Raise(() => foo.CustomEvent += null, expected);
    Assert.Equal(expected, acutal);
    }

    Or using standard events:

    [TestMethod]
    public void ShouldRaiseEventWithStandardEventArgs()
    {
    var executor = Mock.Create>();
    string acutal = null;
    string expected = "ping";
    executor.Done += delegate(object sender, FooArgs args)
    {
    acutal = args.Value;
    };
    Mock.Raise(() => executor.Done+= null, new FooArgs(expected));
    Assert.Equal(expected, acutal);
    }

    More details can be found in EventsFixture.cs

  • Ability to set Occurrence during Mock.Arrange
    This enables you to specify how many times a mock-call should occur directly from arrange

    var foo = Mock.Create();
    Mock.Arrange(() => foo.Submit()).Occurs(2);
    Assert.Throws(() => Mock.Assert(foo));

    As shown this marks the call as required. Hence, it will fail during Mock.Assert if not properly expected
    Some of the other helpful constructs over Occurs()

    OccursOnce()
    OccursNever()
    OccursAtLeast()
    OccursAtMost()

    More examples can be found in PreOccurrenceFixture.cs

  • Ability to specify Occurrence during Mock.AssertSet
  • Ability to chain Returns call that works on a single value for InSequence alternative
    [TestMethod]
    public void ShouldBeAbleToSetMustBeCalledForChainReturn()
    {
    var foo = Mock.Create();
    Mock.Arrange(() => foo.Echo(Arg.AnyInt))
    .Returns(10)
    .Returns(11).MustBeCalled();
    Assert.Equal(10, foo.Echo(1));
    Assert.Equal(11, foo.Echo(2));
    Mock.Assert(foo);
    }

    This feature is enabled when Telerik.JustMock.Helpers namespace is included

  • Support assertion of multiple occurences for a single call in Mock.Assert using Arg.IsAny<T>()
    This enables you to assert multiple occurrences of similar type call using Matcher in Mock.Assert:
    [TestMethod]
    public void ShouldBeAbleToAssertOccursUsingMatcherForSimilarCallAtOneShot()
    {
    var foo = Mock.Create();
    Mock.Arrange(() => foo.Echo(1)).Returns((int arg) => arg);
    Mock.Arrange(() => foo.Echo(2)).Returns((int arg) => arg);
    Mock.Arrange(() => foo.Echo(3)).Returns((int arg) => arg);

    foo.Echo(1);
    foo.Echo(2);
    foo.Echo(3);

    Mock.Assert(() => foo.Echo(Arg.AnyInt), Occurs.Exactly(3));
    }

  • Ability to use matchers for params argument (Castle active record)
    User user = new User("test", "password");
    Mock.SetupStatic(Behavior.Strict);
    var criteria = Mock.Create();
    Mock.Arrange(() => User.FindOne(Arg.IsAny())).Returns(user);
    var result = User.FindOne(criteria);
    Assert.AreEqual(user.Username, result.Username);

    Here the signature of FindOne method looks like:
    public static T FindOne(params ICriterion[] criteria);

  • Should select the setup with the right matcher in case of Specialization, when a more specialized matcher is used along with Arg.IsAny<T> , it should select the proper setup with the right matcher

    var foo = Mock.Create();
    Mock.Arrange(() => foo.Echo(Arg.AnyInt)).Returns(10);
    Mock.Arrange(() => foo.Echo(Arg.Matches(x => x > 10)))
    .Throws(new ArgumentException());
    foo.Echo(1);
    Assert.Throws(() => foo.Echo(11));

  • Support of executing mocked method in the same test-method without necessarily having to pass the type as an argument

    [TestMethod]
    public void ShouldExecuteMockForSameInstanceInSameContext()
    {
    var foo = Mock.Create();
    Mock.Arrange(() => foo.Echo(Arg.AnyInt))
    .Returns((int arg1) => arg1);
    Assert.Equal(new Foo().Echo(10), 10);
    }

    Here an assert Echo is called on a new Foo instance. More Info on this task can be found at:
    http://www.telerik.com/community/forums/justmock/general-discussions/mscorlib-mocking-without-access-to-instance.aspx

  • Ability to mock LINQ queries with custom select
    var simple = new SimpleData();
    Mock.Arrange(() => simple.Products).ReturnsCollection(GetProductLists());
    var expected = (from p in simple.Products
    where p.UnitsInStock == 50
    select new { p.ProductID, p.ProductName }).SingleOrDefault();
    Assert.Equal(expected.ProductID, 2);

  • Support for byte[] for Arg.IsAny<>() argument and internal type mocking with InternalsVisibleToAttribute, when mocking is done via proxy
    [TestMethod]
    public void ShouldMockInternalTypeViaProxy()
    {
    // Provided that InternalsVisibleTo attribute is included in the assemblyinfo.cs.
    var foo = Mock.Create(Behavior.CallOriginal);
    Assert.NotNull(foo.Builder);
    }
    internal class FooInternal
    {
    internal FooInternal()
    {
    builder = new StringBuilder();
    }
    public StringBuilder Builder
    {
    get
    {
    return builder;
    }
    }
    private StringBuilder builder;
    }

    The key to be used in InternalsVisibleToAttribute:
    [assembly: InternalsVisibleTo("Telerik.JustMock,PublicKey=0024000004800000940000000602000000240000525341310004000001000100098b1434e598c6" + "56b22eb59000b0bf73310cb8488a6b63db1d35457f2f939f927414921a769821f371c31a8c1d4b" + "73f8e934e2a0769de4d874e0a517d3d7b9c36cd0ffcea2142f60974c6eb00801de4543ef7e93f7" + "9687b040d967bb6bd55ca093711b013967a096d524a9cadf94e3b748ebdae7947ea6de6622eabf" + "6548448e")]
FIXED
  • Tight integration-support of Telerik OpenAccess , Microsoft Sharepoint and Microsoft entity framework mocking

Telerik JustMock

Product overview Buy Try

New features & Roadmap

Have a feature request?

Post your feedback via the JustMock Feedback portal or the Public forums

What's new across all Telerik products?

See all updates

Next Steps

Download Free Trial

With dedicated technical support.

Check Pricing

Purchase individual products or any of the bundles