Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The way xp is modeled violates liskov substitution principle #60

Open
crhistianramirez opened this issue Mar 15, 2021 · 0 comments
Open

Comments

@crhistianramirez
Copy link
Contributor

crhistianramirez commented Mar 15, 2021

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant