예제 #1
0
        public void CanAddMultiplePoliciesToBagAndRetrieveThem()
        {
            PolicyList list    = new PolicyList();
            FakePolicy policy1 = new FakePolicy();
            FakePolicy policy2 = new FakePolicy();

            list.Set <IBuilderPolicy>(policy1, "1");
            list.Set <IBuilderPolicy>(policy2, "2");

            Assert.AreSame(policy1, list.Get <IBuilderPolicy>("1"));
            Assert.AreSame(policy2, list.Get <IBuilderPolicy>("2"));
        }
예제 #2
0
        public void CanAddMultiplePoliciesToBagAndRetrieveThem()
        {
            PolicyList list = new PolicyList();
            MockPolicy policy1 = new MockPolicy();
            MockPolicy policy2 = new MockPolicy();

            list.Set<IBuilderPolicy>(policy1, typeof(object), "1");
            list.Set<IBuilderPolicy>(policy2, typeof(string), "2");

            Assert.AreSame(policy1, list.Get<IBuilderPolicy>(typeof(object), "1"));
            Assert.AreSame(policy2, list.Get<IBuilderPolicy>(typeof(string), "2"));
        }
예제 #3
0
        public void CanAddMultiplePoliciesToBagAndRetrieveThem()
        {
            PolicyList list    = new PolicyList();
            MockPolicy policy1 = new MockPolicy();
            MockPolicy policy2 = new MockPolicy();

            list.Set <IBuilderPolicy>(policy1, typeof(object), "1");
            list.Set <IBuilderPolicy>(policy2, typeof(string), "2");

            Assert.AreSame(policy1, list.Get <IBuilderPolicy>(typeof(object), "1"));
            Assert.AreSame(policy2, list.Get <IBuilderPolicy>(typeof(string), "2"));
        }
예제 #4
0
        EventBrokerPolicy GetEventBrokerPolicy(Type type)
        {
            EventBrokerPolicy policy = (EventBrokerPolicy)policies.Get <IEventBrokerPolicy>(type);

            if (policy == null)
            {
                policy = new EventBrokerPolicy();
                policies.Set <IEventBrokerPolicy>(policy, type);
            }

            return(policy);
        }
예제 #5
0
        public void CanClearAllPolicies()
        {
            PolicyList list = new PolicyList();

            list.Set <IBuilderPolicy>(new FakePolicy(), "1");
            list.Set <IBuilderPolicy>(new FakePolicy(), "2");

            Assert.IsNotNull(list.Get <IBuilderPolicy>("1"));
            Assert.IsNotNull(list.Get <IBuilderPolicy>("2"));

            list.ClearAll();

            Assert.IsNull(list.Get <IBuilderPolicy>("1"));
            Assert.IsNull(list.Get <IBuilderPolicy>("2"));
        }
예제 #6
0
        public void CanAddPolicyToBagAndRetrieveIt()
        {
            PolicyList list = new PolicyList();

            list.Set<IBuilderPolicy>(new MockPolicy(), typeof(object), null);

            Assert.IsNotNull(list.Get<IBuilderPolicy>(typeof(object), null));
        }
예제 #7
0
        public void CanAddPolicyToBagAndRetrieveIt()
        {
            PolicyList list = new PolicyList();

            list.Set <IBuilderPolicy>(new MockPolicy(), typeof(object), null);

            Assert.IsNotNull(list.Get <IBuilderPolicy>(typeof(object), null));
        }
예제 #8
0
        public void DefaultPolicyUsedWhenSpecificPolicyIsntAvailable()
        {
            PolicyList list          = new PolicyList();
            MockPolicy defaultPolicy = new MockPolicy();

            list.SetDefault <IBuilderPolicy>(defaultPolicy);

            Assert.AreSame(defaultPolicy, list.Get <IBuilderPolicy>(typeof(object), null));
        }
예제 #9
0
        public void CanClearDefaultPolicy()
        {
            PolicyList list = new PolicyList();
            MockPolicy defaultPolicy = new MockPolicy();
            list.SetDefault<IBuilderPolicy>(defaultPolicy);

            list.ClearDefault<IBuilderPolicy>();

            Assert.IsNull(list.Get<IBuilderPolicy>(typeof(object), null));
        }
예제 #10
0
		public void CanClearPolicy()
		{
			PolicyList list = new PolicyList();
			MockPolicy policy = new MockPolicy();

			list.Set<IBuilderPolicy>(policy, typeof(string), "1");
			list.Clear<IBuilderPolicy>(typeof(string), "1");

			Assert.IsNull(list.Get<IBuilderPolicy>(typeof(string), "1"));
		}
예제 #11
0
        public void CanClearPolicy()
        {
            PolicyList list   = new PolicyList();
            FakePolicy policy = new FakePolicy();

            list.Set <IBuilderPolicy>(policy, typeof(string));
            list.Clear <IBuilderPolicy>(typeof(string));

            Assert.IsNull(list.Get <IBuilderPolicy>(typeof(string)));
        }
