public void Create_0()
        {
            List <Argument> args = ArgumentFactory.Create("/", "=",
                                                          new[] { "/debug=on", "house", "/filter", "document.txt", "input" });

            Assert.AreEqual(5, args.Count);

            Assert.IsTrue(args[0] is ArgumentNamed);
            Assert.AreEqual("debug", ((ArgumentNamed)args[0]).Name);
            Assert.AreEqual("on", args[0].Value);
            Assert.AreEqual(0, args[0].Index);

            Assert.IsTrue(args[1] is ArgumentPassed);
            Assert.AreEqual(0, ((ArgumentPassed)args[1]).Order);
            Assert.AreEqual("house", args[1].Value);
            Assert.AreEqual(1, args[1].Index);

            Assert.IsTrue(args[2] is ArgumentNamed);
            Assert.AreEqual("filter", ((ArgumentNamed)args[2]).Name);
            Assert.IsNull(args[2].Value);
            Assert.AreEqual(2, args[2].Index);

            Assert.IsTrue(args[3] is ArgumentPassed);
            Assert.AreEqual(1, ((ArgumentPassed)args[3]).Order);
            Assert.AreEqual("document.txt", args[3].Value);
            Assert.AreEqual(3, args[3].Index);

            Assert.IsTrue(args[4] is ArgumentPassed);
            Assert.AreEqual(2, ((ArgumentPassed)args[4]).Order);
            Assert.AreEqual("input", args[4].Value);
            Assert.AreEqual(4, args[4].Index);
        }
Beispiel #2
0
        public void ConstructorFromExpression_Constant_Ok()
        {
            Argument <int> argument = ArgumentFactory.FromExpression(() => 1);

            Assert.Equal("Static value", argument.Name);
            Assert.Equal(1, argument.Value);
        }
Beispiel #3
0
        public void ConstructorFromExpression_InstanceProperty_Ok()
        {
            Argument <int> argument = ArgumentFactory.FromExpression(() => PrivateTestProperty);

            Assert.Equal(nameof(PrivateTestProperty), argument.Name);
            Assert.Equal(PrivateTestProperty, argument.Value);
        }
Beispiel #4
0
        public void ConstructorFromExpression_Constructor_Ok()
        {
            int             value    = 1;
            Argument <int?> argument = ArgumentFactory.FromExpression(() => new int?(value));

            Assert.Equal("Static value", argument.Name);
            Assert.Equal(new int?(value), argument.Value);
        }
Beispiel #5
0
        public void ConstructorFromExpression_Variable_Ok()
        {
            int            variableName = 1;
            Argument <int> argument     = ArgumentFactory.FromExpression(() => variableName);

            Assert.Equal(nameof(variableName), argument.Name);
            Assert.Equal(variableName, argument.Value);
        }
Beispiel #6
0
        public void ConstructorFromExpression_ObjectProperty_Ok()
        {
            ArgumentFactoryTest objWithProperty = new ArgumentFactoryTest();

            Argument <int> argument = ArgumentFactory.FromExpression(() => objWithProperty.PrivateTestProperty);

            Assert.Equal(nameof(PrivateTestProperty), argument.Name);
            Assert.Equal(PrivateTestProperty, argument.Value);
        }
        public void Create_1()
        {
            ArgumentNamed arg = ArgumentFactory.Create(2, "/", "=", "/debug=on") as ArgumentNamed;

            Assert.IsNotNull(arg);
            Assert.AreEqual("debug", arg.Name);
            Assert.AreEqual("on", arg.Value);
            Assert.AreEqual(2, arg.Index);
        }
        public void ExtractValue()
        {
            Assert.IsNull(ArgumentFactory.ExtractValue("/", "=", ""));
            Assert.IsNull(ArgumentFactory.ExtractValue("/", "=", "/debug"));

            Assert.AreEqual("on", ArgumentFactory.ExtractValue("/", "=", "/debug=on"));
            Assert.AreEqual("on", ArgumentFactory.ExtractValue("/", "=", "/debug=on"));
            Assert.AreEqual("debug", ArgumentFactory.ExtractValue("/", "=", "debug"));
            Assert.AreEqual("document.txt", ArgumentFactory.ExtractValue("/", "=", "document.txt"));
        }
        public void ExtractName()
        {
            Assert.IsNull(ArgumentFactory.ExtractName("/", "=", ""));
            Assert.IsNull(ArgumentFactory.ExtractName("/", "=", "/="));
            Assert.IsNull(ArgumentFactory.ExtractName("/", "=", "/=on"));

            Assert.AreEqual("debug", ArgumentFactory.ExtractName("/", "=", "/debug"));
            Assert.AreEqual("debug", ArgumentFactory.ExtractName("/", "=", "/debug=on"));
            Assert.AreEqual("debug", ArgumentFactory.ExtractName("/", "=", "debug"));
            Assert.AreEqual("debug", ArgumentFactory.ExtractName("/", "=", "debug=on"));
        }
Beispiel #10
0
        /// <summary>
        /// </summary>
        /// <param name="pOptions"></param>
        /// <param name="pValidator"></param>
        /// <param name="pArgs"></param>
        /// <param name="pDescs"></param>
        /// <returns></returns>
        private static Request Create(CliOptions pOptions, iValidator pValidator, IEnumerable <string> pArgs,
                                      ICollection <Description> pDescs)
        {
            IEnumerable <Argument> arguments = ArgumentFactory.Create(pOptions.Prefix, pOptions.EqualChar, pArgs);
            Request request = new Request(arguments, pDescs);

            if (pValidator != null)
            {
                request.Valid = pValidator.Validate(pDescs.ToList(), request);
            }
            return(request);
        }
