Last active
April 22, 2016 06:03
-
-
Save zs40x/c88a62c11d3fbfaae999579abbc95b16 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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