Unit Test Spike
- ObjectMother
- JSON Seed Data
- Builder
Options
- Creates the same entities every time
- Nested objects get complicated
- New entities are the same amount of effort each time
ObjectMother
- This was brought up, but I didn't pursue it because of time constrictions
- Would create a database that is exactly the same for each test
- New entities could be created and would apply to every test
JSON Seed Data
- Easier to build objects
- A lot of work per entity
- Helps make creating entities consistent
- Easy to expand
Builder
Builder
var jmJobCostCode = new JMJobCostCode()
{
Id = jmJobCostCodeId,
Code = "code code 1",
JMJobId = jmJobId,
QuantityFromEntity = QuantityFromEntity.None,
UnitOfMeasure = "Each",
IsDeleted = false,
DeletedBy = null,
DeletedDate = null
};var costCodeBuilder = new CostCodeBuilder();
var jmJobCostCode = costCodeBuilder
.WithId(jmJobCostCodeId)
.WithJobId(jmJobId)
.Build();
Automatically creates:
- Code
- Unit of Measure
- QuantityFromEntity
- Deleted Status
Builder
var jmJobCostCode2 = new JMJobCostCode()
{
Id = jmJobCostCodeId2,
Code = "code code 2",
JMJobId = jmJobId,
QuantityFromEntity = QuantityFromEntity.Material,
QuantityFromId = jmJobMaterialId,
UnitOfMeasure = "TON",
IsDeleted = false,
DeletedBy = null,
DeletedDate = null
};var jmJobCostCode2 = costCodeBuilder
.WithId(jmJobCostCodeId2)
.WithJobId(jmJobId)
.WithQuantityFromDriver(QuantityFromEntity.Material, jmJobMaterialId)
.Build();Api Unit Test Spike
By Michael Klosterboer
Api Unit Test Spike
- 33