0

How does one initialize a complex object with random data for testing?

I've got kind of a complex object that looks like this:

public class DynamicEntity
{
    public string EntityName { get; set; }
    public List<Entity> MappingEntityList { get; set; }
    public List<BaseAttributes> BaseAttributesList { get; set; }
}

I am trying to initialize it with random data:

// Fixture setup
Fixture fixture = new Fixture();
DynamicEntity dynamicEntityFixture = fixture.Create<DynamicEntity>();

I am then setting up my mocked object to return this dynamicEntityFixture:

_mockedObject.Setup(x => x.GetEntityProperties("account"))
                          .Returns(() => dynamicEntityFixture);

When running the unit test I am getting:

Ploeh.AutoFixture.ObjectCreationException : AutoFixture was unable to create an instance from System.Runtime.Serialization.ExtensionDataObject, most likely because it has no public constructor, is an abstract or non-public type.

How can I initialize a complex object with random data for testing?

stuartd
  • 70,509
  • 14
  • 132
  • 163
Alex Gordon
  • 57,446
  • 287
  • 670
  • 1,062

0 Answers0