public void AddPolicy(bool isEnabled, bool isTypeSet, bool expectedAdded)
        {
            var policyCache = new ResourceTriggerFilterPolicyCache(new List <IFilteredTargetHandlerFactory>());

            ResourceTriggerFilterDef policy = CreateDummyPolicy();

            policy.TriggerEnabled = isEnabled;

            if (!isTypeSet)
            {
                policy.TriggeredOnType = null;
            }

            policyCache.UpdateOrAddPolicy(policy);

            if (expectedAdded)
            {
                Assert.That(policyCache.PolicyToFieldsMap.ContainsKey(policy.Id), Is.True);
                Assert.That(policyCache.TypePolicyMap.ContainsKey(policy.TriggeredOnType.Id), Is.True);
            }
            else
            {
                Assert.That(policyCache.PolicyToFieldsMap, Is.Empty);
                Assert.That(policyCache.TypePolicyMap, Is.Empty);
            }
        }
        public void CacheCleanedWhenPolicyDisabled()
        {
            ResourceTriggerFilterDef policy = CreateDummyPolicy();

            var policyCache = new ResourceTriggerFilterPolicyCache(new List <IFilteredTargetHandlerFactory>());

            policyCache.UpdateOrAddPolicy(policy);

            policy = policy.AsWritable <ResourceTriggerFilterDef>();
            policy.TriggerEnabled = false;

            policyCache.UpdateOrAddPolicy(policy);

            Assert.That(policyCache.PolicyToFieldsMap.ContainsKey(policy.Id), Is.False);

            var policies = policyCache.TypePolicyMap[policy.TriggeredOnType.Id];

            Assert.That(policies.FirstOrDefault(p => p.Id == policy.Id), Is.Null);
        }