Skip to content

Commit

Permalink
Add BindingSource tests (#1073)
Browse files Browse the repository at this point in the history
* Add BindingSource tests
  • Loading branch information
hughbe authored and RussKie committed Jun 3, 2019
1 parent 02d5d0d commit 9ad396e
Show file tree
Hide file tree
Showing 2 changed files with 913 additions and 10 deletions.
20 changes: 10 additions & 10 deletions src/System.Windows.Forms/src/System/Windows/Forms/BindingSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public BindingSource(System.ComponentModel.IContainer container) : this()
container.Add(this);
}

private bool AllowNewInternal(bool checkconstructor)
private bool AllowNewInternal(bool checkConstructor)
{
if (_disposedOrFinalized)
{
Expand All @@ -149,13 +149,13 @@ private bool AllowNewInternal(bool checkconstructor)
}
else
{
return IsListWriteable(checkconstructor);
return IsListWriteable(checkConstructor);
}
}

private bool IsListWriteable(bool checkconstructor)
private bool IsListWriteable(bool checkConstructor)
{
return !List.IsReadOnly && !List.IsFixedSize && (!checkconstructor || _itemConstructor != null);
return !List.IsReadOnly && !List.IsFixedSize && (!checkConstructor || _itemConstructor != null);
}

[Browsable(false)]
Expand Down Expand Up @@ -1100,7 +1100,7 @@ public void ResetItem(int itemIndex)
/// Binds the BindingSource to the list specified by its DataSource and DataMember
/// properties.
/// </summary>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1800:DoNotCastUnnecessarily", Justification = "List is cast to IEnumerable twice. Acceptible trade-off versus code clarity (this method contains *critical* logic).")]
[SuppressMessage("Microsoft.Performance", "CA1800:DoNotCastUnnecessarily", Justification = "List is cast to IEnumerable twice. Acceptible trade-off versus code clarity (this method contains *critical* logic).")]
private void ResetList()
{
// Don't bind during initialization, since the data source may not have been initialized yet.
Expand All @@ -1122,7 +1122,7 @@ private void ResetList()
//
// Note: The method below will throw an exception if a data member is specified
// but does not correspond to a valid property on the data source.
object dataSourceInstance = (_dataSource is Type) ? GetListFromType(_dataSource as Type) : _dataSource;
object dataSourceInstance = _dataSource is Type dataSourceType ? GetListFromType(dataSourceType) : _dataSource;
object list = ListBindingHelper.GetList(dataSourceInstance, _dataMember);
_listExtractedFromEnumerable = false;

Expand Down Expand Up @@ -1176,7 +1176,7 @@ private void ResetList()
}

// Bind to this list now
SetList(bindingList, true, true);
SetList(bindingList, metaDataChanged: true, applySortAndFilter: true);
}

/// <summary>
Expand Down Expand Up @@ -1594,12 +1594,12 @@ public virtual PropertyDescriptorCollection GetItemProperties(PropertyDescriptor
public virtual object AddNew()
{
// Throw if adding new items has been disabled
if (!AllowNewInternal(false))
if (!AllowNewInternal(checkConstructor: false))
{
throw new InvalidOperationException(SR.BindingSourceBindingListWrapperAddToReadOnlyList);
}

if (!AllowNewInternal(true))
if (!AllowNewInternal(checkConstructor: true))
{
throw new InvalidOperationException(string.Format(
SR.BindingSourceBindingListWrapperNeedToSetAllowNew,
Expand Down Expand Up @@ -1689,7 +1689,7 @@ public virtual bool AllowNew
// Don't let user set value to true if inner list can never support adding of items
// do NOT check for a default constructor because someone will set AllowNew=True
// when they have overridden OnAddingNew (which we cannot detect).
if (value == true && !_isBindingList && !IsListWriteable(false))
if (value == true && !_isBindingList && !IsListWriteable(checkConstructor: false))
{
throw new InvalidOperationException(SR.NoAllowNewOnReadOnlyList);
}
Expand Down
Loading

0 comments on commit 9ad396e

Please sign in to comment.