Skip to content
This repository was archived by the owner on Jul 19, 2024. It is now read-only.

Releases: microsoft/SimpleStubs

Generics bug fix - support for call count - Descriptive error messages

18 Aug 22:53

Choose a tag to compare

  • Fixed a bug related to stubbing a generic method for different generic types simultaneously. SimpleStubs was using nameof(Foo<T>) to generate a unique key but nameof ignores generic arguments. We replaced nameof(Foo<T>) with typeof(Foo<T>).ToString() which fixes the problem.
  • Added more descriptive error messages for cases when stubs are not setup correctly to help users find out the problem quickly.
  • Added support for call count setup. To keep backward compatibility, call count is an optional parameter. Examples:
// For one call; an exception will be thrown if more calls occur
var stub = new StubIPhoneBook().GetContactPhoneNumber((firstName, lastName) => 6041234567, Times.Once);

or

// For a specific number of calls
var stub = new StubIPhoneBook().GetContactPhoneNumber((firstName, lastName) => 6041234567, count:5);
  • Simplified the Api for setting up a sequence of calls

Old Api (still supported):

// Define the sequence first
var sequence = StubsUtils.Sequence<Func<string, string, int>>()
    .Once((p1, p2) => { throw new Exception(); }) // first call will throw an exception
    .Repeat((p1, p2) => 11122233, 3) // next three calls will return 11122233
    .Forever((p1, p2) => 22233556); // any subsequent call will return 22233556

var stub = new StubIPhoneBook().GetContactPhoneNumber((p1, p2) => sequence.Next(p1, p2));

New Api:

var stub = new StubIPhoneBook()
    .GetContactPhoneNumber((p1, p2) => 12345678, Times.Once) // first call
    .GetContactPhoneNumber((p1, p2) => 11122233, Times.Twice) // next two calls
    .GetContactPhoneNumber((p1, p2) => 22233556, Times.Forever); // rest of the calls

Add support for generic constraints

19 Jul 20:20

Choose a tag to compare

Generic constraints are now supported on interfaces and methods.

Support for generic methods and Ref/Out parameters

14 Jul 22:46

Choose a tag to compare

  • Generic methods are now supported.
  • Ref and Out parameters are now supported.
  • The new stubbing Api is simpler and more readable:

Old Api:

var stub = new StubIPhoneBook
{
    GetContactPhoneNumber_String_String = (fn, ln) =>
    {
        return 6041234567;
    }
};

New Api:

var stub = new StubIPhoneBook().GetContactPhoneNumber((fn, ln) => 6041234567);