Exemplo n.º 1
0
        public void BuilderWithDependenciesTypeOverloadShouldAddTypeToCollection_OnValidTypeRegistration()
        {
            var commanderBuilder = new CommanderBuilder <TestContext>().WithDependencies(typeof(TestContext), typeof(StringBuilder));

            Assert.Contains(commanderBuilder.Dependencies, (x) => x.Key == typeof(StringBuilder));
            Assert.Contains(commanderBuilder.Dependencies, (x) => x.Key == typeof(TestContext));
        }
Exemplo n.º 2
0
        public void BuilderWithModulesShouldAddModule_OnCallingWithValidModuleTypeAsArgument()
        {
            var commanderBuilder = new CommanderBuilder <TestContext>().WithModules(typeof(TestModule), typeof(InvalidTestModuleNoNamesAttribute));

            Assert.Contains(commanderBuilder.Modules, x => x == typeof(TestModule));
            Assert.Contains(commanderBuilder.Modules, x => x == typeof(InvalidTestModuleNoNamesAttribute));
        }
Exemplo n.º 3
0
        public void BuilderWithDependenciesObjectInstanceOverloadShouldAddDependencies_OnValidDependenciesBeingRegistered(params object[] instances)
        {
            var commanderBuilder = new CommanderBuilder <TestContext>().WithDependencies(instances);

            foreach (var instance in instances)
            {
                Assert.Contains(commanderBuilder.Dependencies, x => x.Key == instance.GetType());
            }
        }
Exemplo n.º 4
0
        public void BuildingBuilderShouldBuildCorrectCommanderInstances_WhenUsedCorrectly()
        {
            var commander = new CommanderBuilder <TestContext>()
                            .WithDependencies(new TestService(10))
                            .WithModule <TestModule>()
                            .WithPrefix("!")
                            .WithDefaultParser()
                            .Build();

            Assert.Equal(typeof(DefaultParser <TestContext>), commander.Parser.GetType());
            Assert.Equal(typeof(TestModule), commander.RegisteredModules.First().Instance.GetType());
        }
Exemplo n.º 5
0
        private static void Main(string[] args)
        {
            var cmdr = new CommanderBuilder <ConsoleContext>()
                       .WithPrefix("!")
                       .WithDefaultParser()
                       .WithModule <MathsModule>()
                       .Build();

            cmdr.OnCommandExecuted += (source, eventArgs) =>
            {
                switch (eventArgs.Status)
                {
                case EventExecutionStatus.Executed:
                    Console.ForegroundColor = ConsoleColor.Green;
                    break;

                case EventExecutionStatus.InsufficientPermissions:
                    Console.ForegroundColor = ConsoleColor.Yellow;
                    break;

                case EventExecutionStatus.CommandNotFound:
                    Console.ForegroundColor = ConsoleColor.Red;
                    break;
                }
                Console.Write($"{eventArgs.Status}");
                Console.ForegroundColor = ConsoleColor.White;
                Console.WriteLine($": {eventArgs.Context.Message}");
            };
            Console.WriteLine("Valid Commands are !maths [add/multiply] [number(s)]");
            Console.WriteLine("e.g. !maths add 1 5 100");
            while (true)
            {
                var newContext = new ConsoleContext(Console.ReadLine());
                cmdr.ProcessMessageAsync(newContext).GetAwaiter().GetResult();
            }
        }
Exemplo n.º 6
0
        public void BuilderWithPrefixShouldNotThrowExceptionAndAssignPrefix_OnValidPrefixString(string testPrefix)
        {
            var commanderBuilder = new CommanderBuilder <TestContext>().WithPrefix(testPrefix);

            Assert.Equal(testPrefix, commanderBuilder.Instance.Prefix);
        }