public void ShouldSyncItsContainerWithModelParents() { var model_a = new Model ("a"); var model_b = new Model ("b"); var model_container = new Model("container"); var models = new ModelCollection(model_container); models.AddRange(new [] {model_a, model_b}); Assert.That(models.Container, Is.EqualTo(model_container)); Assert.That(models.All(m => m.Parent == model_container)); models.Clear(); Assert.That(model_a.Parent, Is.Null); Assert.That(model_b.Parent, Is.Null); models.Add(model_a); Assert.That(model_a.Parent, Is.EqualTo(model_container)); models.Insert(0, model_b); Assert.That(model_b.Parent, Is.EqualTo(model_container)); models.Remove(model_a); Assert.That(model_a.Parent, Is.Null); }
public Model(Model parent, Model owner, string key) { if(string.IsNullOrEmpty(key)) throw new ArgumentException("Name cannot be null or empty!", "key"); this.parent = parent; this.owner = owner; this.key = key; }
internal void SetParent(Model parent) { this.parent = parent; OnParentChanged(); }
public Model(Model owner, string key) : this(null, owner, key) { }