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));
}
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()
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);
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);
}
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