public void ConfigureChronoscopeWithBuilderOnlyRefusesNullBuilder() { // arrange IChronoscopeBuilder builder = null; // act var ex = Assert.Throws <ArgumentNullException>(() => builder.ConfigureChronoscope(b => { })); // assert Assert.Equal(nameof(builder), ex.ParamName); }
public void AddLoggerThrowsOnNullBuilder() { // arrange IChronoscopeBuilder builder = null; // act var ex = Assert.Throws <ArgumentNullException>(() => builder.AddLoggerSink(options => { })); // assert Assert.Equal(nameof(builder), ex.ParamName); }
public void AddLoggerThrowsOnNullConfigure() { // arrange IChronoscopeBuilder builder = Mock.Of <IChronoscopeBuilder>(); Action <LoggerSinkOptions> configure = null; // act var ex = Assert.Throws <ArgumentNullException>(() => builder.AddLoggerSink(configure)); // assert Assert.Equal(nameof(builder), ex.ParamName); }
/// <summary> /// Allows adding services to the underlying host. /// </summary> /// <param name="builder">The builder to extend.</param> /// <param name="configure">The callback to use for adding services.</param> /// <returns>The same builder instance to allow chaining.</returns> public static IChronoscopeBuilder ConfigureServices(this IChronoscopeBuilder builder, Action <IServiceCollection> configure) { if (builder is null) { throw new ArgumentNullException(nameof(builder)); } if (configure is null) { throw new ArgumentNullException(nameof(configure)); } return(builder.ConfigureServices((context, services) => configure(services))); }
/// <summary> /// Adds the <see cref="LoggerSink"/> to the specified <see cref="IChronoscopeBuilder"/> with the specified options. /// </summary> /// <param name="builder">The builder to add the sink to.</param> /// <param name="configure">The action to configure the sink options.</param> /// <returns>The specified builder to allow chaining.</returns> public static IChronoscopeBuilder AddLoggerSink(this IChronoscopeBuilder builder, Action <LoggerSinkOptions> configure) { if (builder is null) { throw new ArgumentNullException(nameof(builder)); } if (configure is null) { throw new ArgumentNullException(nameof(builder)); } return(builder.ConfigureServices(services => { services .AddSingleton <ITrackingSink, LoggerSink>() .AddOptions <LoggerSinkOptions>().Configure(configure).ValidateDataAnnotations(); })); }
static void configure(HostBuilderContext ctx, IChronoscopeBuilder b) /* noop */ }
static void configure(IChronoscopeBuilder b) /* noop */ }
/// <summary> /// Adds the <see cref="LoggerSink"/> to the specified <see cref="IChronoscopeBuilder"/>. /// </summary> /// <param name="builder">The builder to add the sink to.</param> /// <returns>The specified builder to allow chaining.</returns> public static IChronoscopeBuilder AddLoggerSink(this IChronoscopeBuilder builder) => builder.AddLoggerSink(options => { });