I want to enforce on my code base immutable rule with following test
[TestFixture]
public class TestEntityIf
{
[Test]
public void IsImmutable()
{
var setterCount =
(from s in typeof (Entity).GetProperties(BindingFlags.Public | BindingFlags.Instance)
where s.CanWrite
select s)
.Count();
Assert.That(setterCount == 0, Is.True, "Immutable rule is broken");
}
}
It passes for:
public class Entity
{
private int ID1;
public int ID
{
get { return ID1; }
}
}
but doesn't for this:
public class Entity
{
public int ID { get; private set; }
}
And here goes the question "WTF?"