public async Task Should_chain_in_order2() { /* Given */ var values = new List <int>(); var builder = new ResolverBuilder(); builder.Use((context, next) => { values.Add(0); return(next(context)); }); builder.Use((context, next) => { var result = next(context); values.Add(1); return(result); }); builder.Use((context, next) => { values.Add(2); return(next(context)); }); builder.Run(context => new ValueTask <IResolverResult>(Resolve.As(42))); /* When */ var resolver = builder.Build(); await resolver(null); /* Then */ Assert.Equal(new[] { 0, 2, 1 }, values.ToArray()); }
private void LevelUpdateCallBack(object state) { //object[] objParams = state as object[]; DataTable dtHL = state as DataTable; string extHierarchyID = string.Empty; Int16 groupingLevel = 0; ResolverBuilder requestResolver = new ResolverBuilder(); try { requestResolver.Build(); requestResolver.Container.RegisterType <IProductService, ProductService>(new HierarchicalLifetimeManager()); IProductService ps = requestResolver.Container.Resolve <IProductService>(); foreach (DataRow row in dtHL.Rows) { extHierarchyID = row["ExtHierarchyID"].ToString(); groupingLevel = row["LevelInHierarchy"].ConvertToInt16(); AMSResult <bool> amsResult = m_ProductService.UpdateHierarchyLevel(extHierarchyID, groupingLevel); if (amsResult.ResultType != AMSResultType.Success) { infobar.Visible = true; infobar.InnerHtml = PhraseLib.Lookup("pab.config.levelupdateerror", LanguageID) + ": " + amsResult.MessageString; } } } catch (Exception ex) { infobar.Visible = true; infobar.InnerHtml = PhraseLib.Lookup("pab.config.levelupdateerror", LanguageID) + ": " + ex.Message; } }
public void CreateSourcePropertyResolver() { // arrange var context = new Mock <IResolverContext>(MockBehavior.Strict); context.Setup(t => t.Parent <FooType>()) .Returns(new FooType()); context.Setup(t => t.RequestAborted) .Returns(CancellationToken.None); var fieldMember = new FieldMember( "type", "field", typeof(FooType).GetProperty("BarProperty")); var descriptor = new SourceResolverDescriptor( typeof(FooType), fieldMember); // act var resolverBuilder = new ResolverBuilder(); resolverBuilder.AddDescriptor(descriptor); ResolverBuilderResult result = resolverBuilder.Build(); // assert Assert.Collection(result.Resolvers, r => { Assert.Equal("type", r.TypeName); Assert.Equal("field", r.FieldName); Assert.NotNull(r.Resolver); object resolvedResult = r.Resolver( context.Object).Result; Assert.Equal("Hello World Property", resolvedResult); }); }
private ResolverBuilderResult CompileResolvers() { var resolverBuilder = new ResolverBuilder(); resolverBuilder.AddDescriptors(CreateResolverDescriptors()); resolverBuilder.AddDescriptors(CreateMiddlewareDescriptors()); resolverBuilder.AddDescriptors(_resolverDescriptors.Values); return(resolverBuilder.Build()); }
private IServiceResolver GetResolver(string name) { ResolverBuilder resolverBuilder = new ResolverBuilder(); resolverBuilder.Build(); IServiceResolver serviceResolver = resolverBuilder.GetResolver(); serviceResolver.AppName = name; return(serviceResolver); }
public DirectiveFieldVisitorContext WithResolver(Action <ResolverBuilder> build) { if (build == null) { throw new ArgumentNullException(nameof(build)); } var builder = new ResolverBuilder(); build(builder); return(new DirectiveFieldVisitorContext(Name, Field, builder.Build(), Subscriber)); }
public void CreateAsyncCollectionMethodResolver() { // arrange var context = new Mock <IResolverContext>(MockBehavior.Strict); context.Setup(t => t.Parent <FooType>()) .Returns(new FooType()); context.Setup(t => t.Resolver <FooTypeResolver>()) .Returns(new FooTypeResolver()); context.Setup(t => t.RequestAborted) .Returns(CancellationToken.None); var argumentDescriptor = new ArgumentDescriptor( "foo", "b", ArgumentKind.Source, typeof(FooType), null); var fieldMember = new FieldMember( "type", "field", typeof(FooTypeResolver).GetMethod("BarResolverAsync")); var descriptor = new ResolverDescriptor( typeof(FooTypeResolver), typeof(FooType), fieldMember, new[] { argumentDescriptor }); // act var resolverBuilder = new ResolverBuilder(); resolverBuilder.AddDescriptor(descriptor); ResolverBuilderResult result = resolverBuilder.Build(); // assert Assert.Collection(result.Resolvers, r => { Assert.Equal("type", r.TypeName); Assert.Equal("field", r.FieldName); Assert.NotNull(r.Resolver); object resolvedValue = r.Resolver( context.Object) .Result; Assert.Equal("Hello World_123", resolvedValue); }); }
public static void Compile( IDictionary <FieldReference, RegisteredResolver> resolvers) { if (resolvers == null) { throw new ArgumentNullException(nameof(resolvers)); } var resolverBuilder = new ResolverBuilder(); foreach (RegisteredResolver resolver in resolvers.Values) { if (resolver.Field is FieldMember member) { if (resolver.IsSourceResolver) { resolverBuilder.AddDescriptor( new SourceResolverDescriptor( resolver.SourceType, member)); } else { resolverBuilder.AddDescriptor( new ResolverDescriptor( resolver.ResolverType, resolver.SourceType, member)); } } } ResolverBuilderResult result = resolverBuilder.Build(); foreach (FieldResolver resolver in result.Resolvers) { var reference = resolver.ToFieldReference(); if (resolvers.TryGetValue(reference, out RegisteredResolver registered)) { resolvers[reference] = registered.WithField(resolver); } } }
public async Task Should_propagate_resolved_value() { /* Given */ var builder = new ResolverBuilder(); builder .Use((context, next) => next(context)) .Use((context, next) => next(context)) .Use((context, next) => next(context)); builder.Run(context => new ValueTask <IResolverResult>(Resolve.As(42))); /* When */ var resolver = builder.Build(); var result = await resolver(null); /* Then */ Assert.Equal(42, result.Value); }
public void Should_not_call_chain_until_resolver_executed() { /* Given */ var values = new List <int>(); var builder = new ResolverBuilder(); builder.Use((context, next) => { values.Add(0); return(next(context)); }); builder.Run(context => new ValueTask <IResolverResult>(Resolve.As(42))); /* When */ builder.Build(); /* Then */ Assert.Equal(new int[] {}, values.ToArray()); }
public DirectiveFieldVisitorContext WithSubscriber(Action <ResolverBuilder> buildResolver, Action <SubscriberBuilder> buildSubscriber) { if (buildResolver == null) { throw new ArgumentNullException(nameof(buildResolver)); } if (buildSubscriber == null) { throw new ArgumentNullException(nameof(buildSubscriber)); } var resolverBuilder = new ResolverBuilder(); buildResolver(resolverBuilder); var subscriberBuilder = new SubscriberBuilder(); buildSubscriber(subscriberBuilder); return(new DirectiveFieldVisitorContext(Name, Field, resolverBuilder.Build(), subscriberBuilder.Build())); }