Skip to content

Using Ergo

Yan Justino edited this page Dec 26, 2019 · 1 revision

Ergo is an amazing feature of Polyjuice. With Ergo you can register your stubs and use then when necessary. See how use Ergo bellow:

Ergo with default model

Describes a default stub model.

/// Setup
Ergo<Person>.Current.SetDefault(new Person
{
    FirstName = Name.FirstName,
    LastName = Name.LastName,
    FullName = Name.FullName ,
    NameWithPrefix = Name.NameWithPrefix,
    Gender = Gender.Random,
    Birthday = DateAndTime.Birthday 
});

[Test]
public void TestPersonA()
{
    var person = Ergo<Person>.Current.GetDefault()
    ...
}

[Test]
public void TestPersonB()
{
    var person = Ergo<Person>.Current.GetDefault()
    ...
}

Ergo with context

Describes a contextualized stub model.

/// Setup
Ergo<Person>.Current["Regular Customer"] = new Person
{
    FirstName = Name.FirstName,
    LastName = Name.LastName,
    FullName = Name.FullName ,
    NameWithPrefix = Name.NameWithPrefix,
    Gender = Gender.Random,
    Birthday = DateAndTime.Birthday 
};

[Test]
public void TestPersonA()
{
    var stub = Ergo<Person>.Current["Regular Customer"];
    ...
}

[Test]
public void TestPersonB()
{
    var stub = Ergo<Person>.Current["Regular Customer"];
    ...
}
Clone this wiki locally