How to use Planner class of Telerik.JustMock.AutoMock.Ninject.Planning package

Best JustMockLite code snippet using Telerik.JustMock.AutoMock.Ninject.Planning.Planner

StandardProvider.cs

Source:StandardProvider.cs Github

copy

Full Screen

...34 public Type Type { get; private set; }35 /// <summary>36 /// Gets or sets the planner component.37 /// </summary>38 public IPlanner Planner { get; private set; }39 /// <summary>40 /// Gets or sets the selector component.41 /// </summary>42 public IConstructorScorer ConstructorScorer { get; private set; }43 /// <summary>44 /// Initializes a new instance of the <see cref="StandardProvider"/> class.45 /// </summary>46 /// <param name="type">The type (or prototype) of instances the provider creates.</param>47 /// <param name="planner">The planner component.</param>48 /// <param name="constructorScorer">The constructor scorer component.</param>49 public StandardProvider(Type type, IPlanner planner, IConstructorScorer constructorScorer50 )51 {52 Ensure.ArgumentNotNull(type, "type");53 Ensure.ArgumentNotNull(planner, "planner");54 Ensure.ArgumentNotNull(constructorScorer, "constructorScorer");55 Type = type;56 Planner = planner;57 ConstructorScorer = constructorScorer;58 }59 /// <summary>60 /// Creates an instance within the specified context.61 /// </summary>62 /// <param name="context">The context.</param>63 /// <returns>The created instance.</returns>64 public virtual object Create(IContext context)65 {66 Ensure.ArgumentNotNull(context, "context");67 if (context.Plan == null)68 {69 context.Plan = this.Planner.GetPlan(this.GetImplementationType(context.Request.Service));70 }71 if (!context.Plan.Has<ConstructorInjectionDirective>())72 {73 throw new ActivationException(ExceptionFormatter.NoConstructorsAvailable(context));74 }75 var directives = context.Plan.GetAll<ConstructorInjectionDirective>();76 var bestDirectives = directives77 .GroupBy(option => this.ConstructorScorer.Score(context, option))78 .OrderByDescending(g => g.Key)79 .First();80 if (bestDirectives.Skip(1).Any())81 {82 throw new ActivationException(ExceptionFormatter.ConstructorsAmbiguous(context, bestDirectives));83 }84 var directive = bestDirectives.Single();85 var arguments = directive.Targets.Select(target => this.GetValue(context, target)).ToArray();86 var injector = directive.Injector;87 return ProfilerInterceptor.GuardExternal(() => injector(arguments));88 }89 /// <summary>90 /// Gets the value to inject into the specified target.91 /// </summary>92 /// <param name="context">The context.</param>93 /// <param name="target">The target.</param>94 /// <returns>The value to inject into the specified target.</returns>95 public object GetValue(IContext context, ITarget target)96 {97 Ensure.ArgumentNotNull(context, "context");98 Ensure.ArgumentNotNull(target, "target");99 var parameter = context100 .Parameters.OfType<IConstructorArgument>()101 .Where(p => p.AppliesToTarget(context, target)).SingleOrDefault();102 return parameter != null ? parameter.GetValue(context, target) : target.ResolveWithin(context);103 }104 /// <summary>105 /// Gets the implementation type that the provider will activate an instance of106 /// for the specified service.107 /// </summary>108 /// <param name="service">The service in question.</param>109 /// <returns>The implementation type that will be activated.</returns>110 public Type GetImplementationType(Type service)111 {112 Ensure.ArgumentNotNull(service, "service");113 return Type.ContainsGenericParameters ? Type.MakeGenericType(service.GetGenericArguments()) : Type;114 }115 /// <summary>116 /// Gets a callback that creates an instance of the <see cref="StandardProvider"/>117 /// for the specified type.118 /// </summary>119 /// <param name="prototype">The prototype the provider instance will create.</param>120 /// <returns>The created callback.</returns>121 public static Func<IContext, IProvider> GetCreationCallback(Type prototype)122 {123 Ensure.ArgumentNotNull(prototype, "prototype");124 return ctx => new StandardProvider(prototype, ctx.Kernel.Components.Get<IPlanner>(), ctx.Kernel.Components.Get<ISelector>().ConstructorScorer);125 }126 /// <summary>127 /// Gets a callback that creates an instance of the <see cref="StandardProvider"/>128 /// for the specified type and constructor.129 /// </summary>130 /// <param name="prototype">The prototype the provider instance will create.</param>131 /// <param name="constructor">The constructor.</param>132 /// <returns>The created callback.</returns>133 public static Func<IContext, IProvider> GetCreationCallback(Type prototype, ConstructorInfo constructor)134 {135 Ensure.ArgumentNotNull(prototype, "prototype");136 return ctx => new StandardProvider(prototype, ctx.Kernel.Components.Get<IPlanner>(), new SpecificConstructorSelector(constructor));137 }138 }139}...

