Skip to content

The way xp is modeled violates liskov substitution principle #60

@crhistianramirez

Description

@crhistianramirez

Consider the following scenario:

public class MyOrder: Order<MyXp>{}
public class MyXp
{
    public string Color { get; set; }
}

var order = new MyOrder();
order = (Order)order;
order.xp = 5;
order = (MyOrder)order;
var color = order.xp.Color; // 'myOrder.xp.Color' threw an exception of type 'System.InvalidCastException'

The expectation would be that when I use the instance as MyOrder everything will be fine, but it cannot be fine since it is backed by the same dictionary instance and the implementation of ordercloud models does not handle this scenario.

This may seem a bit contrived but I came across this when trying to use AutoFixture to automatically mock ordercloud models with typed xp. AutoFixture cannot ignore the hidden properties, since the hidden property values can always be used, while its lower instance is cast to it's base type.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions