/// <summary> /// Performs an insert operation on the list of data that the <see cref="DataSourceView"/> object represents. /// </summary> /// <param name="values">An <see cref="IDictionary"/> of name/value pairs used during an insert operation.</param> /// <returns>The number of items that were inserted into the underlying data storage.</returns> protected override int ExecuteInsert(IDictionary values) { Guard.ArgumentNotNull(values, "values"); ObjectContainerDataSourceInsertingEventArgs insertingEventArgs = new ObjectContainerDataSourceInsertingEventArgs(values); OnInserting(insertingEventArgs); if (insertingEventArgs.Cancel) { return(0); } object instance = CreateInstance(); TypeDescriptionHelper.BuildInstance(values, instance); Add(instance); OnDataSourceViewChanged(EventArgs.Empty); int rowsAffected = 1; ObjectContainerDataSourceStatusEventArgs insertedEventArgs = new ObjectContainerDataSourceStatusEventArgs(instance, rowsAffected); OnInserted(insertedEventArgs); return(rowsAffected); }
public void BuildInstanceThrowsIfPropertyIsUnexistant() { OrderedDictionary values = new OrderedDictionary(1); values.Add("Unexistant", "unexistant"); TypeDescriptionHelper.BuildInstance(values, new SimpleEntity()); }
public void BuildInstanceThrowsIfPropertyIsReadOnly() { OrderedDictionary values = new OrderedDictionary(1); values.Add("Name", "name"); TypeDescriptionHelper.BuildInstance(values, new SimpleEntityWithReadOnlyProperty()); }
public void BuildInstance() { SimpleEntity simpleEntity = new SimpleEntity(); OrderedDictionary values = new OrderedDictionary(3); values.Add("Id", 1); values.Add("Name", "name"); values.Add("Age", 10); TypeDescriptionHelper.BuildInstance(values, simpleEntity); Assert.AreEqual(1, simpleEntity.Id); Assert.AreEqual("name", simpleEntity.Name); Assert.AreEqual(10, simpleEntity.Age); }
/// <summary> /// Performs an update operation on the list of data that the <see cref="DataSourceView"/> object represents. /// </summary> /// <param name="keys">An <see cref="System.Collections.IDictionary"/> of object or row keys to be updated by the update operation.</param> /// <param name="values">An <see cref="System.Collections.IDictionary"/> of name/value pairs that represent data elements and their new values.</param> /// <param name="oldValues">An <see cref="System.Collections.IDictionary"/> of name/value pairs that represent data elements and their original values.</param> /// <returns>The number of items that were updated in the underlying data storage.</returns> protected override int ExecuteUpdate(IDictionary keys, IDictionary values, IDictionary oldValues) { Guard.CollectionNotNullNorEmpty(keys, String.Format(CultureInfo.CurrentCulture, Resources.NoKeysSpecified), "keys"); Guard.ArgumentNotNull(values, "values"); ObjectContainerDataSourceUpdatingEventArgs updatingEventArgs = new ObjectContainerDataSourceUpdatingEventArgs(DictionaryHelper.GetReadOnlyDictionary(keys), values, oldValues); OnUpdating(updatingEventArgs); if (updatingEventArgs.Cancel) { return(0); } object newInstance = CreateInstance(); TypeDescriptionHelper.BuildInstance(keys, newInstance); TypeDescriptionHelper.BuildInstance(values, newInstance); int rowsAffected; object oldInstance = FindInstance(keys); if (oldInstance != null) { int index = Data.IndexOf(oldInstance); Data[index] = newInstance; rowsAffected = 1; } else { rowsAffected = 0; } OnDataSourceViewChanged(EventArgs.Empty); ObjectContainerDataSourceStatusEventArgs updatedEventArgs = new ObjectContainerDataSourceStatusEventArgs(newInstance, rowsAffected); OnUpdated(updatedEventArgs); return(rowsAffected); }
/// <summary> /// Performs a delete operation on the list of data that the <see cref="DataSourceView"/> object represents. /// </summary> /// <param name="keys">An <see cref="IDictionary"/> of object or row keys to be deleted by /// the <see cref="DataSourceView.ExecuteDelete(System.Collections.IDictionary,System.Collections.IDictionary)"/> /// operation.</param> /// <param name="oldValues">An <see cref="System.Collections.IDictionary"/> of name/value pairs that represent data elements and their original values.</param> /// <returns>The number of items that were deleted from the underlying data storage.</returns> protected override int ExecuteDelete(IDictionary keys, IDictionary oldValues) { Guard.CollectionNotNullNorEmpty(keys, String.Format(CultureInfo.CurrentCulture, Resources.NoKeysSpecified), "keys"); ObjectContainerDataSourceDeletingEventArgs deletingEventArgs = new ObjectContainerDataSourceDeletingEventArgs(DictionaryHelper.GetReadOnlyDictionary(keys), oldValues); OnDeleting(deletingEventArgs); if (deletingEventArgs.Cancel) { return(0); } int rowsAffected; object instance = FindInstance(keys); if (instance == null) { rowsAffected = 0; } else { Data.Remove(instance); rowsAffected = 1; } instance = CreateInstance(); TypeDescriptionHelper.BuildInstance(oldValues, instance); TypeDescriptionHelper.BuildInstance(keys, instance); OnDataSourceViewChanged(EventArgs.Empty); ObjectContainerDataSourceStatusEventArgs deletedEventArgs = new ObjectContainerDataSourceStatusEventArgs(instance, rowsAffected); OnDeleted(deletedEventArgs); return(rowsAffected); }
public void BuildInstanceThrowsIfExistingIsNull() { TypeDescriptionHelper.BuildInstance(new OrderedDictionary(), null); }
public void BuildInstanceThrowsIfValuesIsNull() { TypeDescriptionHelper.BuildInstance(null, new SimpleEntity()); }