For example, I have these partial classes that were created by EF Database First:
Dog: (object EF)
public partial class Dog { public int DogID { get; set; } public string Name { get; set; } public int Age { get; set; } public int PetOwnerID { get; set; }
PetOwner: (object EF)
public partial class PetOwner { public int PetOwnerID { get; set; } public string PetOwnerName { get; set; }
I need a simple stub like Dog for unit testing. But when I try to create a stub using AutoFixture, a recursive dependency exception is thrown. If I try to change the behavior of a device like this, it freezes.
var fixture = new Fixture(); fixture.Behaviors.OfType<ThrowingRecursionBehavior>().ToList().ForEach(b => fixture.Behaviors.Remove(b)); fixture.Behaviors.Add(new OmitOnRecursionBehavior(1)); var dog = fixture.Create<Dog>();
I don't need any EF functions, just a simple class with properties for testing. I have NUnit, Moq, AutoFixture.
UPDATE:
var dog = fixture.Build<Dog>().Without(x => x.PetOwner).Create();
This solves the problem, but I need the navigation property not to be null.
source share