public void DynamicTypeBuilderTransactionalProxyHasMultipleValues() { var target1 = new TransactionProxyClass { DecimalProperty = 123, IntProperty = 456, StringProperty = "Test", Targets = new Collection <TestTarget> { new TestTarget() } }; var target2 = new TransactionProxyClass { DecimalProperty = 123, IntProperty = 457, StringProperty = "Test", Targets = new Collection <TestTarget> { new TestTarget() } }; var target3 = new TransactionProxyClass { DecimalProperty = 123, IntProperty = 458, StringProperty = "Test3", Targets = new Collection <TestTarget> { new TestTarget() } }; var dtb = new DynamicTypeBuilder <TransactionProxyClass>(); dtb.AddConvention(new TransactionProxyConvention(typeof(TransactionProxyClass), true)); if (!dtb.Conventions.OfType <NotifyPropertyChangedConvention>().Any()) { dtb.AddConvention(new NotifyPropertyChangedConvention()); } var proxy = Activator.CreateInstance(dtb.GeneratedType) as TransactionProxyClass; ((ITransactionProxy <TransactionProxyClass>)proxy).SetTargets(new[] { target1, target2, target3 }); var type = proxy.GetType(); Assert.False((bool)type.GetProperty("DecimalProperty_HasMultipleValues").GetValue(proxy)); Assert.True((bool)type.GetProperty("IntProperty_HasMultipleValues").GetValue(proxy)); Assert.True((bool)type.GetProperty("StringProperty_HasMultipleValues").GetValue(proxy)); Assert.True((bool)type.GetProperty("Targets_HasMultipleValues").GetValue(proxy)); }
public void DynamicTypeBuilderTransactionalProxySingleCommit() { var target1 = new TransactionProxyClass { DecimalProperty = 123, IntProperty = 456, StringProperty = "Test", Targets = new Collection <TestTarget> { new TestTarget() } }; var dtb = new DynamicTypeBuilder <TransactionProxyClass>(); dtb.AddConvention(new TransactionProxyConvention(typeof(TransactionProxyClass), true)); if (!dtb.Conventions.OfType <NotifyPropertyChangedConvention>().Any()) { dtb.AddConvention(new NotifyPropertyChangedConvention()); } var proxy = Activator.CreateInstance(dtb.GeneratedType) as TransactionProxyClass; ((ITransactionProxy <TransactionProxyClass>)proxy).SetTargets(new[] { target1 }); Assert.Equal(123, proxy.DecimalProperty); Assert.Equal(456, proxy.IntProperty); Assert.Equal("Test", proxy.StringProperty); Assert.Single(proxy.Targets); Assert.Equal(target1.Targets.First(), proxy.Targets.First()); proxy.DecimalProperty = 1234; proxy.IntProperty = 5678; proxy.StringProperty = "Test2"; proxy.Targets.Add(new TestTarget()); Assert.Equal(123, target1.DecimalProperty); Assert.Equal(456, target1.IntProperty); Assert.Equal("Test", target1.StringProperty); Assert.Single(target1.Targets); ((ICommitable)proxy).Commit(); Assert.Equal(1234, target1.DecimalProperty); Assert.Equal(5678, target1.IntProperty); Assert.Equal("Test2", target1.StringProperty); Assert.Equal(2, target1.Targets.Count()); }
public void TransactionProxyCreatorCreateSingleProxy() { var target1 = new TransactionProxyClass { DecimalProperty = 123, StringProperty = "Test" }; var proxy = TransactionProxyCreator.Current.CreateProxy <TransactionProxyClass>(target1); var proxy2 = TransactionProxyCreator.Current.CreateProxy <TransactionProxyClass>(target1); var proxy3 = TransactionProxyCreator.Current.CreateProxy <TransactionProxyClass>(target1); var proxy4 = TransactionProxyCreator.Current.CreateProxy <TestTarget>(new TestTarget()); Assert.Equal(proxy.GetType(), proxy2.GetType()); Assert.Equal(proxy2.GetType(), proxy3.GetType()); Assert.NotEqual(proxy4.GetType(), proxy.GetType()); Assert.Equal(123, proxy.DecimalProperty); Assert.Equal("Test", proxy.StringProperty); }
public void DynamicTypeBuilderTransactionalProxySetTypedTarget() { var target1 = new TransactionProxyClass(); var target2 = new TransactionProxyClass(); var dtb = new DynamicTypeBuilder <TransactionProxyClass>(); dtb.AddConvention(new TransactionProxyConvention(typeof(TransactionProxyClass), true)); if (!dtb.Conventions.OfType <NotifyPropertyChangedConvention>().Any()) { dtb.AddConvention(new NotifyPropertyChangedConvention()); } var proxy = Activator.CreateInstance(dtb.GeneratedType) as ITransactionProxy <TransactionProxyClass>; proxy.SetTargets(new[] { target1 }); Assert.Single(proxy.Targets); Assert.Equal(target1, proxy.Targets.First()); proxy.SetTargets(new[] { target2 }); Assert.Single(proxy.Targets); Assert.Equal(target2, proxy.Targets.First()); }