コード例 #1
0
        public void ClassMemberInAutoServiceIfStatement()
        {
            var appIds          = DiContainer.Resolve <IAppIds>();
            var appIdToPriority = DiContainer.Resolve <IAppIdToPriority>();

            // Test IAppIds.DefaultAppId in if element.
            Assert.AreEqual(14, appIdToPriority.GetPriority(appIds.DefaultAppId));

            // Test IAppIds.GetAppId in if element.
            Assert.AreEqual(25, appIdToPriority.GetPriority(appIds.GetAppId()));

            // Test AppIdVars.NonStaticAppIdVar in if element.
            // Note, no binding was provided for AppIdVars (non-interface and n on abstract class with public constructor).
            // IoC.Configuration generated one, since it is used in classMember element.
            var appIdVars = DiContainer.Resolve <AppIdVars>();

            Assert.AreEqual(23, appIdToPriority.GetPriority(appIdVars.NonStaticAppIdVar));

            // Test constant value ConstAndStaticAppIds.AppId1 in if element.
            Assert.AreEqual(4, appIdToPriority.GetPriority(ConstAndStaticAppIds.AppId1));

            // Test static value ConstAndStaticAppIds.AppId2 in if element.
            Assert.AreEqual(7, appIdToPriority.GetPriority(ConstAndStaticAppIds.AppId2));

            // Test static property ConstAndStaticAppIds.AppId3 in if element.
            Assert.AreEqual(8, appIdToPriority.GetPriority(ConstAndStaticAppIds.AppId3));

            // Test static method ConstAndStaticAppIds.GetAppId4() in if element.
            Assert.AreEqual(5, appIdToPriority.GetPriority(ConstAndStaticAppIds.GetAppId4()));

            // Test default priority
            Assert.AreEqual(0, appIdToPriority.GetPriority(-1));
        }
コード例 #2
0
        public void ClassMemberInParameterInjectedPropertyEtc()
        {
            var appIds   = DiContainer.Resolve <IAppIds>();
            var appInfos = DiContainer.Resolve <IAppInfos>();

            // Test IAppIds.DefaultAppId injected into constructor
            Assert.AreEqual(appIds.DefaultAppId, appInfos.AllAppInfos[0].AppId);

            // Test IAppIds.DefaultAppDescription injected into property
            Assert.AreEqual(appIds.DefaultAppDescription, appInfos.AllAppInfos[0].AppDescription);

            // Test call to a non-static method with parameters
            Assert.AreEqual(1258, appInfos.AllAppInfos[1].AppId);
            Assert.AreEqual("App info created with non-static method call.", appInfos.AllAppInfos[1].AppDescription);

            // Test call to a static method with parameters
            Assert.AreEqual(1259, appInfos.AllAppInfos[2].AppId);
            Assert.AreEqual("App info created with static method call.", appInfos.AllAppInfos[2].AppDescription);


            // Test IAppIds.GetAppId() injected into constructor
            Assert.AreEqual(appIds.GetAppId(), appInfos.AllAppInfos[3].AppId);

            // Test IoC.Configuration.Tests.ClassMember.Services.AppIdVars injected into constructor
            // Note, no binding was provided for AppIdVars (non-interface and n on abstract class with public constructor).
            // IoC.Configuration generated one, since it is used in classMember element.
            Assert.AreEqual(DiContainer.Resolve <AppIdVars>().NonStaticAppIdVar, appInfos.AllAppInfos[4].AppId);

            // Test constant variable ConstAndStaticAppIds.AppId1 used in classMember element as constructor parameter
            Assert.AreEqual(ConstAndStaticAppIds.AppId1, appInfos.AllAppInfos[5].AppId);

            // Test constant variable ConstAndStaticAppIds.AppId1 used in classMember element as constructor parameter
            Assert.AreEqual(ConstAndStaticAppIds.App1Description, appInfos.AllAppInfos[5].AppDescription);

            // Test static variable ConstAndStaticAppIds.AppId1 used in classMember element as constructor parameter
            Assert.AreEqual(ConstAndStaticAppIds.AppId2, appInfos.AllAppInfos[6].AppId);

            // Test static variable ConstAndStaticAppIds.AppId1 used in classMember element as constructor parameter
            Assert.AreEqual(ConstAndStaticAppIds.App2Description, appInfos.AllAppInfos[6].AppDescription);

            // Test static property ConstAndStaticAppIds.AppId3 used in classMember element as constructor parameter
            Assert.AreEqual(ConstAndStaticAppIds.AppId3, appInfos.AllAppInfos[7].AppId);

            // Test static method ConstAndStaticAppIds.GetApp3Description() used in classMember element as constructor parameter
            Assert.AreEqual(ConstAndStaticAppIds.GetApp3Description(), appInfos.AllAppInfos[7].AppDescription);

            // Test static method ConstAndStaticAppIds.GetAppId4 used in classMember element as constructor parameter
            Assert.AreEqual(ConstAndStaticAppIds.GetAppId4(), appInfos.AllAppInfos[8].AppId);

            // Test enum value IoC.Configuration.Tests.ClassMember.Services.AppTypes.App1 used in classMember element as constructor parameter
            Assert.AreEqual((int)AppTypes.App1, appInfos.AllAppInfos[9].AppId);
        }