Full Screen

Full Screen

Context.cs

Source:Context.cs Github

copy

Full Screen

...60 public ICache Cache { get; private set; }61 /// <summary>62 /// Gets or sets the planner component.63 /// </summary>64 public IPlanner Planner { get; private set; }65 /// <summary>66 /// Gets or sets the pipeline component.67 /// </summary>68 public IPipeline Pipeline { get; private set; }69 /// <summary>70 /// Initializes a new instance of the <see cref="Context"/> class.71 /// </summary>72 /// <param name="kernel">The kernel managing the resolution.</param>73 /// <param name="request">The context's request.</param>74 /// <param name="binding">The context's binding.</param>75 /// <param name="cache">The cache component.</param>76 /// <param name="planner">The planner component.</param>77 /// <param name="pipeline">The pipeline component.</param>78 public Context(IKernel kernel, IRequest request, IBinding binding, ICache cache, IPlanner planner, IPipeline pipeline)79 {80 Ensure.ArgumentNotNull(kernel, "kernel");81 Ensure.ArgumentNotNull(request, "request");82 Ensure.ArgumentNotNull(binding, "binding");83 Ensure.ArgumentNotNull(cache, "cache");84 Ensure.ArgumentNotNull(planner, "planner");85 Ensure.ArgumentNotNull(pipeline, "pipeline");86 Kernel = kernel;87 Request = request;88 Binding = binding;89 Parameters = request.Parameters.Union(binding.Parameters).ToList();90 Cache = cache;91 Planner = planner;92 Pipeline = pipeline;93 if (binding.Service.IsGenericTypeDefinition)94 {95 HasInferredGenericArguments = true;96 GenericArguments = request.Service.GetGenericArguments();97 }98 }99 /// <summary>100 /// Gets the scope for the context that "owns" the instance activated therein.101 /// </summary>102 /// <returns>The object that acts as the scope.</returns>103 public object GetScope()104 {105 if (this.cachedScope == null)106 {107 var scope = this.Request.GetScope() ?? this.Binding.GetScope(this);108 this.cachedScope = new WeakReference(scope);109 }110 111 return this.cachedScope.Target;112 }113 /// <summary>114 /// Gets the provider that should be used to create the instance for this context.115 /// </summary>116 /// <returns>The provider that should be used.</returns>117 public IProvider GetProvider()118 {119 return Binding.GetProvider(this);120 }121 /// <summary>122 /// Resolves the instance associated with this hook.123 /// </summary>124 /// <returns>The resolved instance.</returns>125 public object Resolve()126 {127 lock (Binding)128 {129 if (Request.ActiveBindings.Contains(Binding))130 throw new ActivationException(ExceptionFormatter.CyclicalDependenciesDetected(this));131 var cachedInstance = Cache.TryGet(this);132 if (cachedInstance != null)133 return cachedInstance;134 Request.ActiveBindings.Push(Binding);135 var reference = new InstanceReference { Instance = GetProvider().Create(this) };136 Request.ActiveBindings.Pop();137 if (reference.Instance == null)138 {139 if (!this.Kernel.Settings.AllowNullInjection)140 {141 throw new ActivationException(ExceptionFormatter.ProviderReturnedNull(this));142 }143 if (this.Plan == null)144 {145 this.Plan = this.Planner.GetPlan(this.Request.Service);146 }147 return null;148 }149 if (GetScope() != null)150 Cache.Remember(this, reference);151 if (Plan == null)152 Plan = Planner.GetPlan(reference.Instance.GetType());153 Pipeline.Activate(this, reference);154 return reference.Instance;155 }156 }157 }158}...

