Skip to content
Akira Sugiura edited this page Sep 7, 2014 · 22 revisions

Welcome to the Prig wiki!

QUICK TOUR

Please see README.md!

FEATURES

Calling Original Method

Depending on a test case, you may think that "I want to call original method, and verify only the passed value", or "I want to just call indirectly at nth time". Prig provides the feature to call original method easily. For details, please see this page!

Default Behavior

When you protect existing behavior via automated testing, tentatively you sometimes want to just check whether the method is called or not. For example, I think there is the scene as follows: "I want to detect the invocation of any methods of the class Environment, because I want to know that whether the target method accesses the information of current environment or platform." To achieve it, Prig supports the feature to modify the default behavior of their indirections. For more details, please check this page!

Generics

How do I hijack a generic type or a generic method? For details, please see this page!

Profilers Chain

The meaning of Profilers Chain is the feature that profilers are linked together and are run. You may think that "Are there any situation that links profilers together?". I believe it is yes. For details, please see this page!

COMBINATION OF OTHER FRAMEWORKS

Prig doesn't support the feature of traditional mocking frameworks, because I believe it can be done by just using them :)

Let me say the test for the following class:

using System;
using System.ComponentModel;
using System.Runtime.CompilerServices;

namespace TraditionalMockingFrameworkSample
{
    public class NotifyingObject : INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler PropertyChanged;

        int m_valueWithRandomAdded;
        public int ValueWithRandomAdded
        {
            get { return m_valueWithRandomAdded; }
            set
            {
                m_valueWithRandomAdded = value;
                m_valueWithRandomAdded += new Random((int)DateTime.Now.Ticks).Next();
                OnPropertyChanged();
            }
        }

        protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = "")
        {
            var handler = PropertyChanged;
            if (handler == null)
                return;

            handler(this, new PropertyChangedEventArgs(propertyName));
        }
    }
}

I think you probably want to test that "ValueWithRandomAdded should raise PropertyChanged event with its name." or "ValueWithRandomAdded should hold passed value + Random.Next().". So, I will introduce combination examples to test with using Moq, NSubstitute, Rhino Mocks and FakeItEasy.

Using Moq

About combination examples of Moq. For details, please see this page!

Using NSubstitute

About combination examples of NSubstitute. For details, please see this page!

Using Rhino Mocks

About combination examples of Rhino Mocks. For details, please see this page!

Using FakeItEasy

About combination examples of FakeItEasy. For details, please see this page!

MIGRATION

Mocking Asynchronous Pattern by Microsoft Research Moles

Let's migrate the sample that mocks with Moles against the class that embraces "Event-based Asynchronous Pattern" to Prig. For more information, please check this page!

Mocking HttpWebRequest by Microsoft Fakes

This page introduces Fakes -> Prig migration, also I take the migration explanation that is listed in the section "Migrating from commercial and open source frameworks" of the article "Better Unit Testing with Microsoft Fakes" for example. By the way, I believe that the way to leave Moq untouched is easier because Fakes has no features as a mock, Umm... :{

Final Mocking by Telerik JustMock

This is one of the series that implements the samples that are in the official documents of JustMock. In this page, Final Mocking samples are migrated to Prig.

Sealed Mocking by Telerik JustMock

This is one of the series that implements the samples that are in the official documents of JustMock, part 2. In this page, Sealed Mocking samples are migrated to Prig.

Static Mocking by Telerik JustMock

This is one of the series that implements the samples that are in the official documents of JustMock, part 3. In this page, Static Mocking samples are migrated to Prig.

Test using MessageBox by Typemock Isolator

Typemock introduces the sample that replaces MessageBox to a mock in Isolator's Quick Start. Also, you can migrate it to Prig(with Moq).