Beispiel #1
0
        public void Container_RegisterSingleton_Returns_Null_If_Container_Disposed()
        {
            //Arrange
            var container = new Container();
            var mock = new Mock<IDisposable>();
            var inst = mock.Object;

            //Act
            container.RegisterSingleton(typeof(IDisposable), "key", inst);
            container.Dispose();
            var inst1 = container.GetInstance<IDisposable>("key");

            //Assert
            Assert.IsNull(inst1);
        }
Beispiel #2
0
        public void Container_RegisterSingleton_Returns_Same_Instance()
        {
            //Arrange
            var container = new Container();
            var mock = new Mock<IService>();
            var inst = mock.Object;

            //Act
            container.RegisterSingleton(typeof(IService), "key", inst);
            var inst1 = container.GetInstance<IService>("key");
            var inst2 = container.GetInstance<IService>("key");

            //Assert
            Assert.AreSame(inst, inst1);
            Assert.AreSame(inst, inst2);
        }