@@ -16,7 +16,9 @@ namespace ReactiveUI.Tests
1616{
1717 public class PocoObservableForPropertyTests
1818 {
19- private static TestLogger ? _testLoggerForNotificationPocoErrorOnBind ;
19+ #pragma warning disable CA1812 // Class is not instantiated
20+
21+ ////private static TestLogger? _testLoggerForNotificationPocoErrorOnBind;
2022
2123 [ Fact ]
2224 public void CheckGetAffinityForObjectValues ( )
@@ -28,81 +30,81 @@ public void CheckGetAffinityForObjectValues()
2830 Assert . Equal ( 1 , instance . GetAffinityForObject ( typeof ( INPCClass ) , null ! , false ) ) ;
2931 }
3032
31- [ Fact ( Skip = "Test Scheduler is null on occasions" ) ]
32- public void NotificationPocoErrorOnBind ( )
33- {
34- RxApp . EnsureInitialized ( ) ;
33+ //// [Fact(Skip = "Test Scheduler is null on occasions")]
34+ //// public void NotificationPocoErrorOnBind()
35+ //// {
36+ //// RxApp.EnsureInitialized();
3537
36- // Use same logger, when the test is executed multiple times in the same AndroidRunner/AppDomain/AssemblyLoadContext
37- if ( _testLoggerForNotificationPocoErrorOnBind is null )
38- {
39- _testLoggerForNotificationPocoErrorOnBind = new TestLogger ( ) ;
40- }
38+ //// // Use same logger, when the test is executed multiple times in the same AndroidRunner/AppDomain/AssemblyLoadContext
39+ //// if (_testLoggerForNotificationPocoErrorOnBind is null)
40+ //// {
41+ //// _testLoggerForNotificationPocoErrorOnBind = new TestLogger();
42+ //// }
4143
42- // Run test twice and verify that POCO message is logged only once.
43- for ( var i = 0 ; i < 2 ; i ++ )
44- {
45- using ( var testLoggerRegistration = new TestLoggerRegistration ( _testLoggerForNotificationPocoErrorOnBind ) )
46- {
47- var instance = new POCOObservableForProperty ( ) ;
44+ //// // Run test twice and verify that POCO message is logged only once.
45+ //// for (var i = 0; i < 2; i++)
46+ //// {
47+ //// using (var testLoggerRegistration = new TestLoggerRegistration(_testLoggerForNotificationPocoErrorOnBind))
48+ //// {
49+ //// var instance = new POCOObservableForProperty();
4850
49- var testLogger = testLoggerRegistration . Logger ;
51+ //// var testLogger = testLoggerRegistration.Logger;
5052
51- var testClass = new PocoType ( ) ;
53+ //// var testClass = new PocoType();
5254
53- Expression < Func < PocoType , string > > expr = x => x . Property1 ! ;
54- var exp = Reflection . Rewrite ( expr . Body ) ;
55+ //// Expression<Func<PocoType, string>> expr = x => x.Property1!;
56+ //// var exp = Reflection.Rewrite(expr.Body);
5557
56- var propertyName = exp . GetMemberInfo ( ) ? . Name ;
58+ //// var propertyName = exp.GetMemberInfo()?.Name;
5759
58- if ( propertyName is null )
59- {
60- throw new InvalidOperationException ( "propertyName should not be null" ) ;
61- }
60+ //// if (propertyName is null)
61+ //// {
62+ //// throw new InvalidOperationException("propertyName should not be null");
63+ //// }
6264
63- instance . GetNotificationForProperty ( testClass , exp , propertyName , false ) . Subscribe ( _ => { } ) ;
65+ //// instance.GetNotificationForProperty(testClass, exp, propertyName, false).Subscribe(_ => { });
6466
65- Assert . True ( testLogger . LastMessages . Count > 0 ) ;
67+ //// Assert.True(testLogger.LastMessages.Count > 0);
6668
67- var expectedMessage = $ "{ nameof ( POCOObservableForProperty ) } : The class { typeof ( PocoType ) . FullName } property { nameof ( PocoType . Property1 ) } is a POCO type and won't send change notifications, WhenAny will only return a single value!";
68- Assert . Equal ( expectedMessage , testLogger . LastMessages [ 0 ] ) ;
69+ //// var expectedMessage = $"{nameof(POCOObservableForProperty)}: The class {typeof(PocoType).FullName} property {nameof(PocoType.Property1)} is a POCO type and won't send change notifications, WhenAny will only return a single value!";
70+ //// Assert.Equal(expectedMessage, testLogger.LastMessages[0]);
6971
70- // Verify that the message is logged only once
71- foreach ( var logMessage in testLogger . LastMessages . Skip ( 1 ) )
72- {
73- Assert . NotEqual ( expectedMessage , logMessage ) ;
74- }
75- }
76- }
77- }
72+ //// // Verify that the message is logged only once
73+ //// foreach (var logMessage in testLogger.LastMessages.Skip(1))
74+ //// {
75+ //// Assert.NotEqual(expectedMessage, logMessage);
76+ //// }
77+ //// }
78+ //// }
79+ //// }
7880
79- [ Fact ( Skip = "Test Scheduler is null on occasions" ) ]
80- public void NotificationPocoSuppressErrorOnBind ( )
81- {
82- RxApp . EnsureInitialized ( ) ;
83- using ( var testLoggerRegistration = new TestLoggerRegistration ( ) )
84- {
85- var instance = new POCOObservableForProperty ( ) ;
81+ //// [Fact(Skip = "Test Scheduler is null on occasions")]
82+ //// public void NotificationPocoSuppressErrorOnBind()
83+ //// {
84+ //// RxApp.EnsureInitialized();
85+ //// using (var testLoggerRegistration = new TestLoggerRegistration())
86+ //// {
87+ //// var instance = new POCOObservableForProperty();
8688
87- var testLogger = testLoggerRegistration . Logger ;
89+ //// var testLogger = testLoggerRegistration.Logger;
8890
89- var testClass = new PocoType ( ) ;
91+ //// var testClass = new PocoType();
9092
91- Expression < Func < PocoType , string > > expr = x => x . Property1 ! ;
92- var exp = Reflection . Rewrite ( expr . Body ) ;
93+ //// Expression<Func<PocoType, string>> expr = x => x.Property1!;
94+ //// var exp = Reflection.Rewrite(expr.Body);
9395
94- var propertyName = exp . GetMemberInfo ( ) ? . Name ;
96+ //// var propertyName = exp.GetMemberInfo()?.Name;
9597
96- if ( propertyName is null )
97- {
98- throw new InvalidOperationException ( "propertyName should not be null" ) ;
99- }
98+ //// if (propertyName is null)
99+ //// {
100+ //// throw new InvalidOperationException("propertyName should not be null");
101+ //// }
100102
101- instance . GetNotificationForProperty ( testClass , exp , propertyName , false , true ) . Subscribe ( _ => { } ) ;
103+ //// instance.GetNotificationForProperty(testClass, exp, propertyName, false, true).Subscribe(_ => { });
102104
103- testLogger . LastMessages . Should ( ) . NotContain ( m => m . Contains ( nameof ( POCOObservableForProperty ) ) ) ;
104- }
105- }
105+ //// testLogger.LastMessages.Should().NotContain(m => m.Contains(nameof(POCOObservableForProperty)));
106+ //// }
107+ //// }
106108
107109 private class PocoType
108110 {
@@ -111,62 +113,60 @@ private class PocoType
111113 public string ? Property2 { get ; set ; }
112114 }
113115
114- #pragma warning disable CA1812 // Class is not instantiated
115-
116116 private class INPCClass : INotifyPropertyChanged
117117 {
118118 public event PropertyChangedEventHandler ? PropertyChanged ;
119119
120120 public void NotifyPropertyChanged ( ) => PropertyChanged ? . Invoke ( this , new PropertyChangedEventArgs ( string . Empty ) ) ;
121121 }
122122
123- #pragma warning restore CA1812 // Class is not instantiated
123+ ////private class TestLogger : ILogger
124+ ////{
125+ //// public List<string> LastMessages { get; } = new();
124126
125- private class TestLogger : ILogger
126- {
127- public List < string > LastMessages { get ; } = new ( ) ;
127+ //// public LogLevel Level => LogLevel.Debug;
128128
129- public LogLevel Level => LogLevel . Debug ;
129+ //// public void Write(Exception exception, string message, Type type, LogLevel logLevel) => LastMessages.Add(message) ;
130130
131- public void Write ( Exception exception , string message , Type type , LogLevel logLevel ) => LastMessages . Add ( message ) ;
131+ //// public void Write(string message, LogLevel logLevel) => LastMessages.Add(message);
132132
133- public void Write ( string message , LogLevel logLevel ) => LastMessages . Add ( message ) ;
133+ //// public void Write(Exception exception, string message, LogLevel logLevel) => LastMessages.Add(message);
134134
135- public void Write ( Exception exception , string message , LogLevel logLevel ) => LastMessages . Add ( message ) ;
135+ //// public void Write([Localizable(false)] string message, [Localizable(false)] Type type, LogLevel logLevel) => LastMessages.Add(message);
136+ ////}
136137
137- public void Write ( [ Localizable ( false ) ] string message , [ Localizable ( false ) ] Type type , LogLevel logLevel ) => LastMessages . Add ( message ) ;
138- }
138+ ////private sealed class TestLoggerRegistration : IDisposable
139+ ////{
140+ //// private readonly List<ILogger> _originalLoggers;
139141
140- private sealed class TestLoggerRegistration : IDisposable
141- {
142- private readonly List < ILogger > _originalLoggers ;
143-
144- public TestLoggerRegistration ( )
145- : this ( null )
146- {
147- }
148-
149- public TestLoggerRegistration ( TestLogger ? testLogger )
150- {
151- _originalLoggers = Locator . Current . GetServices < ILogger > ( ) . ToList ( ) ;
152-
153- Logger = testLogger ?? new TestLogger ( ) ;
154- Locator . CurrentMutable . RegisterConstant < ILogger > ( Logger ) ;
155- }
156-
157- public TestLogger Logger { get ; }
158-
159- public void Dispose ( )
160- {
161- // It's not possible to unregister specific logger,
162- // so all are unregistered and originals are re-registered.
163- Locator . CurrentMutable . UnregisterAll < ILogger > ( ) ;
164-
165- foreach ( var logger in _originalLoggers )
166- {
167- Locator . CurrentMutable . RegisterConstant < ILogger > ( logger ) ;
168- }
169- }
170- }
142+ //// public TestLoggerRegistration()
143+ //// : this(null)
144+ //// {
145+ //// }
146+
147+ //// public TestLoggerRegistration(TestLogger? testLogger)
148+ //// {
149+ //// _originalLoggers = Locator.Current.GetServices<ILogger>().ToList();
150+
151+ //// Logger = testLogger ?? new TestLogger();
152+ //// Locator.CurrentMutable.RegisterConstant<ILogger>(Logger);
153+ //// }
154+
155+ //// public TestLogger Logger { get; }
156+
157+ //// public void Dispose()
158+ //// {
159+ //// // It's not possible to unregister specific logger,
160+ //// // so all are unregistered and originals are re-registered.
161+ //// Locator.CurrentMutable.UnregisterAll<ILogger>();
162+
163+ //// foreach (var logger in _originalLoggers)
164+ //// {
165+ //// Locator.CurrentMutable.RegisterConstant<ILogger>(logger);
166+ //// }
167+ //// }
168+ ////}
169+
170+ #pragma warning restore CA1812 // Class is not instantiated
171171 }
172172}
0 commit comments