public void SetterBaseCollection_Insert_When_Sealed() { var sbc = new SetterBaseCollection(); sbc.Seal(); sbc.IsSealed.Should().BeTrue(); var setter = new Setter(Control.PaddingProperty, new Thickness(20d)); Assert.ThrowsException <InvalidOperationException>(() => sbc.Insert(0, setter)); }
public void Sealed() { Style style = new Style(typeof(UIElement)); SetterBaseCollection c = style.Setters; Setter s = new Setter(Canvas.LeftProperty, 0); c.Add(s); style.Seal(); Assert.Throws(delegate { c.Add(new Setter(Canvas.TopProperty, 0)); }, typeof(Exception)); Assert.Throws(delegate { c.Insert(0, new Setter(Canvas.TopProperty, 0)); }, typeof(Exception)); /*Assert.Throws (delegate {*/ c.Remove(s); /* }, typeof (Exception));*/ Assert.AreEqual(0, c.Count); // need to reinitialize things here since the // Remove above actually succeeded. style = new Style(typeof(UIElement)); c = style.Setters; s = new Setter(Canvas.LeftProperty, 0); c.Add(s); style.Seal(); // lame, this should raise an exception too /*Assert.Throws (delegate {*/ c.RemoveAt(0); /* }, typeof (Exception));*/ Assert.AreEqual(0, c.Count); // need to reinitialize things here since the // RemoveAt above actually succeeded. style = new Style(typeof(UIElement)); c = style.Setters; s = new Setter(Canvas.LeftProperty, 0); c.Add(s); style.Seal(); Assert.Throws(delegate { c[0] = new Setter(Canvas.TopProperty, 0); }, typeof(Exception)); }
public void SetterBaseCollection_Insert_Null() { var sbc = new SetterBaseCollection(); Assert.ThrowsException <ArgumentNullException>(() => sbc.Insert(0, null)); }