Пример #1
0
 public FakeObjectCreator(
     FakeCallProcessorProvider.Factory fakeCallProcessorProviderFactory,
     IMethodInterceptionValidator castleMethodInterceptionValidator,
     IMethodInterceptionValidator delegateMethodInterceptionValidator)
 {
     this.defaultCreationStrategy  = new DefaultCreationStrategy(castleMethodInterceptionValidator, fakeCallProcessorProviderFactory);
     this.delegateCreationStrategy = new DelegateCreationStrategy(delegateMethodInterceptionValidator, fakeCallProcessorProviderFactory);
 }
Пример #2
0
        public bool MethodCanBeInterceptedOnInstance(MethodInfo method, object?callTarget, [NotNullWhen(false)] out string?failReason)
        {
            if (callTarget is not null && DelegateCreationStrategy.IsResponsibleForCreating(callTarget.GetType()))
            {
                return(this.delegateCreationStrategy.MethodCanBeInterceptedOnInstance(method, callTarget, out failReason));
            }

            return(this.defaultCreationStrategy.MethodCanBeInterceptedOnInstance(method, callTarget, out failReason));
        }
Пример #3
0
        public CreationResult CreateFake(Type typeOfFake, IProxyOptions proxyOptions, IDummyValueResolver resolver)
        {
            if (typeOfFake.GetTypeInfo().IsInterface)
            {
                return(this.defaultCreationStrategy.CreateFakeInterface(typeOfFake, proxyOptions));
            }

            return(DelegateCreationStrategy.IsResponsibleForCreating(typeOfFake)
                ? this.delegateCreationStrategy.CreateFake(typeOfFake, proxyOptions)
                : this.defaultCreationStrategy.CreateFake(typeOfFake, proxyOptions, resolver));
        }
Пример #4
0
        public CreationResult CreateFakeWithoutLoopDetection(
            Type typeOfFake,
            IProxyOptions proxyOptions,
            IDummyValueResolver resolver,
            LoopDetectingResolutionContext resolutionContext)
        {
            if (typeOfFake.IsInterface)
            {
                return(this.defaultCreationStrategy.CreateFakeInterface(typeOfFake, proxyOptions));
            }

            return(DelegateCreationStrategy.IsResponsibleForCreating(typeOfFake)
                ? this.delegateCreationStrategy.CreateFake(typeOfFake, proxyOptions)
                : this.defaultCreationStrategy.CreateFake(typeOfFake, proxyOptions, resolver, resolutionContext));
        }
 public bool MethodCanBeInterceptedOnInstance(MethodInfo method, object callTarget, out string failReason) =>
 DelegateCreationStrategy.IsResponsibleForCreating(callTarget?.GetType())
         ? this.delegateCreationStrategy.MethodCanBeInterceptedOnInstance(method, callTarget, out failReason)
         : this.defaultCreationStrategy.MethodCanBeInterceptedOnInstance(method, callTarget, out failReason);