Ramunas Ramunas -4 years ago 153
C# Question

SpecFlow and complex objects

I'm evaluating SpecFlow and I'm a bit stuck.

All samples I have found are basically with simple objects.

Project I'm working on heavily relies on a complex object. A close sample could be this object:

public class MyObject
public int Id { get; set; }
public DateTime StartDate { get; set; }
public DateTime EndDate { get; set; }
public IList<ChildObject> Children { get; set; }


public class ChildObject
public int Id { get; set; }
public string Name { get; set; }
public int Length { get; set; }

Does anyone have any idea how could a write my features/scenarios where
would be instantiated from a "Given" step and used in "When" and "Then" steps?

Thanks in advance

EDIT: Just a shot in mind: are nested tables supported?

Answer Source

For the example you have shown I would say you're cuking it wrong. This example looks more suitable to write with nunit and probably using an object mother. Tests written with specflow or similar tool should be customer facing and use the same language as your customer would use to describe the feature.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download