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() { var instance = new POCOObservableForProperty(); var testLogger = new TestLogger(); Locator.CurrentMutable.RegisterConstant <ILogger>(testLogger); 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))); }
public void NotificationPocoErrorOnBind() { var instance = new POCOObservableForProperty(); var testLogger = new TestLogger(); Locator.CurrentMutable.RegisterConstant <ILogger>(testLogger); 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).Subscribe(_ => { }); Assert.True(testLogger.LastMessages.Count > 0); Assert.Equal(testLogger.LastMessages[0], $"{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!"); }
public PocoType(Type type, PocoType?root) { Type = type; if (root != null) { Debug.Assert(root.RootCollector != null, "The root centralizes the collector."); Root = root; root.RootCollector.Add(type); } else { Root = this; RootCollector = new List <Type>() { type }; } }
public CreatePocoClass(PocoType pocoType = PocoType.SoftWired, string outputDirectory = null, string outputNameSpace = null, bool readOnlyProps = true, bool nullableProps = true) { this.pocoType = pocoType; this.outputDirectory = outputDirectory; this.outputNameSpace = outputNameSpace; this.readOnlyProps = readOnlyProps; this.nullableProps = nullableProps; if (String.IsNullOrWhiteSpace(this.outputDirectory)) { this.outputDirectory = @".\"; // current directory } if (String.IsNullOrWhiteSpace(this.outputNameSpace)) { this.outputNameSpace = namespaceDefault; } }