Esempio n. 1
0
        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();
        }
Esempio n. 3
0
 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();
        }
Esempio n. 5
0
 public void pipeline(ResolverType resolverType)
 {
     test(
         resolverType,
         GetPipelineStep(4),
         new[] { 0.25f, 0.5f, 0.75f, 1f });
 }
Esempio n. 6
0
        /// <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);
        }
Esempio n. 7
0
 public void pipeline___less_items_than_expected(ResolverType resolverType)
 {
     test(
         resolverType,
         GetPipelineStep(3, 4),
         new[] { 0.25f, 0.5f, 0.75f });
 }
Esempio n. 8
0
 public void pipeline___more_items_than_expected(ResolverType resolverType)
 {
     test(
         resolverType,
         GetPipelineStep(3, 2),
         new[] { 0.5f, 1f, 1f });
 }
Esempio n. 9
0
        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);
        }
Esempio n. 10
0
 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)
 }
Esempio n. 11
0
 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
 }
Esempio n. 12
0
        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);
        }
Esempio n. 13
0
 public void basic(ResolverType resolverType)
 {
     test(
         resolverType,
         BasicTaskStep.Empty("Step"),
         new byte[] { 100 });
 }
Esempio n. 14
0
        public void basic(ResolverType resolverType)
        {
            var task = new TaskDefinition(
                new BasicTaskStep(
                    FailingStepName,
                    () => throw _error));

            test(task, resolverType);
        }
Esempio n. 15
0
        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));
        }
Esempio n. 16
0
        private void test_conditional_execution(
            ResolverType resolverType,
            TaskDefinition task,
            bool testedStepExecuted)
        {
            // Act
            task.Execute(resolverType, cancellation: _cancellationSource);

            // Assert
            _testedStepExecuted.Should().Be(testedStepExecuted);
        }
Esempio n. 17
0
 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;
 }
Esempio n. 18
0
        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());
        }
Esempio n. 19
0
        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);
        }
Esempio n. 20
0
 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)
     }));
Esempio n. 21
0
        public void basic_automatic(ResolverType resolverType)
        {
            var task = new TaskDefinition(
                new BasicTaskStep(
                    "Cancel",
                    _cancellationSource.Cancel),
                new BasicTaskStep(
                    "Complete",
                    () => { _completed = true; }));

            test(task, resolverType);
        }
Esempio n. 22
0
        public void custom_conditon(
            ResolverType resolverType,
            bool shouldExecute)
        {
            var task = new TaskDefinition(
                new BasicTaskStep(
                    "TestedStep",
                    () => { _testedStepExecuted = true; },
                    _ => shouldExecute));

            test_conditional_execution(resolverType, task, shouldExecute);
        }
Esempio n. 23
0
        /// <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);
        }
Esempio n. 24
0
        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);
        }
Esempio n. 25
0
        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());
        }
Esempio n. 26
0
        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);
        }
Esempio n. 28
0
        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);
        }
Esempio n. 29
0
        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);
 }