コード例 #1
0
        void TestTrigger(TestHandler testHandler,
                         Action <ResourceTriggerFilterDef> configurePolicyAction,
                         Action <ResourceTriggerFilterDef> doStuff)
        {
            var dummyPolicyType = Entity.Create <EntityType>();

            dummyPolicyType.Name = "ResourceTriggerFilterTest type";
            dummyPolicyType.Inherits.Add(Entity.Get <EntityType>("core:resourceTriggerFilterDef"));
            dummyPolicyType.Save();
            _toDelete.Add(dummyPolicyType.Id);

            var factory = new TestFactory(dummyPolicyType, testHandler);

            var policyCache = new ResourceTriggerFilterPolicyCache(factory.ToEnumerable());

            using (var scope = Factory.Current.BeginLifetimeScope(builder =>
            {
                builder.Register(ctx => factory).As <IFilteredTargetHandlerFactory>();
                builder.Register(ctx => policyCache).As <IResourceTriggerFilterPolicyCache>();
            }))
                using (Factory.SetCurrentScope(scope))
                {
                    var dummyTriggerType = Entity.Create <EntityType>();
                    dummyTriggerType.Save();
                    _toDelete.Add(dummyTriggerType.Id);

                    var policy = Entity.Create(dummyPolicyType.Id).As <ResourceTriggerFilterDef>();
                    policy.TriggerEnabled  = true;
                    policy.TriggeredOnType = dummyTriggerType;
                    policy.Save();
                    _toDelete.Add(policy.Id);

                    configurePolicyAction(policy);

                    testHandler.Clear();

                    doStuff(policy);

                    testHandler.Check();
                }
        }