public void Invalid_FallbackValue_Logs_Error() { var called = false; LogCallback checkLogMessage = (level, area, src, mt, pv) => { if (level == LogEventLevel.Warning && area == LogArea.Binding && mt == "Error in binding to {Target}.{Property}: {Message}" && pv.Length == 3 && pv[0] is ProgressBar && object.ReferenceEquals(pv[1], ProgressBar.ValueProperty) && (string)pv[2] == "Could not convert FallbackValue 'bar' to 'System.Double'") { called = true; } }; using (UnitTestApplication.Start(TestServices.StyledWindow)) using (TestLogSink.Start(checkLogMessage)) { var xaml = @" <Window xmlns='https://github.com/avaloniaui'> <ProgressBar Maximum='10' Value='{Binding Value, FallbackValue=bar}'/> </Window>"; var window = (Window)AvaloniaRuntimeXamlLoader.Load(xaml); var progressBar = (ProgressBar)window.Content; window.DataContext = new { Value = "foo" }; window.ApplyTemplate(); Assert.Equal(0, progressBar.Value); Assert.True(called); } }
public void Bind_Logs_BindingError() { var target = new Class1(); var source = new Subject <object>(); var called = false; var expectedMessageTemplate = "Error binding to {Target}.{Property}: {Message}"; LogCallback checkLogMessage = (level, area, src, mt, pv) => { if (level == LogEventLevel.Error && area == LogArea.Binding && mt == expectedMessageTemplate) { called = true; } }; using (TestLogSink.Start(checkLogMessage)) { target.Bind(Class1.QuxProperty, source); source.OnNext(6.7); source.OnNext(new BindingError(new InvalidOperationException("Foo"))); Assert.Equal(6.7, target.GetValue(Class1.QuxProperty)); Assert.True(called); } }
public void Binding_To_Direct_Property_Logs_BindingError() { var target = new Class1(); var source = new Subject <object>(); var called = false; LogCallback checkLogMessage = (level, area, src, mt, pv) => { if (level == LogEventLevel.Warning && area == LogArea.Binding && mt == "Error in binding to {Target}.{Property}: {Message}" && pv.Length == 3 && pv[0] is Class1 && object.ReferenceEquals(pv[1], Class1.FooProperty) && (string)pv[2] == "Binding Error Message") { called = true; } }; using (TestLogSink.Start(checkLogMessage)) { target.Bind(Class1.FooProperty, source); source.OnNext("baz"); source.OnNext(new BindingNotification(new InvalidOperationException("Binding Error Message"), BindingErrorType.Error)); } Assert.True(called); }
public void Control_Should_Not_Log_Binding_Errors_When_Detached_From_Visual_Tree() { using (UnitTestApplication.Start(TestServices.StyledWindow)) { var xaml = @" <Window xmlns='https://github.com/avaloniaui' xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml' xmlns:local='clr-namespace:Avalonia.Base.UnitTests.Logging;assembly=Avalonia.UnitTests'> <Panel Name='panel'> <Rectangle Name='rect' Fill='{Binding $parent[Window].Background}'/> </Panel> </Window>"; var window = (Window)AvaloniaRuntimeXamlLoader.Load(xaml); var calledTimes = 0; using var logSink = TestLogSink.Start((l, a, s, m, d) => { if (l >= Avalonia.Logging.LogEventLevel.Warning) { calledTimes++; } }); var panel = window.FindControl <Panel>("panel"); var rect = window.FindControl <Rectangle>("rect"); window.ApplyTemplate(); window.Presenter.ApplyTemplate(); panel.Children.Remove(rect); Assert.Equal(0, calledTimes); } }
public void Control_Should_Log_Binding_Errors_When_No_Ancestor_With_Such_Name() { using (UnitTestApplication.Start(TestServices.StyledWindow)) { var xaml = @" <Window xmlns='https://github.com/avaloniaui' xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml' xmlns:local='clr-namespace:Avalonia.Base.UnitTests.Logging;assembly=Avalonia.UnitTests'> <Panel> <Rectangle Fill='{Binding $parent[Grid].Background}'/> </Panel> </Window>"; var calledTimes = 0; using var logSink = TestLogSink.Start((l, a, s, m, d) => { if (l >= Avalonia.Logging.LogEventLevel.Warning && s is Rectangle) { calledTimes++; } }); var window = (Window)AvaloniaRuntimeXamlLoader.Load(xaml); window.ApplyTemplate(); window.Presenter.ApplyTemplate(); Assert.Equal(1, calledTimes); } }
public void SetResult_ToUnknown_Throws() { var logSink = new TestLogSink(); var context = CreateChainContext(logSink: logSink); Assert.Throws <ArgumentOutOfRangeException>(() => context.SetResult(ExecutionResult.Unknown)); }
public void SetResult_CalledTwice_Throws() { var logSink = new TestLogSink(); var context = CreateChainContext(logSink: logSink); context.SetResult(ExecutionResult.Completed); Assert.Throws <NotSupportedException>(() => context.SetResult(ExecutionResult.Completed)); }
public void SetResult_Logs(ExecutionResult status, LogLevel logLevel) { const string reason = "TestReason"; var logSink = new TestLogSink(); var context = CreateChainContext(logSink: logSink); context.SetResult(status, null, reason); Assert.Contains(logSink.LogEntries, e => e.LogLevel == logLevel && e.Message.Contains(reason)); }
/// <summary> /// Create provider /// </summary> /// <param name="setups"></param> /// <returns></returns> public static IServiceProvider CreateProvider(Action <string, ClientConfigurator> customSetup, params ClientSetup[] setups) { // init collection var collection = new ServiceCollection(); // add logging var logSink = new TestLogSink(); collection.AddSingleton(logSink); collection.AddLogging(cfg => cfg.AddProvider(new TestLoggerProvider(logSink))); // setup clients setups.ToList().ForEach(setup => { // add grpc client one collection.AddGrpcClient(cfg => { // set name if (!string.IsNullOrWhiteSpace(setup.Name)) { cfg.SetName(setup.Name); } // add services cfg.AddService <ITestService>(); cfg.AddService <Greeter.GreeterClient>(); // add channels setup.Ports.ToList().ForEach(port => { cfg.AddHost(new GrpcChannelConnectionData { Port = port, Url = "127.0.0.1" }); }); // client options var opts = new GrpcClientOptions { TimeoutMs = setup.TimeoutMs, StatusServiceEnabled = setup.EnableStatus }; cfg.SetClientOptions(opts); // custom setup customSetup?.Invoke(setup.Name, cfg); }); }); // build provider for services return(collection.BuildServiceProvider()); }
public void Should_Not_Log_Binding_Error_When_Not_Attached_To_Logical_Tree() { var target = new Decorator { DataContext = "foo" }; var called = false; LogCallback checkLogMessage = (level, area, src, mt, pv) => { if (level >= Logging.LogEventLevel.Warning) { called = true; } }; using (TestLogSink.Start(checkLogMessage)) { target.Bind(Decorator.TagProperty, new Binding("Foo")); } Assert.False(called); }
public void SetUp() { sink = new TestLogSink(); // Tests that exercise filtering enable it themselves. logger = new Logger(sink, includeDebug: true); }
public TestLoggerProvider(TestLogSink sink) { _sink = sink; }