public CreationResult CreateFake( Type typeOfFake, IProxyOptions proxyOptions, IDummyValueResolver resolver, LoopDetectingResolutionContext resolutionContext) { if (!CastleDynamicProxyGenerator.CanGenerateProxy(typeOfFake, out string?reasonCannotGenerate)) { return(CreationResult.FailedToCreateFake(typeOfFake, reasonCannotGenerate)); } if (proxyOptions.ArgumentsForConstructor is not null) { var proxyGeneratorResult = this.GenerateProxy(typeOfFake, proxyOptions, proxyOptions.ArgumentsForConstructor); return(proxyGeneratorResult.ProxyWasSuccessfullyGenerated ? CreationResult.SuccessfullyCreated(proxyGeneratorResult.GeneratedProxy) : CreationResult.FailedToCreateFake(typeOfFake, proxyGeneratorResult.ReasonForFailure !)); } return(this.TryCreateFakeWithDummyArgumentsForConstructor( typeOfFake, proxyOptions, resolver, resolutionContext)); }
public CreationResult CreateFakeInterface(Type typeOfFake, IProxyOptions proxyOptions) { if (proxyOptions.ArgumentsForConstructor is not null) { throw new ArgumentException(DynamicProxyMessages.ArgumentsForConstructorOnInterfaceType); } var fakeCallProcessorProvider = this.fakeCallProcessorProviderFactory(typeOfFake, proxyOptions); var proxyGeneratorResult = CastleDynamicProxyGenerator.GenerateInterfaceProxy( typeOfFake, proxyOptions.AdditionalInterfacesToImplement, proxyOptions.Attributes, fakeCallProcessorProvider); return(proxyGeneratorResult.ProxyWasSuccessfullyGenerated ? CreationResult.SuccessfullyCreated(proxyGeneratorResult.GeneratedProxy) : CreationResult.FailedToCreateFake(typeOfFake, proxyGeneratorResult.ReasonForFailure !)); }
public CreationResult CreateFake(Type typeOfFake, IProxyOptions proxyOptions, DummyCreationSession session, IDummyValueResolver resolver) { if (proxyOptions.Attributes.Any()) { return(CreationResult.FailedToCreateFake(typeOfFake, "Faked delegates cannot have custom attributes applied to them.")); } if (proxyOptions.ArgumentsForConstructor != null && proxyOptions.ArgumentsForConstructor.Any()) { return(CreationResult.FailedToCreateFake(typeOfFake, "Faked delegates cannot be made using explicit constructor arguments.")); } if (proxyOptions.AdditionalInterfacesToImplement.Any()) { return(CreationResult.FailedToCreateFake(typeOfFake, "Faked delegates cannot be made to implement additional interfaces.")); } var fakeCallProcessorProvider = this.fakeCallProcessorProviderFactory(typeOfFake, proxyOptions); var proxyGeneratorResult = DelegateProxyGenerator.GenerateProxy(typeOfFake, fakeCallProcessorProvider); return(proxyGeneratorResult.ProxyWasSuccessfullyGenerated ? CreationResult.SuccessfullyCreated(proxyGeneratorResult.GeneratedProxy) : CreationResult.FailedToCreateFake(typeOfFake, proxyGeneratorResult.ReasonForFailure)); }
public CreationResult CreateFake( Type typeOfFake, IProxyOptions proxyOptions, IDummyValueResolver resolver, LoopDetectingResolutionContext resolutionContext) { if (!resolutionContext.TryBeginToResolve(typeOfFake)) { return(CreationResult.FailedToCreateFake(typeOfFake, "Recursive dependency detected. Already resolving " + typeOfFake + '.')); } try { return(this.CreateFakeWithoutLoopDetection( typeOfFake, proxyOptions, resolver, resolutionContext)); } finally { resolutionContext.EndResolve(typeOfFake); } }
public CreationResult CreateFake( Type typeOfFake, IProxyOptions proxyOptions, IDummyValueResolver resolver, LoopDetectingResolutionContext resolutionContext) { if (!resolutionContext.TryBeginToResolve(typeOfFake)) { return(CreationResult.FailedToCreateFake(typeOfFake, "Recursive dependency detected. Already resolving " + typeOfFake + '.')); } var result = this.CreateFakeWithoutLoopDetection( typeOfFake, proxyOptions, resolver, resolutionContext); if (result.WasSuccessful) { resolutionContext.OnSuccessfulResolve(typeOfFake); } return(result); }