Beispiel #1
0
        public void LiteContainer_RegisterSingleton_ReturnsSameReference()
        {
            var c = new LiteContainer();

            c.RegisterSingleton(() => new Number(3));

            var instance1 = c.Resolve <Number>();
            var instance2 = c.Resolve <Number>();

            Assert.IsTrue(ReferenceEquals(instance1, instance2));
        }
Beispiel #2
0
        public void LiteContainer_ResolveTypeAsInterface_CanResolveType()
        {
            var c = new LiteContainer();

            c.Register <Person>(() => new Student("Jim"));

            var instance = c.Resolve <Person>();

            Assert.AreEqual("Jim", instance.Name);
        }
Beispiel #3
0
        public void LiteContainer_ResolveConcreteRegisteredType_TypeIsCorrect()
        {
            var c = new LiteContainer();

            c.Register(() => new Number(2));

            var instance = c.Resolve <Number>();

            Assert.AreEqual(2, instance.Value);
        }
Beispiel #4
0
        public void LiteContainer_ResolveUnknownInterfaceType_ThrowsKeyNotFoundException()
        {
            var c = new LiteContainer();

            AssertThrowsExceptionOfType <KeyNotFoundException>(() => c.Resolve <Person>());
        }
Beispiel #5
0
        public void LiteContainer_ResolveUnknownConcreteType_ThrowsKeyNotFoundException()
        {
            var c = new LiteContainer();

            AssertThrowsExceptionOfType <KeyNotFoundException>(() => c.Resolve <Number>());
        }