public void IndexOf() { var factory = ViewFactory.IListSimpleItems(); var list = factory.List; var view = factory.View; list.Add(new SimpleClass(100, "aaa", new DateTime(1970, 1, 1))); var bbb = new SimpleClass(80, "bbb", new DateTime(1980, 12, 12)); list.Add(bbb); list.Add(new SimpleClass(60, "ccc", new DateTime(1975, 6, 6))); Assert.AreEqual(1, view.IndexOf(bbb)); }
public void Setup() { list = new List<SimpleClass>(); list.Add(new SimpleClass(100, "aaa", new DateTime(1970, 1, 1))); bbb = new SimpleClass(80, "bbb", new DateTime(1980, 12, 12)); list.Add(bbb); list.Add(new SimpleClass(60, "ccc", new DateTime(1975, 6, 6))); view = new ObjectListView(list); SetupListEventHandlers(view); }
public void ContainsItemInList() { var factory = ViewFactory.IListSimpleItems(); var list = factory.List; var view = factory.View; list.Add(new SimpleClass(100, "aaa", new DateTime(1970, 1, 1))); var bbb = new SimpleClass(80, "bbb", new DateTime(1980, 12, 12)); list.Add(bbb); list.Add(new SimpleClass(60, "ccc", new DateTime(1975, 6, 6))); Assert.IsTrue(view.Contains(bbb)); }
public void ItemGet() { ViewFactory factory = ViewFactory.IListSimpleItems(); IList list = factory.List; ObjectListView view = factory.View; list.Add(new SimpleClass(100, "aaa", new DateTime(1970, 1, 1))); SimpleClass bbb = new SimpleClass(80, "bbb", new DateTime(1980, 12, 12)); factory.List.Add(bbb); list.Add(new SimpleClass(60, "ccc", new DateTime(1975, 6, 6))); object item = view[1]; Assert.AreEqual(bbb, item); }
public void GetValueNullReferenceType() { SimpleClass item = new SimpleClass(42, "Orders", DateTime.Now); ExtendedProperty prop = new ExtendedProperty(typeof(SimpleClass), "Total", typeof(string), true, null); int callbacks = 0; prop.GetValue += delegate(object sender, ExtendedPropertyEventArgs args) { callbacks++; args.Value = null; }; object propValue = prop.PropertyDescriptor.GetValue(item); Assert.IsNull(propValue); }
public void RemoveNotInList() { var factory = ViewFactory.IListSimpleItems(); var list = factory.List; var view = factory.View; list.Add(new SimpleClass(100, "aaa", new DateTime(1970, 1, 1))); list.Add(new SimpleClass(80, "bbb", new DateTime(1980, 12, 12))); list.Add(new SimpleClass(60, "ccc", new DateTime(1975, 6, 6))); factory.ClearEventCounts(); var ddd = new SimpleClass(66, "ddd", new DateTime(1980, 12, 12)); view.Remove(ddd); Assert.AreEqual(0, factory.ListChangedDeletedCount); Assert.AreEqual(0, factory.RemovingItemCount); }
public void SetValue() { SimpleClass item = new SimpleClass(42, "Orders", DateTime.Now); ExtendedProperty prop = new ExtendedProperty(typeof(SimpleClass), "Total", typeof(string), true, null); int callbacks = 0; prop.SetValue += delegate(object sender, ExtendedPropertyEventArgs args) { callbacks++; Assert.AreEqual("Total", args.PropertyName); Assert.AreSame(item, args.Target); Assert.IsNotNull(args.Value); Assert.AreEqual(typeof(string), args.Value.GetType()); Assert.AreEqual("Orders: 57", args.Value); }; prop.PropertyDescriptor.SetValue(item, "Orders: 57"); Assert.AreEqual(1, callbacks); }
public void CopyTo() { ObjectListView view = new ObjectListView(nonEmptyList); SimpleClass[] array = new SimpleClass[3]; view.CopyTo(array, 0); SimpleClass item = array[0]; Assert.IsNotNull(item); Assert.AreEqual(100, item.IntegerValue); Assert.AreEqual("aaa", item.StringValue); Assert.AreEqual(new DateTime(1970, 1, 1), item.DateTimeValue); item = array[1]; Assert.AreEqual(80, item.IntegerValue); Assert.AreEqual("bbb", item.StringValue); Assert.AreEqual(new DateTime(1980, 12, 12), item.DateTimeValue); item = array[2]; Assert.AreEqual(60, item.IntegerValue); Assert.AreEqual("ccc", item.StringValue); Assert.AreEqual(new DateTime(1975, 6, 6), item.DateTimeValue); }
public void GetValue() { SimpleClass item = new SimpleClass(42, "Orders", DateTime.Now); ExtendedProperty prop = new ExtendedProperty(typeof(SimpleClass), "Total"); int callbacks = 0; prop.GetValue += delegate(object sender, ExtendedPropertyEventArgs args) { callbacks++; Assert.AreEqual("Total", args.PropertyName); Assert.AreSame(item, args.Target); Assert.AreEqual(null, args.Value); args.Value = string.Format("{0}: {1}", ((SimpleClass)args.Target).StringValue, ((SimpleClass)args.Target).IntegerValue); }; object propValue = prop.PropertyDescriptor.GetValue(item); Assert.AreEqual(1, callbacks); Assert.IsNotNull(propValue); Assert.AreEqual(typeof(string), propValue.GetType()); Assert.AreEqual("Orders: 42", propValue); }
public void RemoveAtIBindingList() { var factory = ViewFactory.IBindingListSimpleItems(); factory.List.Add(new SimpleClass(100, "aaa", new DateTime(1970, 1, 1))); var bbb = new SimpleClass(80, "bbb", new DateTime(1980, 12, 12)); factory.List.Add(bbb); factory.List.Add(new SimpleClass(60, "ccc", new DateTime(1975, 6, 6))); factory.ClearEventCounts(); var removingIndex = -1; factory.View.RemovingItem += delegate(object sender, RemovingItemEventArgs args) { removingIndex = args.Index; }; factory.View.RemoveAt(0); Assert.AreEqual(2, factory.List.Count); Assert.AreEqual("bbb", ((SimpleClass)factory.List[0]).StringValue); Assert.AreEqual(1, factory.ListChangedDeletedCount); Assert.AreEqual(1, factory.RemovingItemCount); Assert.AreEqual(0, removingIndex); }
public void GetValueNullNullableValueType() { SimpleClass item = new SimpleClass(42, "Orders", DateTime.Now); ExtendedProperty prop = new ExtendedProperty(typeof(SimpleClass), "Total", typeof(int?), true, null); prop.GetValue += delegate(object sender, ExtendedPropertyEventArgs args) { args.Value = null; }; object propValue = prop.PropertyDescriptor.GetValue(item); Assert.IsNull(propValue); }
public void SetValueReadOnly() { SimpleClass item = new SimpleClass(42, "Orders", DateTime.Now); ExtendedProperty prop = new ExtendedProperty(typeof(SimpleClass), "Total"); prop.PropertyDescriptor.SetValue(item, "Orders: 57"); }
public void AllowRemoveSetFalseRemoveAt() { ViewFactory factory = ViewFactory.IBindingListSimpleItems(); SimpleClass item = new SimpleClass(); factory.View.Add(item); factory.View.AllowRemove = false; factory.View.RemoveAt(0); }
public void GetValueWrongTypeReferenceType() { SimpleClass item = new SimpleClass(42, "Orders", DateTime.Now); ExtendedProperty prop = new ExtendedProperty(typeof(SimpleClass), "Total", typeof(string), true, null); prop.GetValue += delegate(object sender, ExtendedPropertyEventArgs args) { args.Value = 42; }; object propValue = prop.PropertyDescriptor.GetValue(item); }
public void ListChangedItemReplaced() { BindingList<SimpleClass> list = new BindingList<SimpleClass>(); list.Add(new SimpleClass(100, "aaa", new DateTime(1970, 1, 1))); list.Add(new SimpleClass(80, "bbb", new DateTime(1980, 12, 12))); list.Add(new SimpleClass(60, "ccc", new DateTime(1975, 6, 6))); ObjectListView view = new ObjectListView(list); SetupListEventHandlers(view); SimpleClass item = new SimpleClass(50, "555", new DateTime(1955, 5, 5)); Assert.AreEqual(0, this.listChangedAddedRaised); Assert.AreEqual(0, this.listChangedDeletedRaised); Assert.AreEqual(0, this.listChangedItemChangedRaised); Assert.AreEqual(0, this.listChangedResetRaised); list[2] = item; Assert.AreEqual(0, this.listChangedAddedRaised); Assert.AreEqual(0, this.listChangedDeletedRaised); Assert.AreEqual(1, this.listChangedItemChangedRaised); Assert.AreEqual(0, this.listChangedResetRaised); }
public void ContainsItemInList() { ViewFactory factory = ViewFactory.IListSimpleItems(); IList list = factory.List; ObjectListView view = factory.View; list.Add(new SimpleClass(100, "aaa", new DateTime(1970, 1, 1))); SimpleClass bbb = new SimpleClass(80, "bbb", new DateTime(1980, 12, 12)); list.Add(bbb); list.Add(new SimpleClass(60, "ccc", new DateTime(1975, 6, 6))); Assert.IsTrue(view.Contains(bbb)); }
public void RemoveAtIBindingList() { ViewFactory factory = ViewFactory.IBindingListSimpleItems(); factory.List.Add(new SimpleClass(100, "aaa", new DateTime(1970, 1, 1))); SimpleClass bbb = new SimpleClass(80, "bbb", new DateTime(1980, 12, 12)); factory.List.Add(bbb); factory.List.Add(new SimpleClass(60, "ccc", new DateTime(1975, 6, 6))); factory.ClearEventCounts(); int removingIndex = -1; factory.View.RemovingItem += delegate(object sender, RemovingItemEventArgs args) { removingIndex = args.Index; }; factory.View.RemoveAt(0); Assert.AreEqual(2, factory.List.Count); Assert.AreEqual("bbb", ((SimpleClass)factory.List[0]).StringValue); Assert.AreEqual(1, factory.ListChangedDeletedCount); Assert.AreEqual(1, factory.RemovingItemCount); Assert.AreEqual(0, removingIndex); }
public void RemoveNotInList() { ViewFactory factory = ViewFactory.IListSimpleItems(); IList list = factory.List; ObjectListView view = factory.View; list.Add(new SimpleClass(100, "aaa", new DateTime(1970, 1, 1))); list.Add(new SimpleClass(80, "bbb", new DateTime(1980, 12, 12))); list.Add(new SimpleClass(60, "ccc", new DateTime(1975, 6, 6))); factory.ClearEventCounts(); SimpleClass ddd = new SimpleClass(66, "ddd", new DateTime(1980, 12, 12)); view.Remove(ddd); Assert.AreEqual(0, factory.ListChangedDeletedCount); Assert.AreEqual(0, factory.RemovingItemCount); }
public void CopyToEmptyList() { ObjectListView view = new ObjectListView(emptyList); SimpleClass[] array = new SimpleClass[0]; view.CopyTo(array, 0); }