Full Screen

Full Screen

Planner.cs

Source:Planner.cs Github

copy

Full Screen

1//-------------------------------------------------------------------------------2// <copyright file="Planner.cs" company="Ninject Project Contributors">3// Copyright (c) 2007-2009, Enkari, Ltd.4// Copyright (c) 2009-2011 Ninject Project Contributors5// Authors: Nate Kohari (nate@enkari.com)6// Remo Gloor (remo.gloor@gmail.com)7// 8// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).9// you may not use this file except in compliance with one of the Licenses.10// You may obtain a copy of the License at11//12// http://www.apache.org/licenses/LICENSE-2.013// or14// http://www.microsoft.com/opensource/licenses.mspx15//16// Unless required by applicable law or agreed to in writing, software17// distributed under the License is distributed on an "AS IS" BASIS,18// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.19// See the License for the specific language governing permissions and20// limitations under the License.21// </copyright>22//-------------------------------------------------------------------------------23namespace Telerik.JustMock.AutoMock.Ninject.Planning24{25 using System;26 using System.Collections.Generic;27 using System.Linq;28 using System.Threading;29 using Telerik.JustMock.AutoMock.Ninject.Components;30 using Telerik.JustMock.AutoMock.Ninject.Infrastructure;31 using Telerik.JustMock.AutoMock.Ninject.Infrastructure.Language;32 using Telerik.JustMock.AutoMock.Ninject.Planning.Strategies;33 /// <summary>34 /// Generates plans for how to activate instances.35 /// </summary>36 public class Planner : NinjectComponent, IPlanner37 {38 private readonly ReaderWriterLock plannerLock = new ReaderWriterLock();39 private readonly Dictionary<Type, IPlan> plans = new Dictionary<Type, IPlan>();40 /// <summary>41 /// Initializes a new instance of the <see cref="Planner"/> class.42 /// </summary>43 /// <param name="strategies">The strategies to execute during planning.</param>44 public Planner(IEnumerable<IPlanningStrategy> strategies)45 {46 Ensure.ArgumentNotNull(strategies, "strategies");47 this.Strategies = strategies.ToList();48 }49 /// <summary>50 /// Gets the strategies that contribute to the planning process.51 /// </summary>52 public IList<IPlanningStrategy> Strategies { get; private set; }53 54 /// <summary>55 /// Gets or creates an activation plan for the specified type.56 /// </summary>57 /// <param name="type">The type for which a plan should be created.</param>58 /// <returns>The type's activation plan.</returns>...

Full Screen

Full Screen

Planner

Using AI Code Generation

copy

Full Screen

