I am experimenting with Code Contract, and I ran into one problem. I have a class:
public class SpecialPoint { public int X { get; set; } public int Y { get; set; } public SpecialPoint(int x, int y) { Contract.Requires<ArgumentException>(y > x); X = x; Y = y; } [ContractInvariantMethod] private void ClassContract() { Contract.Invariant(Y > X); } }
and I will test against him:
[TestFixture] class SpecialPointTests { [Test] public void SpecialPoint() { var p = new SpecialPoint(10, 20); pX = 30; } }
I expected static checks to warn me about pX = 30; as this violates the invariant, but this only happens at runtime. I have the option of static analysis. My version is 1.7.11202.10.
source share