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)); }
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)); }
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()); } }
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()); }
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(); } }
public void BuilderWithPrefixShouldNotThrowExceptionAndAssignPrefix_OnValidPrefixString(string testPrefix) { var commanderBuilder = new CommanderBuilder <TestContext>().WithPrefix(testPrefix); Assert.Equal(testPrefix, commanderBuilder.Instance.Prefix); }