1using System;2using System.Collections.Generic;3using System.Linq;4using System.Text;5using System.Threading.Tasks;6using Telerik.JustMock.AutoMock.Ninject.Planning;7using Telerik.JustMock.AutoMock.Ninject.Planning.Targets;8{9 {10 public void Plan()11 {12 var planner = new Telerik.JustMock.AutoMock.Ninject.Planning.Planner();13 var target = new Target(typeof(Planner), typeof(Planner).GetMethod("Plan"), typeof(Planner).GetConstructors().First());14 planner.GetPlan(target);15 }16 }17}18using System;19using System.Collections.Generic;20using System.Linq;21using System.Text;22using System.Threading.Tasks;23using Telerik.JustMock.AutoMock.Ninject.Planning;24using Telerik.JustMock.AutoMock.Ninject.Planning.Targets;25{26 {27 public void Plan()28 {29 var planner = new Telerik.JustMock.AutoMock.Ninject.Planning.Planner();30 var target = new Target(typeof(Planner), typeof(Planner).GetMethod("Plan"), typeof(Planner).GetConstructors().First());31 planner.GetPlan(target);32 }33 }34}35using System;36using System.Collections.Generic;37using System.Linq;38using System.Text;39using System.Threading.Tasks;40using Telerik.JustMock.AutoMock.Ninject.Planning;41using Telerik.JustMock.AutoMock.Ninject.Planning.Targets;42{43 {44 public void Plan()45 {46 var planner = new Telerik.JustMock.AutoMock.Ninject.Planning.Planner();47 var target = new Target(typeof(Planner), typeof(Planner).GetMethod("Plan"), typeof(Planner).GetConstructors().First());48 planner.GetPlan(target);49 }50 }51}52using System;53using System.Collections.Generic;54using System.Linq;55using System.Text;56using System.Threading.Tasks;57using Telerik.JustMock.AutoMock.Ninject.Planning;

Full Screen

Full Screen

Planner

Using AI Code Generation

copy

Full Screen

1using Telerik.JustMock.AutoMock.Ninject.Planning;2using Telerik.JustMock.AutoMock.Planning;3using Telerik.JustMock.AutoMock.Ninject.Planning;4using Telerik.JustMock.AutoMock.Planning;5using Telerik.JustMock.AutoMock.Ninject.Planning;6using Telerik.JustMock.AutoMock.Planning;7using Telerik.JustMock.AutoMock.Ninject.Planning;8using Telerik.JustMock.AutoMock.Planning;9using Telerik.JustMock.AutoMock.Ninject.Planning;10using Telerik.JustMock.AutoMock.Planning;11using Telerik.JustMock.AutoMock.Ninject.Planning;12using Telerik.JustMock.AutoMock.Planning;13using Telerik.JustMock.AutoMock.Ninject.Planning;14using Telerik.JustMock.AutoMock.Planning;15using Telerik.JustMock.AutoMock.Ninject.Planning;16using Telerik.JustMock.AutoMock.Planning;

Full Screen

Full Screen

Planner

Using AI Code Generation

copy

Full Screen

1{2 {3 private readonly IPlanner planner;4 public AutoMockingKernel(params INinjectModule[] modules)5 : base(modules)6 {7 this.planner = new Planner(this);8 }9 public AutoMockingKernel(IPlanner planner, params INinjectModule[] modules)10 : base(modules)11 {12 this.planner = planner;13 }14 public override void Load(IEnumerable<INinjectModule> modules)15 {16 base.Load(modules);17 this.planner.Plan();18 }19 public override void Load(params INinjectModule[] modules)20 {21 base.Load(modules);22 this.planner.Plan();23 }24 }25}26{27 {28 private readonly IPlanner planner;29 public AutoMockingKernel(params INinjectModule[] modules)30 : base(modules)31 {32 this.planner = new Planner(this);33 }34 public AutoMockingKernel(IPlanner planner, params INinjectModule[] modules)35 : base(modules)36 {37 this.planner = planner;38 }39 public override void Load(IEnumerable<INinjectModule> modules)40 {41 base.Load(modules);42 this.planner.Plan();43 }44 public override void Load(params INinjectModule[] modules)45 {46 base.Load(modules);47 this.planner.Plan();48 }49 }50}51{52 {53 private readonly IPlanner planner;54 public AutoMockingKernel(params INinjectModule[] modules)55 : base(modules)56 {57 this.planner = new Planner(this);58 }59 public AutoMockingKernel(IPlanner planner, params INinjectModule[] modules)

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run JustMockLite automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful