本文整理汇总了C#中ObservableDictionary.Last方法的典型用法代码示例。如果您正苦于以下问题:C# ObservableDictionary.Last方法的具体用法?C# ObservableDictionary.Last怎么用?C# ObservableDictionary.Last使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ObservableDictionary
的用法示例。
在下文中一共展示了ObservableDictionary.Last方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RemoveNotifiesRemovalAsResetIfRequestedTest
public void RemoveNotifiesRemovalAsResetIfRequestedTest(int initialDictionarySize, int amountOfItemsToRemove)
{
if (amountOfItemsToRemove > initialDictionarySize)
throw new ArgumentOutOfRangeException(nameof(amountOfItemsToRemove), $"Must be less than {nameof(initialDictionarySize)}");
// given
var scheduler = new TestScheduler();
var initialValues = Enumerable.Range(0, initialDictionarySize).ToDictionary(item => item, item => $"#{item}");
var observer = scheduler.CreateObserver<IObservableDictionaryChange<int, string>>();
var resetsObserver = scheduler.CreateObserver<Unit>();
using (var observableDictionary = new ObservableDictionary<int, string>(initialValues, scheduler: scheduler))
{
// when
observableDictionary.ThresholdAmountWhenChangesAreNotifiedAsReset = 0;
using (observableDictionary.DictionaryChanges.Subscribe(observer))
{
using (observableDictionary.Resets.Subscribe(resetsObserver))
{
var removedKeyValuePairs = new List<KeyValuePair<int, string>>();
for (int i = 0; i < amountOfItemsToRemove; i++)
{
var lastEntry = observableDictionary.Last();
observableDictionary.Remove(lastEntry.Key);
removedKeyValuePairs.Add(lastEntry);
scheduler.AdvanceBy(2);
}
// then
observableDictionary.Count.Should().Be(initialDictionarySize - amountOfItemsToRemove);
observer.Messages.Count.Should().Be(amountOfItemsToRemove);
resetsObserver.Messages.Count.Should().Be(amountOfItemsToRemove);
if (initialDictionarySize > 0)
{
observer.Messages.Select(message => message.Value.Value.ChangeType).Should().OnlyContain(changeType => changeType == ObservableDictionaryChangeType.Reset);
observer.Messages.Select(message => message.Value.Value.Key).Should().Match(ints => ints.All(@int => Equals(default(int), @int)));
observer.Messages.Select(message => message.Value.Value.Value).Should().Match(strings => strings.All(@string => Equals(default(string), @string)));
}
}
}
}
}
示例2: RemoveNotifiesCountDecrease
public void RemoveNotifiesCountDecrease(int initialDictionarySize, int amountOfItemsToRemove)
{
if (amountOfItemsToRemove > initialDictionarySize)
throw new ArgumentOutOfRangeException(nameof(amountOfItemsToRemove), $"Must be less than {nameof(initialDictionarySize)}");
// given
var initialValues = Enumerable.Range(0, initialDictionarySize).ToDictionary(item => item, item => $"#{item}");
int observableReportedCount = initialValues.Count;
int countChangesCalled = 0;
using (var observableDictionary = new ObservableDictionary<int, string>(initialValues))
{
// when
observableDictionary.ThresholdAmountWhenChangesAreNotifiedAsReset = int.MaxValue;
observableDictionary.CountChanges.Subscribe(i =>
{
observableReportedCount = i;
countChangesCalled++;
});
for (int i = 0; i < amountOfItemsToRemove; i++)
{
observableDictionary.Remove(observableDictionary.Last().Key);
}
// then check whether all items have been accounted for
var expectedCount = initialDictionarySize - amountOfItemsToRemove;
observableReportedCount.Should().Be(expectedCount); // +1 because the upper for loop goes up to & inclusive the upperLimit
observableReportedCount.Should().Be(observableDictionary.Count);
countChangesCalled.Should().Be(amountOfItemsToRemove);
}
}
示例3: ObservableDictionaryExtensions_Last_ReturnsLastItemInObservableDictionary
public void ObservableDictionaryExtensions_Last_ReturnsLastItemInObservableDictionary()
{
var dictionary = new ObservableDictionary<Int32, String>()
{
{ 1, "A" },
{ 2, "B" },
{ 3, "C" },
};
var result = dictionary.Last();
TheResultingValue(result).ShouldBe(new KeyValuePair<Int32, String>(3, "C"));
}
示例4: ObservableDictionaryExtensions_Last_ThrowsExceptionIfObservableDictionaryIsEmpty
public void ObservableDictionaryExtensions_Last_ThrowsExceptionIfObservableDictionaryIsEmpty()
{
var dictionary = new ObservableDictionary<Int32, String>();
Assert.That(() => dictionary.Last(),
Throws.TypeOf<InvalidOperationException>());
}
示例5: ObservableDictionaryExtensions_Last_ThrowsExceptionIfObservableDictionaryIsEmpty
public void ObservableDictionaryExtensions_Last_ThrowsExceptionIfObservableDictionaryIsEmpty()
{
var dictionary = new ObservableDictionary<Int32, String>();
dictionary.Last();
}