public void NotificationPocoSuppressErrorOnBind() { RxApp.EnsureInitialized(); using (var testLoggerRegistration = new TestLoggerRegistration()) { var instance = new POCOObservableForProperty(); var testLogger = testLoggerRegistration.Logger; var testClass = new PocoType(); Expression <Func <PocoType, string> > expr = x => x.Property1 !; var exp = Reflection.Rewrite(expr.Body); var propertyName = exp.GetMemberInfo()?.Name; if (propertyName is null) { throw new InvalidOperationException("propertyName should not be null"); } instance.GetNotificationForProperty(testClass, exp, propertyName, false, true).Subscribe(_ => { }); testLogger.LastMessages.Should().NotContain(m => m.Contains(nameof(POCOObservableForProperty))); } }
public void NotificationPocoErrorOnBind() { RxApp.EnsureInitialized(); // Use same logger, when the test is executed multiple times in the same AndroidRunner/AppDomain/AssemblyLoadContext if (_testLoggerForNotificationPocoErrorOnBind is null) { _testLoggerForNotificationPocoErrorOnBind = new TestLogger(); } // Run test twice and verify that POCO message is logged only once. for (var i = 0; i < 2; i++) { using (var testLoggerRegistration = new TestLoggerRegistration(_testLoggerForNotificationPocoErrorOnBind)) { var instance = new POCOObservableForProperty(); var testLogger = testLoggerRegistration.Logger; var testClass = new PocoType(); Expression <Func <PocoType, string> > expr = x => x.Property1 !; var exp = Reflection.Rewrite(expr.Body); var propertyName = exp.GetMemberInfo()?.Name; if (propertyName is null) { throw new InvalidOperationException("propertyName should not be null"); } instance.GetNotificationForProperty(testClass, exp, propertyName, false).Subscribe(_ => { }); Assert.True(testLogger.LastMessages.Count > 0); 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!"; Assert.Equal(expectedMessage, testLogger.LastMessages[0]); // Verify that the message is logged only once foreach (var logMessage in testLogger.LastMessages.Skip(1)) { Assert.NotEqual(expectedMessage, logMessage); } } } }
public void NotificationPocoSuppressErrorOnBind() { using (var testLoggerRegistration = new TestLoggerRegistration()) { var instance = new POCOObservableForProperty(); var testLogger = testLoggerRegistration.Logger; var testClass = new PocoType(); Expression <Func <PocoType, string> > expr = x => x.Property1; var exp = Reflection.Rewrite(expr.Body); instance.GetNotificationForProperty(testClass, exp, exp.GetMemberInfo().Name, false, true).Subscribe(_ => { }); testLogger.LastMessages.ShouldNotContain(m => m.Contains(nameof(POCOObservableForProperty))); } }