예제 #12
0
		public void SetOverwritesExistingPolicy()
		{
			PolicyList list = new PolicyList();
			MockPolicy policy1 = new MockPolicy();
			MockPolicy policy2 = new MockPolicy();

			list.Set<IBuilderPolicy>(policy1, typeof(string), "1");
			list.Set<IBuilderPolicy>(policy2, typeof(string), "1");

			Assert.AreSame(policy2, list.Get<IBuilderPolicy>(typeof(string), "1"));
		}
예제 #13
0
        public void SetOverwritesExistingPolicy()
        {
            PolicyList list    = new PolicyList();
            MockPolicy policy1 = new MockPolicy();
            MockPolicy policy2 = new MockPolicy();

            list.Set <IBuilderPolicy>(policy1, typeof(string), "1");
            list.Set <IBuilderPolicy>(policy2, typeof(string), "1");

            Assert.AreSame(policy2, list.Get <IBuilderPolicy>(typeof(string), "1"));
        }
예제 #14
0
        public void CanClearDefaultPolicy()
        {
            PolicyList list          = new PolicyList();
            MockPolicy defaultPolicy = new MockPolicy();

            list.SetDefault <IBuilderPolicy>(defaultPolicy);

            list.ClearDefault <IBuilderPolicy>();

            Assert.IsNull(list.Get <IBuilderPolicy>(typeof(object), null));
        }
예제 #15
0
        public void SpecificPolicyOverridesDefaultPolicy()
        {
            PolicyList list           = new PolicyList();
            MockPolicy defaultPolicy  = new MockPolicy();
            MockPolicy specificPolicy = new MockPolicy();

            list.Set <IBuilderPolicy>(specificPolicy, typeof(object), null);
            list.SetDefault <IBuilderPolicy>(defaultPolicy);

            Assert.AreSame(specificPolicy, list.Get <IBuilderPolicy>(typeof(object), null));
        }
예제 #16
0
        public void PolicyRegisteredForTypeIsUsedIfKeyIsNotFound()
        {
            PolicyList list          = new PolicyList();
            FakePolicy policyForType = new FakePolicy();

            list.Set <IBuilderPolicy>(policyForType, typeof(object));

            IBuilderPolicy result = list.Get <IBuilderPolicy>(new NamedTypeBuildKey <object>("name"));

            Assert.Same(policyForType, result);
        }
예제 #17
0
        public void CanRegisterGenericPolicyAndRetrieveWithSpecificGenericInstance()
        {
            PolicyList list   = new PolicyList();
            FakePolicy policy = new FakePolicy();

            list.Set(policy, typeof(IDummy <>));

            FakePolicy result = list.Get <FakePolicy>(typeof(IDummy <int>));

            Assert.AreSame(policy, result);
        }
예제 #18
0
        public void DefaultPolicyUsedWhenSpecificPolicyIsntAvailable()
        {
            PolicyList list          = new PolicyList();
            FakePolicy defaultPolicy = new FakePolicy();

            list.SetDefault <IBuilderPolicy>(defaultPolicy);

            IBuilderPolicy result = list.Get <IBuilderPolicy>(typeof(object));

            Assert.AreSame(defaultPolicy, result);
        }
예제 #19
0
        public void CanAddPolicyToBagAndRetrieveIt()
        {
            PolicyList list   = new PolicyList();
            FakePolicy policy = new FakePolicy();

            list.Set <IBuilderPolicy>(policy, typeof(object));

            IBuilderPolicy result = list.Get <IBuilderPolicy>(typeof(object));

            Assert.AreSame(policy, result);
        }
예제 #20
0
        public void PolicyRegisteredForOpenGenericTypeUsedIfKeyIsNotFound()
        {
            PolicyList list          = new PolicyList();
            FakePolicy policyForType = new FakePolicy();

            list.Set <IBuilderPolicy>(policyForType, typeof(IDummy <>));

            IBuilderPolicy result = list.Get <IBuilderPolicy>(new NamedTypeBuildKey <IDummy <object> >("name"));

            Assert.AreSame(policyForType, result);
        }
예제 #21
0
        public void CanGetLocalPolicy()
        {
            PolicyList innerList   = new PolicyList();
            PolicyList outerList   = new PolicyList(innerList);
            FakePolicy innerPolicy = new FakePolicy();

            innerList.Set(innerPolicy, typeof(object));

            FakePolicy result = outerList.Get <FakePolicy>(typeof(object), true);

            Assert.IsNull(result);
        }
예제 #22
0
        public void WillUseInnerDefaultPolicyWhenOuterHasNoAnswer()
        {
            PolicyList innerList = new PolicyList();
            PolicyList outerList = new PolicyList(innerList);
            FakePolicy policy    = new FakePolicy();

            innerList.SetDefault(policy);

            FakePolicy result = outerList.Get <FakePolicy>(typeof(object));

            Assert.AreSame(policy, result);
        }
예제 #23
0
        public void CanClearDefaultPolicy()
        {
            PolicyList list          = new PolicyList();
            FakePolicy defaultPolicy = new FakePolicy();

            list.SetDefault <IBuilderPolicy>(defaultPolicy);

            list.ClearDefault <IBuilderPolicy>();

            IBuilderPolicy result = list.Get <IBuilderPolicy>(typeof(object));

            Assert.IsNull(result);
        }
