当前位置: 首页>>代码示例>>C#>>正文


C# Scope.SetItem方法代码示例

本文整理汇总了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);
        }
开发者ID:BrettJaner,项目名称:SimpleInjector,代码行数:18,代码来源:ScopeTests.cs

示例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!");
        }
开发者ID:BrettJaner,项目名称:SimpleInjector,代码行数:18,代码来源:ScopeTests.cs

示例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.");
        }
开发者ID:BrettJaner,项目名称:SimpleInjector,代码行数:18,代码来源:ScopeTests.cs

示例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);
        }
开发者ID:BrettJaner,项目名称:SimpleInjector,代码行数:11,代码来源:ScopeTests.cs


注:本文中的Scope.SetItem方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。