Microsoft Moles:循环引用错误?

时间:2012-02-17 09:06:38

标签: unit-testing moles stub circular-reference

我有以下实体框架实体:

public class Country
{
    public long Id { get; set; }
    public string Code { get; set; }
    public virtual ICollection<Person> Persons { get; set; }
}

public class Person
{
    public long Id { get; set; }
    public long? Country_Id { get; set; }
    public Country HomeCountry { get; set; }
}

Moles已生成 MPerson MCountry 存根类。

现在我想要存根Country_Id的集合:

MPerson.AllInstances.Country_IdSetNullableOfInt64 = (Person instance, long? id) =>
{
    // Do something

    // Set the Country_Id to the provided id
    // This will trigger this same method again and again. How to avoid this ?
    instance.Country_Id = id;
};

1 个答案:

答案 0 :(得分:0)

This post给出答案:

MolesContext.ExecuteWithoutMoles(() => instance.Country_Id = id);