public void pipeline___within_single_block_between_items(ResolverType resolverType) { var task = new TaskDefinition( new PipelineTaskStep <int>( "Step", new[] { 0, 1 }, new List <PipelineBlock <int> > { new PipelineBlock <int>( "Cancel / Complete", x => { if (x == 0) { _cancellationSource.Cancel(); } else { _completed = true; } }) })); test(task, resolverType); }
public void item_start_and_end_is_reported(ResolverType resolverType) { // Arrange ItemStartedEvent?startedEvent = null; ItemEndedEvent? endedEvent = null; var events = new PipelineExecutionEvents(); events.ItemStarted += x => startedEvent = x; events.ItemEnded += x => endedEvent = x; var item = 1; var task = new TaskDefinition( new PipelineTaskStep <int>( "Step", new[] { item }, new List <PipelineBlock <int> >())); // Act task.Execute(resolverType, events: events); // Assert startedEvent.Should().NotBeNull(); startedEvent.Value.ItemNumber.Should().Be(1); startedEvent.Value.Item.Should().Be(item); startedEvent.Value.MaterializationDuration.Should().BePositive(); endedEvent.Should().NotBeNull(); endedEvent.Value.ItemNumber.Should().Be(1); endedEvent.Value.Item.Should().Be(item); endedEvent.Value.Duration.Should().BePositive(); }
public void pipeline(ResolverType resolverType) { test( resolverType, GetPipelineStep(3), new byte[] { 33, 66, 100 }); }
public void block_start_and_end_is_reported(ResolverType resolverType) { // Arrange BlockStartedEvent?startedEvent = null; BlockEndedEvent? endedEvent = null; var events = new PipelineExecutionEvents(); events.BlockStarted += x => startedEvent = x; events.BlockEnded += x => endedEvent = x; var block = new PipelineBlock <int>( "Block", x => { }); var task = new TaskDefinition( new PipelineTaskStep <int>( "Step", new[] { 0 }, new List <PipelineBlock <int> > { block })); // Act task.Execute(resolverType, events: events); // Assert startedEvent.Should().NotBeNull(); startedEvent.Value.Block.Should().BeSameAs(block); endedEvent.Should().NotBeNull(); endedEvent.Value.Block.Should().BeSameAs(block); endedEvent.Value.Duration.Should().BePositive(); }
public void pipeline(ResolverType resolverType) { test( resolverType, GetPipelineStep(4), new[] { 0.25f, 0.5f, 0.75f, 1f }); }
/// <summary> /// Creates an <see cref="IAccessor"/> for the indicated GraphQL field /// </summary> /// <param name="type">The type to check.</param> /// <param name="field">The desired field.</param> /// <param name="resolverType">defaults to Resolver</param> public static IAccessor ToAccessor(this Type type, string field, ResolverType resolverType) { if (type == null) { return(null); } var methodInfo = type.MethodForField(field, resolverType); if (methodInfo != null) { return(new SingleMethodAccessor(methodInfo)); } if (resolverType != ResolverType.Resolver) { return(null); } var propertyInfo = type.PropertyForField(field); if (propertyInfo != null) { return(new SinglePropertyAccessor(propertyInfo)); } return(null); }
public void pipeline___less_items_than_expected(ResolverType resolverType) { test( resolverType, GetPipelineStep(3, 4), new[] { 0.25f, 0.5f, 0.75f }); }
public void pipeline___more_items_than_expected(ResolverType resolverType) { test( resolverType, GetPipelineStep(3, 2), new[] { 0.5f, 1f, 1f }); }
public void TaskExecutionCondition_gets_most_severe_previous_step_outcome( ResolverType resolverType, TaskOutcome firstStepOutcome, TaskOutcome secondStepOutcome, TaskOutcome outcomePassedToThirdStepCondition) { // Arrange var actualOutcomePassedToCondition = (TaskOutcome?)null; var task = new TaskDefinition( GetStepForOutcome(firstStepOutcome), GetStepForOutcome(secondStepOutcome, TaskStepUtils.AlwaysExecuteCondition), new BasicTaskStep( "TestedStep", () => { }, x => { actualOutcomePassedToCondition = x; return(true); })); // Act task.Execute(resolverType, cancellation: _cancellationSource); // Assert actualOutcomePassedToCondition.Should().Be(outcomePassedToThirdStepCondition); }
public void pipeline___less_items_than_expected(ResolverType resolverType) { test( resolverType, GetPipelineStep(3, 4), new byte[] { 25, 50, 75 }); // TODO: Consider including step status in TaskProgress (and reporting finished when finished) }
public void pipeline___more_items_than_expected(ResolverType resolverType) { test( resolverType, GetPipelineStep(3, 2), new byte[] { 50, 100, 100 }); // TODO: Consider not reporting unexpected items }
public void pipeline___catches_error_in_input_materialization( ResolverType resolverType, int invalidItemIndex) { var task = new TaskDefinition( new PipelineTaskStep <int>( FailingStepName, new[] { 0, 1, 2 }.Select((x, i) => { if (i == invalidItemIndex) { throw _error; } return(x); }), 3, new List <PipelineBlock <int> > { new PipelineBlock <int>( "Block", _ => { }), })); test(task, resolverType); }
public void basic(ResolverType resolverType) { test( resolverType, BasicTaskStep.Empty("Step"), new byte[] { 100 }); }
public void basic(ResolverType resolverType) { var task = new TaskDefinition( new BasicTaskStep( FailingStepName, () => throw _error)); test(task, resolverType); }
public static TaskResult Execute( this TaskDefinition task, ResolverType resolverType = ResolverType.Sequential, CancellationTokenSource cancellation = null, params IExecutionEvents[] events) { var executor = TaskExecutorFactory.Create(resolverType); return(executor.Execute(task, cancellation?.Token, events)); }
private void test_conditional_execution( ResolverType resolverType, TaskDefinition task, bool testedStepExecuted) { // Act task.Execute(resolverType, cancellation: _cancellationSource); // Assert _testedStepExecuted.Should().Be(testedStepExecuted); }
public Helper( StoreType hasData, ResolverType resolver, IsStatusOKDelegate isOkStatus = null, bool debug = false) { this.hasData = hasData; this.resolver = resolver; this.isOkStatus = isOkStatus ?? Helper.IsOkDefault; this.debug = debug; }
private static void ConfigureServices(IServiceCollection serviceCollection) { configuration = new ConfigurationBuilder() .SetBasePath(Directory.GetParent(AppContext.BaseDirectory).FullName) .AddJsonFile("appsettings.json", false) .Build(); ResolverType.Initialize(); ResolverType.MyContainer().Install(new ConfigurationInstallerFacade(configuration.GetConnectionString("pgConnection"))); ResolverType.MyContainer().Install(new AutoMapperInstaller()); }
private void test( TaskDefinition task, ResolverType resolverType) { // Act var result = task.Execute(resolverType, cancellation: _cancellationSource); // Assert result.Outcome.Should().Be(TaskOutcome.Canceled); _completed.Should().Be(false); }
public void pipeline___catches_error(ResolverType resolverType) { var task = new TaskDefinition( new PipelineTaskStep <int>( FailingStepName, new[] { 0 }, new List <PipelineBlock <int> > { new PipelineBlock <int>( "Block", _ => throw _error) }));
public void basic_automatic(ResolverType resolverType) { var task = new TaskDefinition( new BasicTaskStep( "Cancel", _cancellationSource.Cancel), new BasicTaskStep( "Complete", () => { _completed = true; })); test(task, resolverType); }
public void custom_conditon( ResolverType resolverType, bool shouldExecute) { var task = new TaskDefinition( new BasicTaskStep( "TestedStep", () => { _testedStepExecuted = true; }, _ => shouldExecute)); test_conditional_execution(resolverType, task, shouldExecute); }
/// <summary> /// Returns the method associated with the indicated GraphQL field /// </summary> /// <param name="type">The type to check.</param> /// <param name="field">The desired field.</param> /// <param name="resolverType">Indicates if a resolver or subscriber method is requested.</param> public static MethodInfo MethodForField(this Type type, string field, ResolverType resolverType) { var methods = type.GetMethods(BindingFlags.Public | BindingFlags.Instance); var method = methods.FirstOrDefault(m => { var attr = m.GetCustomAttribute <GraphQLMetadataAttribute>(); var name = attr?.Name ?? m.Name; return(string.Equals(field, name, StringComparison.OrdinalIgnoreCase) && resolverType == (attr?.ResolverType ?? ResolverType.Resolver)); }); return(method); }
public void default_condition___executed_only_if_successful( ResolverType resolverType, TaskOutcome precedingStepOutcome, bool testedStepExecuted) { var task = new TaskDefinition( GetStepForOutcome(precedingStepOutcome), new BasicTaskStep( "TestedStep", () => { _testedStepExecuted = true; })); test_conditional_execution(resolverType, task, testedStepExecuted); }
public static ITaskExecutor Create( ResolverType resolverType, params IExecutionEvents[] events) { var builder = new TaskExecutorBuilder() .RegisterPipelineExecution(resolverType); foreach (var e in events) { builder.RegisterEvents(e); } return(builder.Build()); }
public void basic_manual(ResolverType resolverType) { var task = new TaskDefinition( new BasicTaskStep( "Cancel", (p, c) => { _cancellationSource.Cancel(); c.ThrowIfCancellationRequested(); _completed = true; })); test(task, resolverType); }
/// <summary> /// Registers the resolver. /// </summary> /// <remarks> /// The resolver with the greatest version number is retained /// </remarks> /// <returns>The resolver.</returns> /// <param name="resolverImpl">Resolver impl.</param> public static IResolver RegisterResolver(IResolver resolverImpl, ResolverType resolverType = ResolverType.Default) { if (resolverImpl == null) { return(Resolver); } IResolver destResolver; if (!_resolvers.TryGetValue(resolverType, out destResolver) || destResolver.Version() < resolverImpl.Version()) { _resolvers[resolverType] = resolverImpl; } return(resolverImpl); }
public void test(ResolverType resolverType) { // Arrange var initialized = false; var sum = 0; var completed = false; var task = new TaskDefinition( new BasicTaskStep( "Initialize", () => { initialized = true; }), PipelineTaskStep .Builder <int>("Pipeline") .WithInput(new[] { 1, 2, 3, 4, 5, 6 }) .WithBlock("Sum", x => sum += x) .WithBlock("Log", x => _output.WriteLine(x.ToString())) .Build(), new BasicTaskStep( "Complete", () => { completed = true; })); var progress = new SynchronousProgress <TaskProgress>(x => _output.WriteLine($"{x.StepName}: {x.ProgressPercentage}%")); var cancellationSource = new CancellationTokenSource(); var taskEvents = new TaskExecutionEvents( taskStarted: x => _output.WriteLine("Task started."), taskEnded: x => _output.WriteLine($"Task ended after {x.Duration.Ticks} ticks."), stepStarted: x => _output.WriteLine($"Step '{x.Step.Name}' started."), stepEnded: x => _output.WriteLine($"Step '{x.Step.Name}' ended after {x.Duration.Ticks} ticks.")); var pipelineEvents = new PipelineExecutionEvents( itemStarted: x => _output.WriteLine($"Item {x.ItemNumber} of step '{x.Step.Name}' started."), itemEnded: x => _output.WriteLine($"Item {x.ItemNumber} of step '{x.Step.Name}' ended after {x.Duration.Ticks} ticks."), blockStarted: x => _output.WriteLine($"Block '{x.Block.Name}' of step '{x.Step.Name}' started processing item {x.ItemNumber}."), blockEnded: x => _output.WriteLine($"Block '{x.Block.Name}' of step '{x.Step.Name}' ended processing item {x.ItemNumber} after {x.Duration.Ticks} ticks.")); // Act var result = task.Execute(resolverType, progress, cancellationSource, taskEvents, pipelineEvents); // Assert result.Outcome.Should().Be(TaskOutcome.Successful); initialized.Should().Be(true); sum.Should().Be(21); completed.Should().Be(true); }
public void pipeline___between_blocks(ResolverType resolverType) { var task = new TaskDefinition( new PipelineTaskStep <int>( "Step", new[] { 0 }, new List <PipelineBlock <int> > { new PipelineBlock <int>( "Cancel", x => { _cancellationSource.Cancel(); }), new PipelineBlock <int>( "Complete", x => { _completed = true; }) })); test(task, resolverType); }
static void Main(string[] args) { var connectionString = ConfigurationManager.ConnectionStrings["pgConnection"].ConnectionString; ResolverType.Initialize(); ResolverType.MyContainer().Install(new ConfigurationInstallerFacade(connectionString)); ResolverType.MyContainer().Install(new AutoMapperInstaller()); var logic = ResolverType.GetLogicFactory <ITestLogic>(); var cuentas = logic.GetCuentaContable(); foreach (var cuenta in cuentas) { Console.WriteLine($"Cuenta :{ cuenta.NumeroCuenta } - Descripción: { cuenta.Descripcion }"); } Console.ReadKey(); }
public void Resolve_AppropriateTermType_True() { var resolverType = new ResolverType<FunctionDeclarationTerm>(); var term = new FunctionDeclarationTerm("variable", 1); Assert.That(resolverType.Resolve(term), Is.True); }
public void Resolve_InappropriateTermType_True() { var resolverType = new ResolverType<FunctionDeclarationTerm>(); var term = new ConstantDeclarationTerm("variable"); Assert.That(resolverType.Resolve(term), Is.False); }