Пример #1
0
        public void DoesNotUsePolicyWhenPassedExistingObject()
        {
            object             existing = new object();
            MockBuilderContext context  = CreateContext();
            StubCreationPolicy policy   = new StubCreationPolicy();

            context.Policies.SetDefault <ICreationPolicy>(policy);

            object result = context.HeadOfChain.BuildUp(context, typeof(object), existing);

            Assert.False(policy.Create__Called);
            Assert.Same(existing, result);
        }
Пример #2
0
        public void UsesPolicyToCreateObject()
        {
            object             obj     = new object();
            MockBuilderContext context = CreateContext();
            StubCreationPolicy policy  = new StubCreationPolicy();

            policy.Create__Result = obj;
            context.Policies.SetDefault <ICreationPolicy>(policy);

            object result = context.HeadOfChain.BuildUp(context, typeof(object), null);

            Assert.True(policy.Create__Called);
            Assert.Same(context, policy.Create_Context);
            Assert.Same(typeof(object), policy.Create_BuildKey);
            Assert.Same(obj, result);
        }