本文整理汇总了C#中ObservableDictionary.RemoveRange方法的典型用法代码示例。如果您正苦于以下问题:C# ObservableDictionary.RemoveRange方法的具体用法?C# ObservableDictionary.RemoveRange怎么用?C# ObservableDictionary.RemoveRange使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ObservableDictionary
的用法示例。
在下文中一共展示了ObservableDictionary.RemoveRange方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RemoveRangeRaisesPropertyChangedEventForItemIndexerAndCount
public void RemoveRangeRaisesPropertyChangedEventForItemIndexerAndCount()
{
// given
var items = new List<KeyValuePair<int, string>>()
{
new KeyValuePair<int, string>(1, "One"),
new KeyValuePair<int, string>(2, "Two"),
new KeyValuePair<int, string>(3, "Three"),
};
using (var observableDictionary = new ObservableDictionary<int, string>(items))
{
observableDictionary.ThresholdAmountWhenChangesAreNotifiedAsReset = 0;
observableDictionary.MonitorEvents();
// when
observableDictionary.RemoveRange(items);
// then
observableDictionary
.ShouldRaise(nameof(observableDictionary.PropertyChanged))
.WithSender(observableDictionary)
.WithArgs<PropertyChangedEventArgs>(args => args.PropertyName == "Item[]");
observableDictionary
.ShouldRaise(nameof(observableDictionary.PropertyChanged))
.WithSender(observableDictionary)
.WithArgs<PropertyChangedEventArgs>(args => args.PropertyName == nameof(observableDictionary.Count));
}
}
示例2: using
public void RemoveRangeRaisesPropertyChangedEventForItemIndexerAndCountOnlyOnceWhenThresholdAmountWhenItemChangesAreNotifiedAsResetIsSetAccordingly()
{
// given
var items = new List<KeyValuePair<int, string>>()
{
new KeyValuePair<int, string>(1, "One"),
new KeyValuePair<int, string>(2, "Two"),
new KeyValuePair<int, string>(3, "Three"),
};
using (var observableDictionary = new ObservableDictionary<int, string>(items))
{
observableDictionary.ThresholdAmountWhenChangesAreNotifiedAsReset = 0;
observableDictionary.MonitorEvents();
// when
observableDictionary.RemoveRange(items);
// then
observableDictionary
.ShouldRaise(nameof(observableDictionary.PropertyChanged))
.WithSender(observableDictionary)
.WithArgs<PropertyChangedEventArgs>(args => args.PropertyName == "Item[]")
.Should().HaveCount(1); // ToDo: re-enable test if/when https://github.com/dennisdoomen/fluentassertions/issues/337 has been fixed
observableDictionary
.ShouldRaise(nameof(observableDictionary.PropertyChanged))
.WithSender(observableDictionary)
.WithArgs<PropertyChangedEventArgs>(args => args.PropertyName == nameof(observableDictionary.Count))
.Should().HaveCount(1); // ToDo: re-enable test if/when https://github.com/dennisdoomen/fluentassertions/issues/337 has been fixed
}
}
示例3: RemoveRangeOfKeyValuePairsThrowsOnNonExistingItems
public void RemoveRangeOfKeyValuePairsThrowsOnNonExistingItems()
{
// given
using (var observableDictionary = new ObservableDictionary<int, string>())
{
// when
Action invalidRemoveRangeForNonExistingKey = () => observableDictionary.RemoveRange(new List<KeyValuePair<int, string>>() {new KeyValuePair<int, string>(10, "Ten")});
// then
invalidRemoveRangeForNonExistingKey
.ShouldThrow<ArgumentOutOfRangeException>()
.WithMessage("The following key/value pair(s) are not in this dictionary and cannot be removed from it: [10, Ten]\r\nParameter name: items");
observableDictionary.Count.Should().Be(0);
}
}
示例4: RemoveRangeOfKeyValuePairsThrowsOnNullItems
public void RemoveRangeOfKeyValuePairsThrowsOnNullItems()
{
// given
using (var observableDictionary = new ObservableDictionary<int, string>())
{
// when
Action action = () => observableDictionary.RemoveRange((List<KeyValuePair<int, string>>) null);
// then
action
.ShouldThrow<ArgumentNullException>()
.WithMessage("Value cannot be null.\r\nParameter name: items");
observableDictionary.Count.Should().Be(0);
}
}
示例5: RemoveRangeOfKeyValuePairsRemovesItems
public void RemoveRangeOfKeyValuePairsRemovesItems(int initialAmountOfItems, int amountsOfItemsToRemove)
{
// given
var keyValuePairs = Enumerable.Range(0, initialAmountOfItems)
.Select(i => new KeyValuePair<int, string>(i, $"#{i}"))
.ToList();
var keyValuePairsToRemove = Enumerable.Range(0, amountsOfItemsToRemove)
.Select(i => new KeyValuePair<int, string>(i, $"#{i}"))
.ToDictionary(keyValuePair => keyValuePair.Key, keyValuePair => keyValuePair.Value).ToList();
using (var observableDictionary = new ObservableDictionary<int, string>(keyValuePairs))
{
// when
observableDictionary.RemoveRange(keyValuePairsToRemove);
// then check whether all items have been accounted for
observableDictionary.Count.Should().Be(initialAmountOfItems - amountsOfItemsToRemove);
foreach (var removedKeyValuePair in keyValuePairsToRemove)
{
observableDictionary.Should().NotContain(removedKeyValuePair);
}
}
}