Beispiel #11
0
        /// <inheritdoc/>
        public IArgument[] CreateArgumentsForClassIfNotExists(Type underlyingComponentType)
        {
            var argFactory = new ArgumentFactory();

            return(argFactory.CreateArgumentsForClassIfNotExistsGeneric(underlyingComponentType,

                                                                        //tell it how to create new instances of us related to parent
                                                                        this,

                                                                        //what arguments already exist
                                                                        PipelineComponentArguments.ToArray())

                   //convert the result back from generic to specific (us)
                   .Cast <PipelineComponentArgument>().ToArray());
        }
Beispiel #12
0
        private void RefreshArgumentList()
        {
            var argumentFactory = new ArgumentFactory();

            DemandDictionary = argumentFactory.GetDemandDictionary(_parent, _argumentsAreFor);

            lblNoArguments.Visible = !DemandDictionary.Any();
            pArguments.Visible     = DemandDictionary.Any();

            if (!DemandDictionary.Any())
            {
                return;
            }

            pArguments.Controls.Clear();
            pArguments.SuspendLayout();

            var headerLabel = GetLabelHeader("Arguments");

            pArguments.Controls.Add(headerLabel);

            _currentY       = headerLabel.Height;
            _maxValueUILeft = 0;
            _valueUIs.Clear();

            foreach (var kvp in DemandDictionary)
            {
                CreateLine(_parent, kvp.Key, kvp.Value);
            }

            foreach (Control control in _valueUIs)
            {
                control.Left  = _maxValueUILeft;
                control.Width = pArguments.Width - (_maxValueUILeft + 25);
                control.Parent.MinimumSize = new Size(_maxValueUILeft + control.MinimumSize.Width, control.Parent.Height);
            }

            pArguments.ResumeLayout(true);
        }
        private void RefreshArgumentList()
        {
            var argumentFactory = new ArgumentFactory();

            DemandDictionary = argumentFactory.GetDemandDictionary(_parent, _argumentsAreFor);

            lblNoArguments.Visible = !DemandDictionary.Any();
            pArguments.Visible     = DemandDictionary.Any();

            if (!DemandDictionary.Any())
            {
                return;
            }

            pArguments.Controls.Clear();
            pArguments.SuspendLayout();

            float maxArgNameWidth = 0;

            if (DemandDictionary.Any())
            {
                var g = this.CreateGraphics();
                maxArgNameWidth = DemandDictionary.Select(a =>
                                                          g.MeasureString(UsefulStuff.PascalCaseStringToHumanReadable(a.Value.Name), Label.DefaultFont).Width)
                                  .Max();
            }


            foreach (var kvp in DemandDictionary)
            {
                CreateLine(_parent, kvp.Key, kvp.Value, maxArgNameWidth);
            }

            //headerLabel.SendToBack();
            pArguments.ResumeLayout(true);
        }
        public void TestNestedDemandsGetPutIntoDatabaseAndCanBeBroughtBack()
        {
            var pipe = new Pipeline(CatalogueRepository, "NestedPipe");
            var pc   = new PipelineComponent(CatalogueRepository, pipe, typeof(BasicDataReleaseDestination), -1,
                                             "Coconuts");

            pipe.DestinationPipelineComponent_ID = pc.ID;
            pipe.SaveToDatabase();

            //some of the DemandsInitialization on BasicDataReleaseDestination should be nested
            var f = new ArgumentFactory();

            Assert.True(
                f.GetRequiredProperties(typeof(BasicDataReleaseDestination)).Any(r => r.ParentPropertyInfo != null));

            //new pc should have no arguments
            Assert.That(pc.GetAllArguments(), Is.Empty);

            //we create them (the root and nested ones!)
            var args = pc.CreateArgumentsForClassIfNotExists <BasicDataReleaseDestination>();

            //and get all arguments / create arguments for class should have handled that
            Assert.That(pc.GetAllArguments().Any());

            var match = args.Single(a => a.Name == "ReleaseSettings.DeleteFilesOnSuccess");

            match.SetValue(true);
            match.SaveToDatabase();

            var useCase = ReleaseUseCase.DesignTime();

            var factory      = new DataFlowPipelineEngineFactory(useCase, RepositoryLocator.CatalogueRepository.MEF);
            var destInstance = factory.CreateDestinationIfExists(pipe);

            Assert.AreEqual(true, ((BasicDataReleaseDestination)destInstance).ReleaseSettings.DeleteFilesOnSuccess);
        }
Beispiel #15
0
 /// <summary>
 /// Start validaton for an argument.
 /// WARNING.
 /// </summary>
 /// <typeparam name="T">Any type</typeparam>
 /// <param name="value">Validated argument</param>
 /// <returns>An object on which to call validation methods</returns>
 public static Argument <T> Validate <T>(Expression <Func <T> > value)
 {
     return(ArgumentFactory.FromExpression(value));
 }
 public void Create_2()
 {
     Argument arg = ArgumentFactory.Create(2, "/", "=", "/=on");
 }
Beispiel #17
0
 public CommandBuilder addArgument(String name, Type type = null, String description = null)
 {
     _arguments.Add(ArgumentFactory.create(name, type, description));
     return(this);
 }
Beispiel #18
0
        public Type[] ArgumentTypes(Type type)
        {
            ArgumentFactory argumentsFactory = argumentsFactorys.GetOrAdd(type, t => new ArgumentFactory(this.services, t));

            return(argumentsFactory.ArgumentTypes);
        }
Beispiel #19
0
        public object[] CreateArguments(IGrainActivationContext grainActivationContext)
        {
            ArgumentFactory argumentsFactory = argumentsFactorys.GetOrAdd(grainActivationContext.GrainType, type => new ArgumentFactory(this.services, type));

            return(argumentsFactory.CreateArguments(grainActivationContext));
        }