本文整理汇总了C#中ObservableDictionary.Should方法的典型用法代码示例。如果您正苦于以下问题:C# ObservableDictionary.Should方法的具体用法?C# ObservableDictionary.Should怎么用?C# ObservableDictionary.Should使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ObservableDictionary
的用法示例。
在下文中一共展示了ObservableDictionary.Should方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddOfCollectionOfKeyValuePairsAddsNonExistingItem
public void AddOfCollectionOfKeyValuePairsAddsNonExistingItem()
{
// given
using (var observableDictionary = new ObservableDictionary<int, string>())
{
// when
((ICollection<KeyValuePair<int, string>>) observableDictionary).Add(new KeyValuePair<int, string>(1, "One"));
// then
observableDictionary.Count.Should().Be(1);
observableDictionary.Should().Contain(1, "One");
}
}
示例2: AddOrUpdateAddsNewItem
public void AddOrUpdateAddsNewItem()
{
// given
var key = 1;
var value = "One";
using (var observableDictionary = new ObservableDictionary<int, string>())
{
// when
observableDictionary.AddOrUpdate(key, value);
// then check whether all items have been accounted for
observableDictionary.Count.Should().Be(1);
observableDictionary.Should().Contain(1, "One");
}
}
示例3: AddOrUpdateAllowsUpdateForExistingKeyWithSameValue
public void AddOrUpdateAllowsUpdateForExistingKeyWithSameValue()
{
// given
var initialKvPs = new List<KeyValuePair<int, string>>()
{
new KeyValuePair<int, string>(1, "One")
};
using (var observableDictionary = new ObservableDictionary<int, string>(initialKvPs))
{
// when
observableDictionary.AddOrUpdate(1, "One");
// then check whether all items have been accounted for
observableDictionary.Count.Should().Be(1);
observableDictionary.Should().Contain(1, "One");
}
}
示例4: AddOfCollectionOfKeyValuePairsDoesNotAddItemForExistingKey
public void AddOfCollectionOfKeyValuePairsDoesNotAddItemForExistingKey()
{
// given
var initialKvPs = new List<KeyValuePair<int, string>>()
{
new KeyValuePair<int, string>(1, "One")
};
using (var observableDictionary = new ObservableDictionary<int, string>(initialKvPs))
{
// when
Action action = () => ((ICollection<KeyValuePair<int, string>>) observableDictionary).Add(new KeyValuePair<int, string>(1, "Two"));
// then
action
.ShouldThrow<ArgumentException>()
.WithMessage("The key already existed in the dictionary.");
observableDictionary.Count.Should().Be(1);
observableDictionary.Should().Contain(1, "One");
}
}
示例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);
}
}
}
示例6: TryRemoveOfKeyValuePairRemovesExistingItem
public void TryRemoveOfKeyValuePairRemovesExistingItem()
{
// given
var initialKvPs = new List<KeyValuePair<int, string>>()
{
new KeyValuePair<int, string>(1, "One")
};
using (var observableDictionary = new ObservableDictionary<int, string>(initialKvPs))
{
// when
var removalResult = observableDictionary.TryRemove(1);
// then check whether all items have been accounted for
removalResult.Should().Be(true);
observableDictionary.Count.Should().Be(0);
observableDictionary.Should().NotContain(1, "One");
}
}
示例7: TryAddRangeAddsNonExistingNewItems
public void TryAddRangeAddsNonExistingNewItems(int amountOfItemsToAdd)
{
// given
var keyValuePairs = Enumerable.Range(0, amountOfItemsToAdd)
.Select(i => new KeyValuePair<int, string>(i, $"#{i}"))
.ToList();
using (var observableDictionary = new ObservableDictionary<int, string>())
{
// when
IDictionary<int, string> nonAddedKeyValuePairs;
var tryAddResult = observableDictionary.TryAddRange(keyValuePairs, out nonAddedKeyValuePairs);
// then check whether all items have been accounted for
tryAddResult.Should().Be(true);
nonAddedKeyValuePairs.Should().NotBeNull();
nonAddedKeyValuePairs.Should().BeEmpty();
observableDictionary.Count.Should().Be(amountOfItemsToAdd);
foreach (var keyValuePair in keyValuePairs)
{
observableDictionary.Should().Contain(keyValuePair);
}
}
}
示例8: TryAddDoesNotAddExistingItem
public void TryAddDoesNotAddExistingItem()
{
// given
var initialKvPs = new List<KeyValuePair<int, string>>()
{
new KeyValuePair<int, string>(1, "One")
};
using (var observableDictionary = new ObservableDictionary<int, string>(initialKvPs))
{
// when
var tryAddResult = observableDictionary.TryAdd(1, "Two");
// then check whether all items have been accounted for
tryAddResult.Should().Be(false);
observableDictionary.Count.Should().Be(1);
observableDictionary.Should().Contain(1, "One");
}
}
示例9: TryUpdateUpdatesExistingItem
public void TryUpdateUpdatesExistingItem()
{
// given
var initialKvPs = new List<KeyValuePair<int, string>>()
{
new KeyValuePair<int, string>(1, "One")
};
using (var observableDictionary = new ObservableDictionary<int, string>(initialKvPs))
{
// when
var updateResult = observableDictionary.TryUpdate(1, "Two");
// then
updateResult.Should().Be(true);
observableDictionary.Count.Should().Be(1);
observableDictionary.Should().Contain(1, "Two");
observableDictionary.Keys.Should().Contain(1);
observableDictionary.Values.Should().NotContain("One");
observableDictionary.Values.Should().Contain("Two");
}
}
示例10: TryUpdateDoesNotUpdateNonExistingItem
public void TryUpdateDoesNotUpdateNonExistingItem()
{
// given
var initialKvPs = new List<KeyValuePair<int, string>>()
{
new KeyValuePair<int, string>(1, "One")
};
using (var observableDictionary = new ObservableDictionary<int, string>(initialKvPs))
{
// when
var updateResult = observableDictionary.TryUpdate(2, "One");
// then
updateResult.Should().Be(false);
observableDictionary.Count.Should().Be(1);
observableDictionary.Should().Contain(1, "One");
}
}
示例11: TryRemoveRangeOfKeyValuePairsRemovesExistingItemsAndReportsNonremovablesBack
public void TryRemoveRangeOfKeyValuePairsRemovesExistingItemsAndReportsNonremovablesBack()
{
// given
var keyValuePairs = Enumerable.Range(0, 100)
.Select(i => new KeyValuePair<int, string>(i, $"#{i}"))
.ToList();
var keyValuePairsToRemove = Enumerable.Range(50, 100)
.Select(i => new KeyValuePair<int, string>(i, $"#{i}"))
.ToList();
using (var observableDictionary = new ObservableDictionary<int, string>(keyValuePairs))
{
// when
IDictionary<int, string> nonRemovedKeyValuePairs;
var tryRemoveResult = observableDictionary.TryRemoveRange(keyValuePairsToRemove, out nonRemovedKeyValuePairs);
// then check whether all items have been accounted for
tryRemoveResult.Should().Be(false);
nonRemovedKeyValuePairs.Should().NotBeNull();
nonRemovedKeyValuePairs.Should().NotBeEmpty();
nonRemovedKeyValuePairs.Count.Should().Be(50);
observableDictionary.Count.Should().Be(50);
// check whether everything that was reported as removable is removed
foreach (var keyValuePair in keyValuePairsToRemove.Except(nonRemovedKeyValuePairs))
{
observableDictionary.Should().NotContain(keyValuePair);
}
foreach (var keyValuePair in nonRemovedKeyValuePairs)
{
observableDictionary.Should().NotContain(keyValuePair);
}
// and check whether all other one(s) are still there, too
foreach (var keyValuePair in keyValuePairs.Except(keyValuePairsToRemove))
{
observableDictionary.Should().Contain(keyValuePair);
}
}
}
示例12: TryRemoveRangeOfKeyValuePairsForCornerCasesRemovesExistingItemsAndReportsNonremovablesBack
public void TryRemoveRangeOfKeyValuePairsForCornerCasesRemovesExistingItemsAndReportsNonremovablesBack(int initialAmountOfItems, int amountOfItemsToRemove)
{
// given
var keyValuePairs = Enumerable.Range(0, initialAmountOfItems)
.Select(i => new KeyValuePair<int, string>(i, $"#{i}"))
.ToList();
var keyValuePairsToRemove = Enumerable.Range(0, amountOfItemsToRemove)
.Select(i => new KeyValuePair<int, string>(i, $"#{i}"))
.ToList();
using (var observableDictionary = new ObservableDictionary<int, string>(keyValuePairs))
{
// when
IDictionary<int, string> nonRemovedKeyValuePairs;
var tryRemoveResult = observableDictionary.TryRemoveRange(keyValuePairsToRemove, out nonRemovedKeyValuePairs);
// then check whether all items have been accounted for
tryRemoveResult.Should().Be(false);
nonRemovedKeyValuePairs.Should().NotBeNull();
nonRemovedKeyValuePairs.Should().NotBeEmpty();
observableDictionary.Count.Should().Be(initialAmountOfItems - amountOfItemsToRemove + nonRemovedKeyValuePairs.Count);
// check whether everything that was reported as removable is removed
foreach (var keyValuePair in keyValuePairsToRemove.Except(nonRemovedKeyValuePairs))
{
observableDictionary.Should().NotContain(keyValuePair);
}
foreach (var keyValuePair in nonRemovedKeyValuePairs)
{
observableDictionary.Should().NotContain(keyValuePair);
}
}
}
示例13: AddOrUpdateShouldAllowAddWithDefaultValue
public void AddOrUpdateShouldAllowAddWithDefaultValue()
{
// given
using (var observableDictionary = new ObservableDictionary<string, string>())
{
// when
Action action = () => observableDictionary.AddOrUpdate("1", default(string));
// then
action.ShouldNotThrow<ArgumentNullException>();
observableDictionary.Count.Should().Be(1);
observableDictionary.Should().Contain("1", default(string));
}
}
示例14: RemoveOfCollectionOfKeyValuePairsRemovesExistingItem
public void RemoveOfCollectionOfKeyValuePairsRemovesExistingItem()
{
// given
var initialKvPs = new List<KeyValuePair<int, string>>()
{
new KeyValuePair<int, string>(1, "One")
};
using (var observableDictionary = new ObservableDictionary<int, string>(initialKvPs))
{
// when
((ICollection<KeyValuePair<int, string>>) observableDictionary).Remove(new KeyValuePair<int, string>(1, "One"));
// then check whether all items have been accounted for
observableDictionary.Count.Should().Be(0);
observableDictionary.Should().NotContain(1, "One");
}
}
示例15: ResetDoesNotModifyDictionary
public void ResetDoesNotModifyDictionary()
{
// given
var initialKvPs = new List<KeyValuePair<int, string>>()
{
new KeyValuePair<int, string>(1, "One"),
new KeyValuePair<int, string>(2, "Two")
};
using (var observableDictionary = new ObservableDictionary<int, string>(initialKvPs))
{
// when
observableDictionary.Reset();
// then
observableDictionary.Count.Should().Be(2);
observableDictionary.Should().Contain(1, "One");
observableDictionary.Should().Contain(2, "Two");
}
}