Skip to content

Instantly share code, notes, and snippets.

@zs40x
Last active April 22, 2016 06:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zs40x/c88a62c11d3fbfaae999579abbc95b16 to your computer and use it in GitHub Desktop.
Save zs40x/c88a62c11d3fbfaae999579abbc95b16 to your computer and use it in GitHub Desktop.
namespace LiskovSubstitutionPrinciple.Tests
{
[TestFixture]
public class Violation
{
[Test]
public void RectangleIsOkay()
{
Rectangle rect = new Rectangle
{
Width = 5,
Height = 10
};
rect.Area.Should().Be(50);
}
[Test]
public void SquareDoesntWorkAsExpected()
{
Rectangle rect = new Square
{
Width = 5,
Height = 10
};
/*
* Te following Assertions failes, because Square modifies
* the behaviour of Rectangle. Changing width or height
* always changes both attributes to be a valid Square.
*
* => Violation of the Liskov Substitution Principle
*/
rect.Area.Should().Be(50); // is actually 100!
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment