public void ShouldNotBindOnCollectionItemImmutablePropertyChange() { var binder = new Binder <Stub>(); binder.Bind(x => x.SubItems.All(y => string.IsNullOrEmpty(y.ImmutableSource))).To(x => x.Flag); var stub = new Stub(); using (binder.Attach(stub)) { stub.Flag.ShouldBe(true); stub.SubItems.Add(new Stub()); stub.Flag.ShouldBe(true); stub.SubItems.Add(new Stub { ImmutableSource = "z" }); stub.Flag.ShouldBe(false); stub.SubItems[1].ImmutableSource = null; stub.Flag.ShouldBe(false); stub.SubItems.Add(new Stub()); stub.Flag.ShouldBe(true); } }
public void ShouldBindNestedWhenStructInTheMiddle() { var binder = new Binder <ValueContainerClassNotify <ValueContainerStruct <UniversalStub> > >(); binder.Bind(x => x.Value.Value.String).To(x => x.Value.Value.String2); var stub = new ValueContainerClassNotify <ValueContainerStruct <UniversalStub> >(); stub.Value = new ValueContainerStruct <UniversalStub>(new UniversalStub()); using (binder.Attach(stub)) { stub.Value.Value.String2.ShouldBe(null); stub.Value.Value.String = "a"; stub.Value.Value.String2.ShouldBe("a"); stub.Value = new ValueContainerStruct <UniversalStub>(new UniversalStub { String = "b" }); stub.Value.Value.String2.ShouldBe("b"); stub.Value.Value.String = "c"; stub.Value.Value.String2.ShouldBe("c"); } }
public void ShouldBindNestedWhenNoPropertyChangedNotificationsInTheMiddle() { var binder = new Binder <ValueContainerClassNotify <ValueContainerClass <UniversalStub> > >(); binder.Bind(x => x.Value.Value.String).To(x => x.Value.Value.String2); var stub = new ValueContainerClassNotify <ValueContainerClass <UniversalStub> >(); stub.Value = new ValueContainerClass <UniversalStub>(); stub.Value.Value = new UniversalStub(); using (binder.Attach(stub)) { stub.Value.Value.String2.ShouldBe(null); stub.Value.Value.String = "a"; stub.Value.Value.String2.ShouldBe("a"); stub.Value = new ValueContainerClass <UniversalStub> { Value = new UniversalStub { String = "b" } }; stub.Value.Value.String2.ShouldBe("b"); stub.Value.Value.String = "c"; stub.Value.Value.String2.ShouldBe("c"); } }
public void ShouldBindBetweenIndexedObjects() { var binder = new Binder <ObservableDictionary <UniversalStub> >(); var dict = new ObservableDictionary <UniversalStub>(); binder.BindIf(x => x.ContainsKey("first") && x.ContainsKey("second"), x => x["first"].String).To(x => x["second"].String); using (binder.Attach(dict)) { var first = new UniversalStub(); var second = new UniversalStub { String = "a" }; dict.Add("second", second); second.String.ShouldBe("a"); using (second.VerifyChangedOnce("String")) { dict.Add("first", first); } second.String.ShouldBe(null); using (second.VerifyChangedOnce("String")) { first.String = "b"; } second.String.ShouldBe("b"); } }
public void ShouldBindBetweenIndexedObjects() { var binder = new Binder<ObservableDictionary<UniversalStub>>(); var dict= new ObservableDictionary<UniversalStub>(); binder.BindIf(x => x.ContainsKey("first") && x.ContainsKey("second"), x => x["first"].String).To(x => x["second"].String); using (binder.Attach(dict)) { var first = new UniversalStub(); var second = new UniversalStub { String = "a" }; dict.Add("second", second); second.String.ShouldBe("a"); using (second.VerifyChangedOnce("String")) { dict.Add("first", first); } second.String.ShouldBe(null); using (second.VerifyChangedOnce("String")) { first.String = "b"; } second.String.ShouldBe("b"); } }
public ExplosiveModel(int size) { Consumer = Anchor(new Consumer()); for (int i = 0; i < size; ++i) { Children.Add(Anchor(new ExplosiveModel(size - 1))); } Anchor(Binder.Attach(this)); }
private static void Main(string[] args) { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); AppV _appV = new AppV(); _binder = new Binder <AppVM>(_app); _binder.Attach(_appV); _binder.Run(); Application.Run(_appV); }
public void ShouldBindAction() { var binder = new Binder <UniversalStub>(); binder.BindAction(x => ActionBinding(x, x.NullableInt ?? -1)); using (binder.Attach(_stub)) { _stub.Int.ShouldBe(-1); _stub.NullableInt = 1; _stub.Int.ShouldBe(1); } }
public void ShouldCoerceClasses() { var stub = new UniversalStubEx(); var binder = new Binder <UniversalStubEx>(); binder.Bind(x => x.NestedEx).To(x => x.Nested); using (binder.Attach(stub)) { stub.Nested.ShouldBe(null); stub.NestedEx = new UniversalStubEx(); stub.Nested.ShouldBe(stub.NestedEx); } }
private static void DebugStackFrameTest() { var binder = new Binder <SourceModel>(); binder.Bind(x => x.Value1).DoNotRunOnAttach().To(x => { VirtualFrameCompiler.TakeSnapshot(); }); var model = new SourceModel(); using (binder.Attach(model)) { model.Value1 = 1; } }
public void ShouldBindIndexedField() { var binder = new Binder<UniversalStub>(); var stub = new UniversalStub(); stub.Dictionary = new ObservableDictionary<string>(); binder.Bind(x => x.Dictionary["test"]).To(x => x.String); using (binder.Attach(stub)) { stub.String.ShouldBe(null); using (stub.VerifyChangedOnce("String")) { stub.Dictionary.Add("test", "a"); } stub.String.ShouldBe("a"); } }
public void ShouldBindAggregatedCollectionOfValueTypes() { var binder = new Binder <AggregatedCollection <int> >(); binder.Bind(x => x.Sum()).To(x => x.Aggregate); var collection = new AggregatedCollection <int>(); using (binder.Attach(collection)) { collection.Aggregate.ShouldBe(0); using (collection.VerifyChangedOnce("Aggregate")) { collection.Add(1); } collection.Aggregate.ShouldBe(1); using (collection.VerifyChangedOnce("Aggregate")) { collection.Add(2); } collection.Aggregate.ShouldBe(3); using (collection.VerifyChangedOnce("Aggregate")) { collection[0] = 3; } collection.Aggregate.ShouldBe(5); using (collection.VerifyChangedOnce("Aggregate")) { collection.RemoveAt(1); } collection.Aggregate.ShouldBe(3); using (collection.VerifyChangedOnce("Aggregate")) { collection.Clear(); } collection.Aggregate.ShouldBe(0); } }
public void ShouldBindIndexedField() { var binder = new Binder <UniversalStub>(); var stub = new UniversalStub(); stub.Dictionary = new ObservableDictionary <string>(); binder.Bind(x => x.Dictionary["test"]).To(x => x.String); using (binder.Attach(stub)) { stub.String.ShouldBe(null); using (stub.VerifyChangedOnce("String")) { stub.Dictionary.Add("test", "a"); } stub.String.ShouldBe("a"); } }
public void ShouldBindAggregatedCollectionOfValueTypes() { var binder = new Binder<AggregatedCollection<int>>(); binder.Bind(x => x.Sum()).To(x => x.Aggregate); var collection = new AggregatedCollection<int>(); using (binder.Attach(collection)) { collection.Aggregate.ShouldBe(0); using (collection.VerifyChangedOnce("Aggregate")) { collection.Add(1); } collection.Aggregate.ShouldBe(1); using (collection.VerifyChangedOnce("Aggregate")) { collection.Add(2); } collection.Aggregate.ShouldBe(3); using (collection.VerifyChangedOnce("Aggregate")) { collection[0] = 3; } collection.Aggregate.ShouldBe(5); using (collection.VerifyChangedOnce("Aggregate")) { collection.RemoveAt(1); } collection.Aggregate.ShouldBe(3); using (collection.VerifyChangedOnce("Aggregate")) { collection.Clear(); } collection.Aggregate.ShouldBe(0); } }
public void ShouldNotBindOnImmutablePropertyChange() { var binder = new Binder <Stub>(); binder.Bind(x => x.Source + x.ImmutableSource).To(x => x.Target); var stub = new Stub(); using (binder.Attach(stub)) { stub.Target.ShouldBe(string.Empty); stub.Source = "1"; stub.Target.ShouldBe("1"); stub.ImmutableSource = "2"; stub.Target.ShouldBe("1"); stub.Source = "3"; stub.Target.ShouldBe("32"); } }
public void ShouldDowncastClasses() { var binder = new Binder <UniversalStub>(); binder.Bind(x => ((UniversalStubEx)x.Nested).String3).To(x => x.String); var stub = new UniversalStub(); var stubEx = new UniversalStubEx(); stub.Nested = stubEx; using (binder.Attach(stub)) { stub.String.ShouldBe(null); stubEx.String3 = "a"; stub.String.ShouldBe("a"); stub.Nested = new UniversalStubEx { String3 = "b" }; stub.String.ShouldBe("b"); } }
public UserModel() { Binder.Attach(this); }
public Consumer() { Anchor(Source); Anchor(Binder.Attach(this)); }
public Source() { Anchor(Binder.Attach(this)); }