public object CreateFake(Type typeOfFake, IProxyOptions proxyOptions, DummyCreationSession session, IDummyValueResolver resolver, bool throwOnFailure) { if (!this.proxyGenerator.CanGenerateProxy(typeOfFake, out string reasonCannotGenerate)) { if (throwOnFailure) { this.thrower.ThrowFailedToGenerateProxyWithoutTryingConstructors(typeOfFake, reasonCannotGenerate); } return(null); } ProxyGeneratorResult result; if (proxyOptions.ArgumentsForConstructor != null) { result = this.GenerateProxy(typeOfFake, proxyOptions, proxyOptions.ArgumentsForConstructor); if (!result.ProxyWasSuccessfullyGenerated) { if (throwOnFailure) { this.thrower.ThrowFailedToGenerateProxyWithArgumentsForConstructor(typeOfFake, result.ReasonForFailure); } return(null); } return(result.GeneratedProxy); } result = this.TryCreateFakeWithDummyArgumentsForConstructor(typeOfFake, proxyOptions, session, resolver, throwOnFailure); return(result?.GeneratedProxy); }
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)); }
private void AssertThatProxyWasGeneratedWhenArgumentsForConstructorAreSpecified(Type typeOfFake, ProxyGeneratorResult result, IProxyOptions proxyOptions) { if (!result.ProxyWasSuccessfullyGenerated && proxyOptions.ArgumentsForConstructor != null) { this.thrower.ThrowFailedToGenerateProxyWithArgumentsForConstructor(typeOfFake, result.ReasonForFailure); } }
/// <summary> /// Initializes a new instance of the <see cref="GoogleAdwordsClient" /> class. /// </summary> /// <param name="proxyOptions">The proxy options.</param> /// <exception cref="System.ArgumentNullException">f</exception> public GoogleAdwordsClient(IProxyOptions proxyOptions = null) : base(client => new Automa(client, automa => new GoogleAdwordsAutomation(client, automa)), proxyOptions) { Logger = Console.WriteLine; AdWordsUser = new AdWordsUser(); AdWordsUser.Config.EnableGzipCompression = true; }
private CreationResult TryCreateFakeWithDummyArgumentsForConstructor( Type typeOfFake, IProxyOptions proxyOptions, IDummyValueResolver resolver, LoopDetectingResolutionContext resolutionContext) { // Save the constructors as we try them. Avoids eager evaluation and double evaluation // of constructors enumerable. var consideredConstructors = new List <ResolvedConstructor>(); if (this.parameterTypesCache.TryGetValue(typeOfFake, out Type[]? cachedParameterTypes))
private ProxyGeneratorResult GenerateProxy(Type typeOfFake, IProxyOptions proxyOptions, IEnumerable <object> argumentsForConstructor) { var fakeCallProcessorProvider = this.fakeCallProcessorProviderFactory(typeOfFake, proxyOptions); return(this.proxyGenerator.GenerateProxy( typeOfFake, proxyOptions.AdditionalInterfacesToImplement, argumentsForConstructor, proxyOptions.AdditionalAttributes, fakeCallProcessorProvider)); }
public DefaultProxyProxyClient(IProxyOptions proxyOptions) { if (proxyOptions == null) { throw new ArgumentNullException(nameof(proxyOptions)); } _httpClient = new HttpClient { BaseAddress = new Uri(proxyOptions.BaseUrl) }; }
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)); }
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 FakeManagerProvider( FakeManager.Factory fakeManagerFactory, IFakeManagerAccessor fakeManagerAccessor, Type typeOfFake, IProxyOptions proxyOptions) { Guard.AgainstNull(fakeManagerFactory, nameof(fakeManagerFactory)); Guard.AgainstNull(fakeManagerAccessor, nameof(fakeManagerAccessor)); Guard.AgainstNull(typeOfFake, nameof(typeOfFake)); Guard.AgainstNull(proxyOptions, nameof(proxyOptions)); this.fakeManagerFactory = fakeManagerFactory; this.fakeManagerAccessor = fakeManagerAccessor; this.typeOfFake = typeOfFake; this.proxyOptions = proxyOptions; }
public object CreateFake(Type typeOfFake, IProxyOptions proxyOptions, IDummyValueCreationSession session, bool throwOnFailure) { var result = this.GenerateProxy(typeOfFake, proxyOptions, proxyOptions.ArgumentsForConstructor); if (throwOnFailure) { this.AssertThatProxyWasGeneratedWhenArgumentsForConstructorAreSpecified(typeOfFake, result, proxyOptions); } if (!result.ProxyWasSuccessfullyGenerated && proxyOptions.ArgumentsForConstructor == null) { result = this.TryCreateFakeWithDummyArgumentsForConstructor(typeOfFake, proxyOptions, session, result.ReasonForFailure, throwOnFailure); } return(result != null ? result.GeneratedProxy : null); }
public object CreateFake(Type typeOfFake, IProxyOptions proxyOptions, IDummyValueCreationSession session, bool throwOnFailure) { var result = this.GenerateProxy(typeOfFake, proxyOptions, proxyOptions.ArgumentsForConstructor); if (throwOnFailure) { this.AssertThatProxyWasGeneratedWhenArgumentsForConstructorAreSpecified(typeOfFake, result, proxyOptions); } if (!result.ProxyWasSuccessfullyGenerated && proxyOptions.ArgumentsForConstructor == null) { result = this.TryCreateFakeWithDummyArgumentsForConstructor(typeOfFake, proxyOptions, session, result.ReasonForFailure, throwOnFailure); } return result != null ? result.GeneratedProxy : null; }
public FakeManagerProvider( FakeManager.Factory fakeManagerFactory, IFakeManagerAccessor fakeManagerAccessor, Type typeOfFake, IProxyOptions proxyOptions) { Guard.AgainstNull(fakeManagerFactory, "fakeManagerFactory"); Guard.AgainstNull(fakeManagerAccessor, "fakeManagerAccessor"); Guard.AgainstNull(typeOfFake, "typeOfFake"); Guard.AgainstNull(proxyOptions, "proxyOptions"); this.fakeManagerFactory = fakeManagerFactory; this.fakeManagerAccessor = fakeManagerAccessor; this.typeOfFake = typeOfFake; this.proxyOptions = proxyOptions; }
public FakeManagerProviderTests() { this.fakeManagerFactory = A.Fake <FakeManager.Factory>(); this.fakeManagerAccessor = A.Fake <IFakeManagerAccessor>(); this.typeOfFake = A.Fake <Type>(); this.proxyOptions = A.Fake <IProxyOptions>(); this.fakeManagerProvider = new FakeManagerProvider( this.fakeManagerFactory, this.fakeManagerAccessor, this.typeOfFake, this.proxyOptions); this.proxy = new object(); this.fakeManager = new FakeManager(typeof(int), this.proxy, null); A.CallTo(() => this.fakeManagerFactory(A <Type> ._, this.proxy, A <string> .Ignored)).Returns(this.fakeManager); }
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 !)); }
private ProxyGeneratorResult TryCreateFakeWithDummyArgumentsForConstructor(Type typeOfFake, IProxyOptions proxyOptions, IDummyValueCreationSession session, string failReasonForDefaultConstructor, bool throwOnFailure) { var constructors = ResolveConstructors(typeOfFake, session); foreach (var constructor in constructors.Where(x => x.WasSuccessfullyResolved)) { var result = this.GenerateProxy(typeOfFake, proxyOptions, constructor.Arguments.Select(x => x.ResolvedValue)); if (result.ProxyWasSuccessfullyGenerated) { return result; } constructor.ReasonForFailure = result.ReasonForFailure; } if (throwOnFailure) { this.thrower.ThrowFailedToGenerateProxyWithResolvedConstructors(typeOfFake, failReasonForDefaultConstructor, constructors); } return null; }
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); }
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)); }
/// <summary> /// Initializes a new instance of the <see cref="UmbClient" /> class. /// </summary> /// <param name="proxyOptions">The proxy options.</param> public UmbClient(IProxyOptions proxyOptions = null) : base(client => new Automa(client, automa => new UmbAutomation(client, automa), 0M), proxyOptions) { }
public InternalProxyMiddlewareOption(TOptions options) { Options = options; }
private ProxyGeneratorResult GenerateProxy(Type typeOfFake, IProxyOptions proxyOptions, IEnumerable<object> argumentsForConstructor) { var fakeCallProcessorProvider = this.fakeCallProcessorProviderFactory(typeOfFake, proxyOptions); return this.proxyGenerator.GenerateProxy( typeOfFake, proxyOptions.AdditionalInterfacesToImplement, argumentsForConstructor, proxyOptions.Attributes, fakeCallProcessorProvider); }
public bool TryCreateFake(Type typeOfFake, IProxyOptions options, out object result) { result = this.fakeCreator.CreateFake(typeOfFake, options, this.session, throwOnFailure: false); return(result != null); }
/// <summary> /// Initializes a new instance of the <see cref="OktaClient"/> class. /// </summary> /// <param name="oktaUri">The okta URI.</param> /// <param name="oktaId">The okta identifier.</param> public OktaClient(Uri oktaUri, string oktaId, IProxyOptions proxyOptions = null) : base(client => new Automa(client, automa => new OktaAutomation(client, automa, oktaUri), driverOptions: DriverOptions), proxyOptions) { _oktaUri = oktaUri; _oktaId = oktaId; }
public AdpClient(IProxyOptions proxyOptions = null) : base(client => new Automa(client, automa => new AdpAutomation(client, automa)), proxyOptions) { }
public object CreateFake(Type typeOfFake, IProxyOptions options) { return this.fakeCreator.CreateFake(typeOfFake, options, this.session, throwOnFailure: true); }
public bool TryCreateFake(Type typeOfFake, IProxyOptions options, out object result) { result = this.fakeCreator.CreateFake(typeOfFake, options, this.session, throwOnFailure: false); return result != null; }
private ProxyGeneratorResult TryCreateFakeWithDummyArgumentsForConstructor(Type typeOfFake, IProxyOptions proxyOptions, DummyCreationSession session, IDummyValueResolver resolver, string failReasonForDefaultConstructor, bool throwOnFailure) { var constructors = ResolveConstructors(typeOfFake, session, resolver); // Save the constructors as we try them. Avoids eager evaluation and double evaluation // of constructors enumerable. var consideredConstructors = new List <ResolvedConstructor>(); foreach (var constructor in constructors) { if (constructor.WasSuccessfullyResolved) { var result = this.GenerateProxy(typeOfFake, proxyOptions, constructor.Arguments.Select(x => x.ResolvedValue)); if (result.ProxyWasSuccessfullyGenerated) { return(result); } constructor.ReasonForFailure = result.ReasonForFailure; } consideredConstructors.Add(constructor); } if (throwOnFailure) { this.thrower.ThrowFailedToGenerateProxyWithResolvedConstructors(typeOfFake, failReasonForDefaultConstructor, consideredConstructors); } return(null); }
private ProxyGeneratorResult TryCreateFakeWithDummyArgumentsForConstructor(Type typeOfFake, IProxyOptions proxyOptions, DummyCreationSession session, IDummyValueResolver resolver, bool throwOnFailure) { // Save the constructors as we try them. Avoids eager evaluation and double evaluation // of constructors enumerable. var consideredConstructors = new List <ResolvedConstructor>(); if (this.parameterTypesCache.TryGetValue(typeOfFake, out Type[] cachedParameterTypes))
public CreationResult CreateFake(Type typeOfFake, IProxyOptions proxyOptions, DummyCreationSession session, IDummyValueResolver resolver) => this.strategies.First(s => s.IsResponsibleForCreating(typeOfFake)).CreateFake(typeOfFake, proxyOptions, session, resolver);
/// <summary> /// Initializes a new instance of the <see cref="UnanetClient" /> class. /// </summary> /// <param name="options">The options.</param> /// <param name="proxyOptions">The proxy options.</param> public UnanetClient(IUnanetOptions options, IProxyOptions proxyOptions = null) : base(client => new Automa(client, automa => new UnanetAutomation(client, automa, options)), proxyOptions) { Options = options; UnanetUri = Options.UnanetUri; }
/// <summary> /// Initializes a new instance of the <see cref="AutomaClient" /> class. /// </summary> /// <param name="automaFactory">The client factory.</param> public AutomaClient(Func <AutomaClient, IAutoma> automaFactory = null, IProxyOptions proxyOptions = null) { _automaFactory = automaFactory; ProxyOptions = proxyOptions; }
private ProxyGeneratorResult TryCreateFakeWithDummyArgumentsForConstructor(Type typeOfFake, IProxyOptions proxyOptions, IDummyValueCreationSession session, string failReasonForDefaultConstructor, bool throwOnFailure) { var constructors = ResolveConstructors(typeOfFake, session); foreach (var constructor in constructors.Where(x => x.WasSuccessfullyResolved)) { var result = this.GenerateProxy(typeOfFake, proxyOptions, constructor.Arguments.Select(x => x.ResolvedValue)); if (result.ProxyWasSuccessfullyGenerated) { return(result); } constructor.ReasonForFailure = result.ReasonForFailure; } if (throwOnFailure) { this.thrower.ThrowFailedToGenerateProxyWithResolvedConstructors(typeOfFake, failReasonForDefaultConstructor, constructors); } return(null); }
/// <summary> /// Initializes a new instance of the <see cref="FacebookClient" /> class. /// </summary> /// <param name="proxyOptions">The proxy options.</param> /// <exception cref="System.ArgumentNullException">f</exception> public FacebookClient(IProxyOptions proxyOptions = null) : base(client => new Automa(client, automa => new FacebookAutomation(client, automa)), proxyOptions) { RequestedScope = "manage_pages,ads_management"; //read_insights,leads_retrieval Logger = Console.WriteLine; }
public object CreateFake(Type typeOfFake, IProxyOptions options) { return(this.fakeCreator.CreateFake(typeOfFake, options, this.session, throwOnFailure: true)); }