public void ParsingNonExistentLongOptionFailsWithoutThrowingAnException() { var options = new SimpleOptions(); bool result = base.Parser.ParseArguments(new string[] { "--extend" }, options); base.AssertParserFailure(result); }
public void PassingNoValueToAStringTypeLongOptionFails() { var options = new SimpleOptions(); bool result = base.Parser.ParseArguments(new string[] { "--string" }, options); base.AssertParserFailure(result); }
public void ShortOptionRefusesEqualToken() { var options = new SimpleOptions(); Assert.IsFalse(base.Parser.ParseArguments(new string[] { "-i=10" }, options)); Console.WriteLine(options); }
public static IServiceCollection AddSimpleMiddleware(this IServiceCollection services, Action <SimpleOptions> action) { var options = new SimpleOptions(); action(options); return(services.AddTransient <ISimpleService, SimpleService>(factory => new SimpleService(options))); }
public void Passing_no_value_to_a_string_type_long_option_fails() { var options = new SimpleOptions(); var parser = new CommandLine.Parser(); var result = parser.ParseArguments(new string[] { "--string" }, options); result.Should().BeFalse(); }
public void Parsing_non_existent_long_option_fails_without_throwing_an_exception() { var options = new SimpleOptions(); var parser = new CommandLine.Parser(); var result = parser.ParseArguments(new string[] { "--extend" }, options); result.Should().BeFalse(); }
public void AllowSingleDashAsOptionInputValue() { var options = new SimpleOptions(); bool result = base.Parser.ParseArguments(new string[] { "--string", "-" }, options); base.AssertParserSuccess(result); Assert.AreEqual("-", options.StringValue); }
public void Parse_negative_integer_value() { var options = new SimpleOptions(); var parser = new CommandLine.Parser(); var result = parser.ParseArguments(new string[] { "-i", "-4096" }, options); result.Should().BeTrue(); options.IntegerValue.Should().Be(-4096); }
public void Allow_single_dash_as_option_input_value() { var options = new SimpleOptions(); var parser = new CommandLine.Parser(); var result = parser.ParseArguments(new string[] { "--string", "-" }, options); result.Should().BeTrue(); options.StringValue.Should().Be("-"); }
public void Short_option_refuses_equal_token() { var options = new SimpleOptions(); var parser = new CommandLine.Parser(); var result = parser.ParseArguments(new string[] { "-i=10" }, options); result.Should().BeFalse(); Console.WriteLine(options); }
public void ParseStringOption() { var options = new SimpleOptions(); bool result = base.Parser.ParseArguments(new string[] { "-s", "something" }, options); base.AssertParserSuccess(result); Assert.AreEqual("something", options.StringValue); Console.WriteLine(options); }
public void Parse_string_option() { var options = new SimpleOptions(); var parser = new CommandLine.Parser(); var result = parser.ParseArguments(new string[] { "-s", "something" }, options); result.Should().BeTrue(); options.StringValue.Should().Be("something"); Console.WriteLine(options); }
public void ParseStringIntegerBoolOptions() { var options = new SimpleOptions(); bool result = base.Parser.ParseArguments( new string[] { "-s", "another string", "-i100", "--switch" }, options); base.AssertParserSuccess(result); Assert.AreEqual("another string", options.StringValue); Assert.AreEqual(100, options.IntegerValue); Assert.AreEqual(true, options.BooleanValue); Console.WriteLine(options); }
public void Parse_string_integer_bool_options() { var options = new SimpleOptions(); bool result = CommandLine.Parser.Default.ParseArguments( new string[] { "-s", "another string", "-i100", "--switch" }, options); result.Should().BeTrue(); options.StringValue.Should().Be("another string"); options.IntegerValue.Should().Be(100); options.BooleanValue.Should().BeTrue(); Console.WriteLine(options); }
public void Parse_strict_bad_input_fails_and_exits() { var options = new SimpleOptions(); var testWriter = new StringWriter(); ReflectionHelper.AssemblyFromWhichToPullInformation = Assembly.GetExecutingAssembly(); var parser = new CommandLine.Parser(with => with.HelpWriter = testWriter); var result = parser.ParseArgumentsStrict(new string[] { "--bad", "--input" }, options, () => Console.WriteLine("fake fail")); result.Should().BeFalse(); var helpText = testWriter.ToString(); Console.WriteLine(helpText); var lines = helpText.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries); // Did we really produced all help? lines.Should().HaveCount(n => n == 8); // Verify just significant output lines[5].Trim().Should().Be("-s, --string"); lines[6].Trim().Should().Be("-i"); lines[7].Trim().Should().Be("--switch"); }
private static void ShowStandardMsg(NotificationType type, SimpleOptions options) { NotificationFactory.ShowMessageNotification (options.header, options.text, options.timeout, options.width, options.height, type, new TimerEndedHandler (TimerEnded)); }
public static void Main(string[] args) { Application.Init (); SimpleOptions options = new SimpleOptions (); options.ProcessArgs (args); bool collecting = false; StringBuilder textbuilder = new StringBuilder (); StringBuilder headerbuilder = new StringBuilder (); foreach (string s in args) { if (s == "--text") { collecting = true; continue; } else if (s.StartsWith ("--") && collecting) collecting = false; if (collecting) textbuilder.Append (s + " "); } options.text = textbuilder.ToString (); foreach (string s in args) { if (s == "--header") { collecting = true; continue; } else if (s.StartsWith ("--") && collecting) collecting = false; if (collecting) headerbuilder.Append (s + " "); } options.header = headerbuilder.ToString (); if (args.Length == 0) { options.DoHelp (); Environment.Exit (1); } //We are receiving html if (options.html) { NotificationSource sourceType = NotificationSource.Url; string source = null; if (options.content != null) { sourceType = NotificationSource.Text; source = options.content; } else if (options.file != null) { sourceType = NotificationSource.File; source = options.file; } else if (options.url != null) { sourceType = NotificationSource.Url; source = options.url; } else options.DoHelp (); NotificationFactory.ShowHtmlNotification (source, sourceType, options.width, options.height, options.timeout, new TimerEndedHandler (TimerEnded)); } // We are receiving svg else if (options.svg) { if (options.file != null) NotificationFactory.ShowSvgNotification (options.file, options.header, options.text, options.width, options.height, options.timeout, new TimerEndedHandler (TimerEnded)); else if (options.warning) ShowStandardMsg (NotificationType.Warning, options); else if (options.info) ShowStandardMsg (NotificationType.Info, options); else if (options.error) ShowStandardMsg (NotificationType.Error, options); else options.DoHelp (); } else options.DoHelp (); Application.Run (); }
private static void ShowStandardMsg(NotificationType type, SimpleOptions options) { NotificationFactory.ShowMessageNotification(options.header, options.text, options.timeout, options.width, options.height, type, new TimerEndedHandler(TimerEnded)); }
public static void Main(string[] args) { Application.Init(); SimpleOptions options = new SimpleOptions(); options.ProcessArgs(args); bool collecting = false; StringBuilder textbuilder = new StringBuilder(); StringBuilder headerbuilder = new StringBuilder(); foreach (string s in args) { if (s == "--text") { collecting = true; continue; } else if (s.StartsWith("--") && collecting) { collecting = false; } if (collecting) { textbuilder.Append(s + " "); } } options.text = textbuilder.ToString(); foreach (string s in args) { if (s == "--header") { collecting = true; continue; } else if (s.StartsWith("--") && collecting) { collecting = false; } if (collecting) { headerbuilder.Append(s + " "); } } options.header = headerbuilder.ToString(); if (args.Length == 0) { options.DoHelp(); Environment.Exit(1); } //We are receiving html if (options.html) { NotificationSource sourceType = NotificationSource.Url; string source = null; if (options.content != null) { sourceType = NotificationSource.Text; source = options.content; } else if (options.file != null) { sourceType = NotificationSource.File; source = options.file; } else if (options.url != null) { sourceType = NotificationSource.Url; source = options.url; } else { options.DoHelp(); } NotificationFactory.ShowHtmlNotification(source, sourceType, options.width, options.height, options.timeout, new TimerEndedHandler(TimerEnded)); } // We are receiving svg else if (options.svg) { if (options.file != null) { NotificationFactory.ShowSvgNotification(options.file, options.header, options.text, options.width, options.height, options.timeout, new TimerEndedHandler(TimerEnded)); } else if (options.warning) { ShowStandardMsg(NotificationType.Warning, options); } else if (options.info) { ShowStandardMsg(NotificationType.Info, options); } else if (options.error) { ShowStandardMsg(NotificationType.Error, options); } else { options.DoHelp(); } } else { options.DoHelp(); } Application.Run(); }
[InlineData(3, 2, 5, 1, 6)] // Use page size 3 to allow insertions without bounds changes. public async Task Execute(int maxLeavesPerPage, int minExisting, int maxExisting, int minUpdated, int maxUpdated) { var config = new Catalog2RegistrationConfiguration(); var options = new SimpleOptions <Catalog2RegistrationConfiguration>(config); var logger = new NullLogger <HiveMerger>(); var target = new HiveMerger(options, logger); config.MaxLeavesPerPage = maxLeavesPerPage; var allExisting = Enumerable.Range(minExisting, (maxExisting - minExisting) + 1).Select(m => new NuGetVersion(m, 0, 0)).ToList(); var allUpdated = Enumerable.Range(minUpdated, (maxUpdated - minUpdated) + 1).Select(m => new NuGetVersion(m, 0, 0)).ToList(); var versionToNormalized = allExisting.Concat(allUpdated).Distinct().ToDictionary(v => v, v => v.ToNormalizedString()); // Enumerate all of the updated version sets, which is up to 9 versions and for each set every // combination of either PackageDelete or PackageDetails for each version. var deleteOrNotDelete = new[] { true, false }; var updatedCases = IterTools .SubsetsOf(allUpdated) .SelectMany(vs => IterTools.CombinationsOfTwo(vs.ToList(), deleteOrNotDelete)) .Select(ts => ts.Select(t => new VersionAction(t.Item1, t.Item2)).OrderBy(v => v.Version).ToList()) .ToList(); // Enumerate all of the updated version sets, which is up to 7 versions. var existingCases = IterTools .SubsetsOf(allExisting) .Select(vs => vs.OrderBy(v => v).ToList()) .ToList(); // Build all of the test cases which is every pairing of updated and existing cases. var testCases = new ConcurrentBag <TestCase>(); foreach (var existing in existingCases) { foreach (var updated in updatedCases) { testCases.Add(new TestCase(existing, updated)); } } var completed = 0; var total = testCases.Count; var outputLock = new object(); await ParallelAsync .Repeat(async() => { await Task.Yield(); while (testCases.TryTake(out var testCase)) { try { await ExecuteTestCaseAsync(config, target, versionToNormalized, testCase); var thisCompleted = Interlocked.Increment(ref completed); if (thisCompleted % 20000 == 0) { lock (outputLock) { _output.WriteLine($"Progress: {1.0 * thisCompleted / total:P}"); } } } catch (Exception ex) { lock (outputLock) { _output.WriteLine(string.Empty); _output.WriteLine("Test Case Failure"); _output.WriteLine(new string('=', 50)); _output.WriteLine(ex.Message); _output.WriteLine(string.Empty); _output.WriteLine("Existing: " + string.Join(", ", testCase.Existing)); _output.WriteLine("Changes: " + string.Join(", ", testCase.Updated.Select(t => $"{(t.IsDelete ? '-' : '+')}{t.Version}"))); _output.WriteLine(new string('=', 50)); _output.WriteLine(string.Empty); return; } } } }, degreeOfParallelism : 8); _output.WriteLine($"Progress: {1.0 * completed / total:P}"); _output.WriteLine($"Total test cases: {total}"); _output.WriteLine($"Completed test cases: {completed}"); Assert.Equal(total, completed); }
public SimpleService(SimpleOptions options) { _options = options; }
public Trigger(IOperableTrigger newTrigger, string schedulerInstanceName) { if (newTrigger == null) { return; } Name = newTrigger.Key.Name; Group = newTrigger.Key.Group; JobName = newTrigger.JobKey.Name; JobKey = $"{JobName}/{newTrigger.JobKey.Group}"; Scheduler = schedulerInstanceName; State = InternalTriggerState.Waiting; Description = newTrigger.Description; CalendarName = newTrigger.CalendarName; JobDataMap = newTrigger.JobDataMap.WrappedMap; FinalFireTimeUtc = newTrigger.FinalFireTimeUtc; MisfireInstruction = newTrigger.MisfireInstruction; Priority = newTrigger.Priority; HasMillisecondPrecision = newTrigger.HasMillisecondPrecision; FireInstanceId = newTrigger.FireInstanceId; EndTimeUtc = newTrigger.EndTimeUtc; StartTimeUtc = newTrigger.StartTimeUtc; NextFireTimeUtc = newTrigger.GetNextFireTimeUtc(); PreviousFireTimeUtc = newTrigger.GetPreviousFireTimeUtc(); if (NextFireTimeUtc != null) { NextFireTimeTicks = NextFireTimeUtc.Value.UtcTicks; } // Init trigger specific properties according to type of newTrigger. // If an option doesn't apply to the type of trigger it will stay null by default. switch (newTrigger) { case CronTriggerImpl cronTriggerImpl: Cron = new CronOptions { CronExpression = cronTriggerImpl.CronExpressionString, TimeZoneId = cronTriggerImpl.TimeZone.Id }; return; case SimpleTriggerImpl simpTriggerImpl: Simp = new SimpleOptions { RepeatCount = simpTriggerImpl.RepeatCount, RepeatInterval = simpTriggerImpl.RepeatInterval }; return; case CalendarIntervalTriggerImpl calTriggerImpl: Cal = new CalendarOptions { RepeatIntervalUnit = calTriggerImpl.RepeatIntervalUnit, RepeatInterval = calTriggerImpl.RepeatInterval, TimesTriggered = calTriggerImpl.TimesTriggered, TimeZoneId = calTriggerImpl.TimeZone.Id, PreserveHourOfDayAcrossDaylightSavings = calTriggerImpl.PreserveHourOfDayAcrossDaylightSavings, SkipDayIfHourDoesNotExist = calTriggerImpl.SkipDayIfHourDoesNotExist }; return; case DailyTimeIntervalTriggerImpl dayTriggerImpl: Day = new DailyTimeOptions { RepeatCount = dayTriggerImpl.RepeatCount, RepeatIntervalUnit = dayTriggerImpl.RepeatIntervalUnit, RepeatInterval = dayTriggerImpl.RepeatInterval, StartTimeOfDay = dayTriggerImpl.StartTimeOfDay, EndTimeOfDay = dayTriggerImpl.EndTimeOfDay, DaysOfWeek = dayTriggerImpl.DaysOfWeek, TimesTriggered = dayTriggerImpl.TimesTriggered, TimeZoneId = dayTriggerImpl.TimeZone.Id }; break; } }