本文整理汇总了C#中Scope.GetItem方法的典型用法代码示例。如果您正苦于以下问题:C# Scope.GetItem方法的具体用法?C# Scope.GetItem怎么用?C# Scope.GetItem使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Scope
的用法示例。
在下文中一共展示了Scope.GetItem方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetItem_NoValueSet_ReturnsNull
public void GetItem_NoValueSet_ReturnsNull()
{
// Arrange
object key = new object();
var scope = new Scope(new Container());
// Act
object item = scope.GetItem(key);
// Assert
Assert.IsNull(item);
}
示例2: GetItem_WithValueSet_ReturnsThatItem
public void GetItem_WithValueSet_ReturnsThatItem()
{
// Arrange
object key = new object();
object expectedItem = new object();
var scope = new Scope(new Container());
scope.SetItem(key, expectedItem);
// Act
object actualItem = scope.GetItem(key);
// Assert
Assert.AreSame(expectedItem, actualItem);
}
示例3: 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!");
}
示例4: 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.");
}
示例5: GetItem_WithNullKey_ThrowsException
public void GetItem_WithNullKey_ThrowsException()
{
// Arrange
var scope = new Scope(new Container());
// Act
Action action = () => scope.GetItem(null);
// Assert
AssertThat.Throws<ArgumentNullException>(action);
}