Getting Started

Welcome to True Fakes documentation!

This documentation is aimed at the rapid True Fakes mocking framework learning and includes all the necessary steps for a quick start working with True Fakes.

True Fakes stands out from its alternatives. While other mocking frameworks generate fake-objects at runtime, True Fakes generates it at compile time and add it to assembly where unit-tests are. This allows you to use True Fakes for writing unit tests with fully isolated system under test for Xamarin.Android and Xamarin.iOS and running them directly on the device!

You can see more information about True Fakes features on the http://truefakes.net.

True Fakes comes as NuGet-package which you can find here. Simply add it to your project by using standard tools provided by your working IDE (Visual Studio or Xamarin Studio).

NOTE: Starting from True Fakes 1.0.297 we simplified True Fakes setting up process and there is only NuGet-package needed to start working with. So if you have used True Fakes before, please uninstall it and make sure that your IDE has no True Fakes extension. If you have any question please feel free to email us to support@truefakes.net.


License Activation

Authorization Page

To start using True Fakes you need to authorize. If you have any test with True Fakes you can see the following authorization window during building your solution:

Authorization Page

Enter your login and password to go to the license activation page. If you have not registered yet, you can do it here.

Activate License Page

Activate License Page

In this page, you need to attach your workspace to any license. To do so, select the appropriate license from the list. If you have not purchased a license, you can use the full-featured True Fakes 14-days trial version for free.

After a successful workspace activation, you can see the general information about your license attached:

View License Page

You can always attach another license in the current workspace. To do so, run the TrueFakes.exe, which located in {SolutionPath}/packages/TrueFakes.{Version}/. Here you can reauthorize or change your active license.


Let’s start True Fakes features overview with a description of the interface that will be used in the following examples. Suppose that we develop a simple vector graphics editor. Lets define the IShape interface that represents the geometric shape:

/// <summary>
/// Represents a shape which can be drawn in canvas.
/// </summary>
public interface IShape
{
    /// <summary>
    /// Shape name.
    /// </summary>
    string Name { get; set; }

    /// <summary>
    /// Draw shape.
    /// </summary>
    void Draw();

    /// <summary>
    /// Get shape dimensions.
    /// </summary>
    /// <param name="width">Dimension width.</param>
    /// <param name="height">Dimension height.</param>
    void GetDims(out int width, out int height);

    /// <summary>
    /// Get shape contour thickness.
    /// </summary>
    /// <returns>Shape contour thickness.</returns>
    int GetThickness();

    /// <summary>
    /// Check if this shape can select.
    /// </summary>
    /// <param name="xPosition">X position of test point to check.</param>
    /// <param name="yPosition">Y position of test point to check.</param>
    /// <returns>Returns true if this shape can select.</returns>
    bool CanSelect(int xPosition, int yPosition);

    /// <summary>
    /// Clarify shape center using initial position.
    /// </summary>
    /// <param name="xPosition">Initial and clarified X position.</param>
    /// <param name="yPosition">Initial and clarified Y position.</param>
    void ClarifyCenter(ref int xPosition, ref int yPosition);

    /// <summary>
    /// Occurs when shape is drawing.
    /// </summary>
    event EventHandler<DrawEventArgs> Drawing;

    /// <summary>
    /// Occurs after shape has drawed.
    /// </summary>
    event EventHandler Drawed;
}

When writing unit tests often necessary to isolate test class (system under test) from all its dependencies. For this there are special stub classes (fake-classes), simulating the expected behavior. In the following sections we will look at the syntax and capabilities to work with fake-class generated for the IShape interface.