예제 #24
0
        public void SpecificPolicyOverridesDefaultPolicy()
        {
            PolicyList list           = new PolicyList();
            FakePolicy defaultPolicy  = new FakePolicy();
            FakePolicy specificPolicy = new FakePolicy();

            list.Set <IBuilderPolicy>(specificPolicy, typeof(object));
            list.SetDefault <IBuilderPolicy>(defaultPolicy);

            IBuilderPolicy result = list.Get <IBuilderPolicy>(typeof(object));

            Assert.AreSame(specificPolicy, result);
        }
예제 #25
0
        public void SpecificGenericPolicyComesBeforeGenericPolicy()
        {
            PolicyList list           = new PolicyList();
            FakePolicy genericPolicy  = new FakePolicy();
            FakePolicy specificPolicy = new FakePolicy();

            list.Set(genericPolicy, typeof(IDummy <>));
            list.Set(specificPolicy, typeof(IDummy <int>));

            FakePolicy result = list.Get <FakePolicy>(typeof(IDummy <int>));

            Assert.AreSame(specificPolicy, result);
        }
예제 #26
0
        public void SetOverwritesExistingPolicy()
        {
            PolicyList list    = new PolicyList();
            FakePolicy policy1 = new FakePolicy();
            FakePolicy policy2 = new FakePolicy();

            list.Set <IBuilderPolicy>(policy1, typeof(string));
            list.Set <IBuilderPolicy>(policy2, typeof(string));

            IBuilderPolicy result = list.Get <IBuilderPolicy>(typeof(string));

            Assert.AreSame(policy2, result);
        }
예제 #27
0
        public void PolicyForClosedGenericTypeOverridesPolicyForOpenType()
        {
            PolicyList list             = new PolicyList();
            FakePolicy openTypePolicy   = new FakePolicy();
            FakePolicy closedTypePolicy = new FakePolicy();

            list.Set <IBuilderPolicy>(openTypePolicy, typeof(IDummy <>));
            list.Set <IBuilderPolicy>(closedTypePolicy, typeof(IDummy <object>));

            IBuilderPolicy result = list.Get <IBuilderPolicy>(new NamedTypeBuildKey <IDummy <object> >("name"));

            Assert.AreSame(closedTypePolicy, result);
        }
예제 #28
0
        public void SpecificInnerPolicyOverridesDefaultOuterPolicy()
        {
            PolicyList innerList   = new PolicyList();
            PolicyList outerList   = new PolicyList(innerList);
            FakePolicy innerPolicy = new FakePolicy();
            FakePolicy outerPolicy = new FakePolicy();

            innerList.Set(innerPolicy, typeof(object));
            outerList.SetDefault(outerPolicy);

            FakePolicy result = outerList.Get <FakePolicy>(typeof(object));

            Assert.AreSame(innerPolicy, result);
        }
예제 #29
0
        public void WillAskInnerPolicyListWhenOuterHasNoAnswer()
        {
            PolicyList innerList = new PolicyList();
            PolicyList outerList = new PolicyList(innerList);
            FakePolicy policy    = new FakePolicy();

            innerList.Set(policy, typeof(object));

            IPolicyList containingPolicies;
            FakePolicy  result = outerList.Get <FakePolicy>(typeof(object), out containingPolicies);

            Assert.AreSame(policy, result);
            Assert.AreSame(innerList, containingPolicies);
        }
예제 #30
0
        public void OuterPolicyOverridesInnerPolicy()
        {
            PolicyList innerList   = new PolicyList();
            PolicyList outerList   = new PolicyList(innerList);
            FakePolicy innerPolicy = new FakePolicy();
            FakePolicy outerPolicy = new FakePolicy();

            innerList.Set(innerPolicy, typeof(object));
            outerList.Set(outerPolicy, typeof(object));

            IPolicyList containingPolicyList;
            FakePolicy  result = outerList.Get <FakePolicy>(typeof(object), out containingPolicyList);

            Assert.AreSame(outerPolicy, result);
            Assert.AreSame(outerList, containingPolicyList);
        }
예제 #31
0
        public void SpecificPolicyOverridesDefaultPolicy()
        {
            PolicyList list = new PolicyList();
            MockPolicy defaultPolicy = new MockPolicy();
            MockPolicy specificPolicy = new MockPolicy();

            list.Set<IBuilderPolicy>(specificPolicy, typeof(object), null);
            list.SetDefault<IBuilderPolicy>(defaultPolicy);

            Assert.AreSame(specificPolicy, list.Get<IBuilderPolicy>(typeof(object), null));
        }
예제 #32
0
        public void DefaultPolicyUsedWhenSpecificPolicyIsntAvailable()
        {
            PolicyList list = new PolicyList();
            MockPolicy defaultPolicy = new MockPolicy();

            list.SetDefault<IBuilderPolicy>(defaultPolicy);

            Assert.AreSame(defaultPolicy, list.Get<IBuilderPolicy>(typeof(object), null));
        }