I've got a scenario I discovered when checking code coverage on a class's properties. When the property is of type List< T >, and an initializer is used, the set method doesn't appear to be called. This isn't true of other types, like strings and ints. Code coverage doesn't show the set call, nor does a breakpoint in set get hit.
Example class:
public class ContainerClass
{
public string Text { get; set; }
public List<Item> Items { get; set; }
}
When using an initializer, like below, the set method on Text is called, and registers in code coverage, but the set method on Items does not, and I am wondering why:
var arrange = new ContainerClass
{
Text = "value",
Items = { new Item() }
};
Edit: I would point out that the list is correctly assigned, and can be tested against, but it appears to go around the actual set method.
Interestingly, when I specify the new list, it does get called:
var arrange = new ContainerClass
{
Items = new List<Item> { new Item() }
};