本文整理汇总了C#中ObservableDictionary.AddOrUpdate方法的典型用法代码示例。如果您正苦于以下问题:C# ObservableDictionary.AddOrUpdate方法的具体用法?C# ObservableDictionary.AddOrUpdate怎么用?C# ObservableDictionary.AddOrUpdate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ObservableDictionary
的用法示例。
在下文中一共展示了ObservableDictionary.AddOrUpdate方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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");
}
}
示例2: 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");
}
}
示例3: AddOrUpdateShouldAllowUpdateWithDefaultValue
public void AddOrUpdateShouldAllowUpdateWithDefaultValue()
{
// given
var initialKvPs = new List<KeyValuePair<string, string>>()
{
new KeyValuePair<string, string>("1", "One Value")
};
using (var observableDictionary = new ObservableDictionary<string, string>(initialKvPs))
{
// when
Action action = () => observableDictionary.AddOrUpdate("1", default(string));
// then
action.ShouldNotThrow<ArgumentNullException>();
observableDictionary.Count.Should().Be(1);
observableDictionary.Should().Contain("1", default(string));
}
}
示例4: AddOrUpdateThrowsOnNullKey
public void AddOrUpdateThrowsOnNullKey()
{
// given
using (var observableDictionary = new ObservableDictionary<string, string>())
{
// when
Action action = () => observableDictionary.AddOrUpdate(null, null);
// then
action
.ShouldThrow<ArgumentNullException>()
.WithMessage("Value cannot be null.\r\nParameter name: key");
observableDictionary.Count.Should().Be(0);
}
}
示例5: 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));
}
}