示例#1
0
        public void ParseWithType_NullContainerType_ThrowsArgumentNullException()
        {
            Type containerType             = null;
            IEnumerable <string> arguments = Enumerable.Empty <string>();

            Assert.Throws <ArgumentNullException>(() => OptParser.Parse(containerType, arguments));
        }
示例#2
0
        public void ParseWithContainer_NullContainer_ThrowsArgumentNullException()
        {
            object container = null;
            IEnumerable <string> arguments = Enumerable.Empty <string>();

            Assert.Throws <ArgumentNullException>(() => OptParser.Parse(container, arguments));
        }
示例#3
0
        public void ParseWithType_NullArguments_ThrowsArgumentNullException()
        {
            Type containerType             = typeof(OptParserTests);
            IEnumerable <string> arguments = null;

            Assert.Throws <ArgumentNullException>(() => OptParser.Parse(containerType, arguments));
        }
示例#4
0
        public void ParseWithContainerType_WithEmptyArguments_ReturnsObjectOfRightType()
        {
            object container = OptParser.Parse(typeof(OptParserTests), Enumerable.Empty <string>());

            Assert.That(container, Is.Not.Null);
            Assert.That(container, Is.InstanceOf(typeof(OptParserTests)));
        }
示例#5
0
        public void ParseWithContainer_NullArguments_ThrowsArgumentNullException()
        {
            var container = new object();
            IEnumerable <string> arguments = null;

            Assert.Throws <ArgumentNullException>(() => OptParser.Parse(container, arguments));
        }
示例#6
0
        public void ParseGeneric_WithEmptyArguments_ReturnsObjectOfRightType()
        {
            IEnumerable <string> arguments = Enumerable.Empty <string>();

            var container = OptParser.Parse <OptParserTests>(arguments);

            Assert.That(container, Is.Not.Null);
            Assert.That(container, Is.InstanceOf(typeof(OptParserTests)));
        }
示例#7
0
文件: Program.cs 项目: lassevk/Decked
        private static void Execute(string[] args)
        {
            var options = OptParser.Parse <CommandLineOptions>(args);

            assume(options != null);

            var logger = new ConsoleLogger(options);

            var container = new Container(Rules.Default.WithAutoConcreteTypeResolution());

            container.RegisterInstance <ILogger>(logger);

            var problems = options.GetProblems().ToList();

            if (problems.Any())
            {
                foreach (var problem in problems)
                {
                    System.Console.Error.WriteLine(problem);
                }
                Environment.Exit(1);
            }

            assume(options.MainScreenFilename != null);
            System.Console.WriteLine($"loading screen {Path.GetFullPath(options.MainScreenFilename)}");

            var initialScreenConfiguration = ScreenConfiguration.Load(options.MainScreenFilename);
            var pathResolver = new PathResolver(Path.GetDirectoryName(Path.GetFullPath(options.MainScreenFilename)));

            container.RegisterInstance <IPathResolver>(pathResolver);

            var deck = new DeckRunner(container, logger, pathResolver);

            container.RegisterInstance <IStreamDeckServices>(deck);

            deck.InitializeScreen(initialScreenConfiguration);

            //AppDomain.CurrentDomain.AssemblyResolve += delegate(object sender, ResolveEventArgs eventArgs)
            //                                           {
            //                                               System.Console.WriteLine(eventArgs.Name);

            //                                               return null;
            //                                           };

            deck.Run().GetAwaiter().GetResult();
        }
示例#8
0
        public void SupportedIntegerType_IsSetProperly(Type integerType, object value)
        {
            Type         finishedType = TypeCreator.CreateContainerType(integerType, typeof(IntegerOptionAttribute));
            object       instance     = Activator.CreateInstance(finishedType);
            PropertyInfo property     = finishedType.GetProperty("Value");

            var arguments = new[]
            {
                "-p", value.ToString()
            };

            string[] leftOvers = OptParser.Parse(instance, arguments);

            CollectionAssert.AreEqual(leftOvers, new string[0]);

            object propertyValue = property.GetValue(instance, null);

            Assert.That(propertyValue, Is.EqualTo(value));
        }
示例#9
0
        public void ParseGeneric_NullArguments_ThrowsArgumentNullException()
        {
            IEnumerable <string> arguments = null;

            Assert.Throws <ArgumentNullException>(() => OptParser.Parse <OptParserTests>(arguments));
        }
示例#10
0
        public void ArgumentsProperty_GetsLeftOverArguments()
        {
            var options = OptParser.Parse <OptionsWithArguments>(new[] { "arg1", "arg2", "arg3", "arg4" });

            CollectionAssert.AreEqual(options.Args, new[] { "arg3", "arg4" });
        }
示例#11
0
        public void SecondArgumentProperty_WhenTwoArgumentsArePassed_IsFilledWithArgument()
        {
            var options = OptParser.Parse <OptionsWithArguments>(new[] { "arg1", "arg2" });

            Assert.That(options.Arg2, Is.EqualTo("arg2"));
        }
示例#12
0
        public void SecondArgumentProperty_WhenOnlyOneArgumentIsPassed_IsNotFilledWithArgument()
        {
            var options = OptParser.Parse <OptionsWithArguments>(new[] { "arg1" });

            Assert.That(options.Arg2, Is.EqualTo(string.Empty));
        }
示例#13
0
        public void FirstArgumentProperty_WhenOnlyOneArgumentIsPassed_IsFilledWithArgument()
        {
            var options = OptParser.Parse <OptionsWithArguments>(new[] { "arg1" });

            Assert.That(options.Arg1, Is.EqualTo("arg1"));
        }