public void Get_AllConfigurationPopulated_Generated() { var provider = new CommandLineProvider(); var commandLine = provider.Get( "TestSource", new Dictionary <string, string> { { "SourceArg1", "value" }, { "SourceArg2", "42" } }, "TestSink", new Dictionary <string, string> { { "SinkArg1", "100" }, { "SinkArg2", "value" } }); Assert.AreEqual(96, commandLine.Length, TestResources.InvalidCommandLineLength); StringAssert.Contains(commandLine, "/s:TestSource", TestResources.CommandLineArgumentMissing); StringAssert.Contains(commandLine, "/s.SourceArg1:value", TestResources.CommandLineArgumentMissing); StringAssert.Contains(commandLine, "/s.SourceArg2:42", TestResources.CommandLineArgumentMissing); StringAssert.Contains(commandLine, "/t:TestSink", TestResources.CommandLineArgumentMissing); StringAssert.Contains(commandLine, "/t.SinkArg1:100", TestResources.CommandLineArgumentMissing); StringAssert.Contains(commandLine, "/t.SinkArg2:value", TestResources.CommandLineArgumentMissing); }
public void Get_NoInfrastructureArguments_Generated() { var provider = new CommandLineProvider(); var commandLine = provider.Get( null, "AnotherSource", new Dictionary <string, string> { { "SourceArg1", "value42" }, { "SourceArg2", "1" } }, "SomeSink", new Dictionary <string, string> { { "SinkArg1", "351" }, { "SinkArg2", "hello" } }); Assert.AreEqual(100, commandLine.Length, TestResources.InvalidCommandLineLength); StringAssert.Contains(commandLine, "/s:AnotherSource", TestResources.CommandLineArgumentMissing); StringAssert.Contains(commandLine, "/s.SourceArg1:value42", TestResources.CommandLineArgumentMissing); StringAssert.Contains(commandLine, "/s.SourceArg2:1", TestResources.CommandLineArgumentMissing); StringAssert.Contains(commandLine, "/t:SomeSink", TestResources.CommandLineArgumentMissing); StringAssert.Contains(commandLine, "/t.SinkArg1:351", TestResources.CommandLineArgumentMissing); StringAssert.Contains(commandLine, "/t.SinkArg2:hello", TestResources.CommandLineArgumentMissing); }
public void Get_NoSourceArguments_Generated() { var provider = new CommandLineProvider(); var commandLine = provider.Get( Mocks.Of <IInfrastructureConfiguration>(c => c.ErrorLog == "somefile.csv" && c.OverwriteErrorLog == false).First(), "AnotherSource", null, "SomeSink", new Dictionary <string, string> { { "SinkArg1", "351" }, { "SinkArg2", "hello" } }); Assert.AreEqual(85, commandLine.Length, TestResources.InvalidCommandLineLength); StringAssert.Contains(commandLine, "/ErrorLog:somefile.csv", TestResources.CommandLineArgumentMissing); StringAssert.Contains(commandLine, "/s:AnotherSource", TestResources.CommandLineArgumentMissing); StringAssert.Contains(commandLine, "/t:SomeSink", TestResources.CommandLineArgumentMissing); StringAssert.Contains(commandLine, "/t.SinkArg1:351", TestResources.CommandLineArgumentMissing); StringAssert.Contains(commandLine, "/t.SinkArg2:hello", TestResources.CommandLineArgumentMissing); }
public void Get_SwitchArgument_Generated() { var provider = new CommandLineProvider(); var commandLine = provider.Get( Mocks.Of <IInfrastructureConfiguration>(c => c.ErrorLog == "file.csv" && c.OverwriteErrorLog == true).First(), "TestSource", new Dictionary <string, string> { { "SwitchArg", null }, }, "TestSink", new Dictionary <string, string> { { "SinkArg1", "whatever" }, }); Assert.AreEqual(97, commandLine.Length, TestResources.InvalidCommandLineLength); StringAssert.Contains(commandLine, "/ErrorLog:file.csv", TestResources.CommandLineArgumentMissing); StringAssert.Contains(commandLine, "/OverwriteErrorLog", TestResources.CommandLineArgumentMissing); StringAssert.Contains(commandLine, "/s:TestSource", TestResources.CommandLineArgumentMissing); StringAssert.Contains(commandLine, "/s.SwitchArg", TestResources.CommandLineArgumentMissing); StringAssert.Contains(commandLine, "/t:TestSink", TestResources.CommandLineArgumentMissing); StringAssert.Contains(commandLine, "/t.SinkArg1:whatever", TestResources.CommandLineArgumentMissing); }
public void Get_QuotesAndSpacesInArgument_Generated() { var provider = new CommandLineProvider(); var commandLine = provider.Get( Mocks.Of <IInfrastructureConfiguration>(c => c.ErrorLog == @"d:\path with spaces and ""quotes""\file.csv" && c.OverwriteErrorLog == false).First(), "TestSource", new Dictionary <string, string> { { "SourceArg1", "42" }, }, "TestSink", new Dictionary <string, string> { { "SinkArg1", "quotes\" and \"spaces" }, }); Assert.AreEqual(138, commandLine.Length, TestResources.InvalidCommandLineLength); StringAssert.Contains(commandLine, "/ErrorLog:\"d:\\path with spaces and \"\"\"quotes\"\"\"\\file.csv\"", TestResources.CommandLineArgumentMissing); StringAssert.Contains(commandLine, "/s:TestSource", TestResources.CommandLineArgumentMissing); StringAssert.Contains(commandLine, "/s.SourceArg1:42", TestResources.CommandLineArgumentMissing); StringAssert.Contains(commandLine, "/t:TestSink", TestResources.CommandLineArgumentMissing); StringAssert.Contains(commandLine, "/t.SinkArg1:\"quotes\"\"\" and \"\"\"spaces\"", TestResources.CommandLineArgumentMissing); }
public void Get_AllConfigurationPopulated_Generated() { var provider = new CommandLineProvider(); var commandLine = provider.Get( Mocks.Of <IInfrastructureConfiguration>(c => c.ErrorLog == "errors.csv" && c.OverwriteErrorLog == false).First(), "TestSource", new Dictionary <string, string> { { "SourceArg1", "value" }, { "SourceArg2", "42" } }, "TestSink", new Dictionary <string, string> { { "SinkArg1", "100" }, { "SinkArg2", "value" } }); Assert.AreEqual(117, commandLine.Length, TestResources.InvalidCommandLineLength); StringAssert.Contains(commandLine, "/ErrorLog:errors.csv", TestResources.CommandLineArgumentMissing); StringAssert.Contains(commandLine, "/s:TestSource", TestResources.CommandLineArgumentMissing); StringAssert.Contains(commandLine, "/s.SourceArg1:value", TestResources.CommandLineArgumentMissing); StringAssert.Contains(commandLine, "/s.SourceArg2:42", TestResources.CommandLineArgumentMissing); StringAssert.Contains(commandLine, "/t:TestSink", TestResources.CommandLineArgumentMissing); StringAssert.Contains(commandLine, "/t.SinkArg1:100", TestResources.CommandLineArgumentMissing); StringAssert.Contains(commandLine, "/t.SinkArg2:value", TestResources.CommandLineArgumentMissing); }
public static async Task Main(string[] args) { var commandLineProvider = new CommandLineProvider(); var filePathProvider = new FilePathProvider(commandLineProvider); var builder = new HostBuilder() .ConfigureAppConfiguration((hostingContext, config) => { ConfigureHost(config, args, filePathProvider); }) .ConfigureServices((hostContext, services) => { services.AddOptions(); services.Configure <BotConfig>(hostContext.Configuration.GetSection("config")); services.AddSingleton <IHostedService, BotService>(); services.AddSingleton <IDataStorage, DataStorage>(); services.AddSingleton <IConfigProvider, ConfigProvider>(); services.AddSingleton <BotTelegramClient, BotTelegramClient>(); services.AddSingleton <IBotTelegramClient>(s => s.GetRequiredService <BotTelegramClient>()); services.AddSingleton <IBotTelegramClientControl>(s => s.GetRequiredService <BotTelegramClient>()); services.AddSingleton(commandLineProvider); services.AddSingleton(filePathProvider); //services.AddSingleton<AsusRouterRequestService>(); services.AddSingleton <KeeneticRouterRequestService>(); services.AddSingleton <TransmissionService>(); var types = Assembly.GetExecutingAssembly() .GetTypes() .ToArray(); // Поиск и регистрация обработчиков команд. foreach (var type in types) { if (!typeof(IBotCommandHandler).IsAssignableFrom(type) || !type.IsClass) { continue; } services.AddSingleton(typeof(IBotCommandHandler), type); services.AddSingleton(type, type); } services.AddSingleton <IBotDocumentHandler, TorrentDocumentHandler>(); }) .ConfigureLogging((hostingContext, logging) => { ConfigureLogging(logging); }); await builder.RunConsoleAsync(); }
public void Get_ArgumentWithNewLines_NewLinesRemoved() { var provider = new CommandLineProvider(); var commandLine = provider.Get( null, "TestSource", new Dictionary <string, string> { { "TestArg", "Hello" + Environment.NewLine + "World!" }, }, "TestSink", null); Assert.AreEqual(52, commandLine.Length, TestResources.InvalidCommandLineLength); StringAssert.Contains(commandLine, "/s:TestSource", TestResources.CommandLineArgumentMissing); StringAssert.Contains(commandLine, "/s.TestArg:\"Hello World!\"", TestResources.CommandLineArgumentMissing); StringAssert.Contains(commandLine, "/t:TestSink", TestResources.CommandLineArgumentMissing); }
public void Get_NoSinkArguments_Generated() { var provider = new CommandLineProvider(); var commandLine = provider.Get( "SomeSource", new Dictionary <string, string> { { "SourceArg1", "world" }, { "SourceArg2", "50" } }, "AnotherSink", null); Assert.AreEqual(66, commandLine.Length, TestResources.InvalidCommandLineLength); StringAssert.Contains(commandLine, "/s:SomeSource", TestResources.CommandLineArgumentMissing); StringAssert.Contains(commandLine, "/s.SourceArg1:world", TestResources.CommandLineArgumentMissing); StringAssert.Contains(commandLine, "/s.SourceArg2:50", TestResources.CommandLineArgumentMissing); StringAssert.Contains(commandLine, "/t:AnotherSink", TestResources.CommandLineArgumentMissing); }
protected override DependencyObject CreateShell() { var settings = Container.Resolve <IApplicationSettings>(); settings.Reload(); var arguments = new CommandLineProvider <CommandLineOptions>().CreateArgumentsModel(CommandLineParser.Parse(args)); if (arguments.IsValid) { if (arguments.Reset) { settings.Reset(); } } var model = Container.Resolve <IMainWindowViewModel>(); model.ShowView(); return(model.View as DependencyObject); }
public BotService( ILogger <BotService> logger, IEnumerable <IBotCommandHandler> botCommandHandlers, IEnumerable <IBotDocumentHandler> botDocumentHandlers, IBotTelegramClientControl botClientControl, IBotTelegramClient botClient, IConfigProvider configProvider, CommandLineProvider commandLineProvider) { _logger = logger; _botClientControl = botClientControl; _botClient = botClient; _commandLineProvider = commandLineProvider; _config = configProvider.CurrentConfig; configProvider.Changed += OnConfigChanged; _botDocumentHandlers = botDocumentHandlers.ToArray(); foreach (var botCommand in botCommandHandlers) { foreach (var command in botCommand.SupportedCommands) { if (string.IsNullOrWhiteSpace(command)) { continue; } var commandText = command; if (!IsCommand(commandText)) { commandText = CommandPrefix + commandText; } _botCommandHandlers.Add(commandText.ToLower(), botCommand); } } _botClientControl.OnMessageReceived += BotOnMessageReceived; }
public void Get_SpacesInArgument_Generated() { var provider = new CommandLineProvider(); var commandLine = provider.Get( "TestSource", new Dictionary <string, string> { { "SourceArg1", "value with spaces" }, }, "TestSink", new Dictionary <string, string> { { "SinkArg1", "42" }, }); Assert.AreEqual(74, commandLine.Length, TestResources.InvalidCommandLineLength); StringAssert.Contains(commandLine, "/s:TestSource", TestResources.CommandLineArgumentMissing); StringAssert.Contains(commandLine, "/s.SourceArg1:\"value with spaces\"", TestResources.CommandLineArgumentMissing); StringAssert.Contains(commandLine, "/t:TestSink", TestResources.CommandLineArgumentMissing); StringAssert.Contains(commandLine, "/t.SinkArg1:42", TestResources.CommandLineArgumentMissing); }
public void Get_SwitchArgument_Generated() { var provider = new CommandLineProvider(); var commandLine = provider.Get( "TestSource", new Dictionary <string, string> { { "SwitchArg", null }, }, "TestSink", new Dictionary <string, string> { { "SinkArg1", "whatever" }, }); Assert.AreEqual(59, commandLine.Length, TestResources.InvalidCommandLineLength); StringAssert.Contains(commandLine, "/s:TestSource", TestResources.CommandLineArgumentMissing); StringAssert.Contains(commandLine, "/s.SwitchArg", TestResources.CommandLineArgumentMissing); StringAssert.Contains(commandLine, "/t:TestSink", TestResources.CommandLineArgumentMissing); StringAssert.Contains(commandLine, "/t.SinkArg1:whatever", TestResources.CommandLineArgumentMissing); }