本文整理汇总了C#中Scope.SetItem方法的典型用法代码示例。如果您正苦于以下问题:C# Scope.SetItem方法的具体用法?C# Scope.SetItem怎么用?C# Scope.SetItem使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Scope
的用法示例。
在下文中一共展示了Scope.SetItem方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetItem_WithValueSetTwice_ReturnsLastItem
public void GetItem_WithValueSetTwice_ReturnsLastItem()
{
// Arrange
object key = new object();
object firstItem = new object();
object expectedItem = new object();
var scope = new Scope(new Container());
scope.SetItem(key, firstItem);
scope.SetItem(key, expectedItem);
// Act
object actualItem = scope.GetItem(key);
// Assert
Assert.AreSame(expectedItem, actualItem);
}
示例2: GetItem_WithValueSetInOneContainer_DoesNotReturnThatItemInAnotherContainer
public void GetItem_WithValueSetInOneContainer_DoesNotReturnThatItemInAnotherContainer()
{
// Arrange
object key = new object();
object expectedItem = new object();
var container = new Container();
var scope1 = new Scope(container);
var scope2 = new Scope(container);
scope1.SetItem(key, expectedItem);
// Act
object actualItem = scope2.GetItem(key);
// Assert
Assert.IsNull(actualItem, "The items dictionary is expected to be bound to the scope. Not the container!");
}
示例3: GetItem_WithValueReset_ReturnsNull
public void GetItem_WithValueReset_ReturnsNull()
{
// Arrange
object key = new object();
var scope = new Scope(new Container());
scope.SetItem(key, new object());
scope.SetItem(key, null);
// Act
object item = scope.GetItem(key);
// Assert
// This test looks odd, but under the cover the item is removed from the collection when null
// is supplied to prevent the dictionary from ever increasing, but we have to test this code path.
Assert.IsNull(item, "When a value is overridden with null, it is expected to return null.");
}
示例4: SetItem_WithNullKey_ThrowsException
public void SetItem_WithNullKey_ThrowsException()
{
// Arrange
var scope = new Scope(new Container());
// Act
Action action = () => scope.SetItem(null, new object());
// Assert
AssertThat.Throws<ArgumentNullException>(action);
}