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 ShouldOverrideMultipleRules() { _binder.Bind(x => x.Int.ToString()).To(x => x.String); _binder.Bind(x => x.Flag.ToString()).To(x => x.String2); _binder.Bind(x => x.Int.ToString() + "2").To(x => x.String); _binder.Bind(x => x.Flag.ToString() + "2").To(x => x.String2); _stub = new UniversalStub(); using (_binder.Attach(_stub)) { _stub.String.ShouldBe("02"); _stub.String2.ShouldBe("False2"); using (_stub.VerifyChangedOnce("String")) { _stub.Int = 1; } _stub.String.ShouldBe("12"); using (_stub.VerifyChangedOnce("String2")) { _stub.Flag = true; } _stub.String2.ShouldBe("True2"); } }
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 ModifiedClonedBindersShouldNotAffectOriginalOnes() { _binder.Bind(x => x.Int.ToString()).To(x => x.String); var binder2 = _binder.Clone <UniversalStub>(); binder2.Bind(x => x.Flag.ToString()).To(x => x.String2); using (_binder.Attach(_stub)) { _stub.String.ShouldBe("0"); using (_stub.VerifyChangedOnce("String")) { _stub.Int = 1; } _stub.String.ShouldBe("1"); _stub.String2.ShouldBe(null); using (_stub.VerifyNotChanged("String2")) { _stub.Flag = true; } _stub.String2.ShouldBe(null); } _stub = new UniversalStub(); using (binder2.Attach(_stub)) { _stub.String.ShouldBe("0"); using (_stub.VerifyChangedOnce("String")) { _stub.Int = 1; } _stub.String.ShouldBe("1"); _stub.String2.ShouldBe("False"); using (_stub.VerifyChangedOnce("String2")) { _stub.Flag = true; } _stub.String2.ShouldBe("True"); } }
public void ShouldNotOverrideBindingRulesIfKeysAreDifferent() { _binder.Bind(x => x.Int.ToString()).OverrideKey("test1").To(x => x.String); _binder.Bind(x => x.String2).DoNotOverride().OverrideKey("test2").To(x => x.String); _stub = new UniversalStub(); using (_binder.Attach(_stub)) { _stub.String.ShouldBe(null); using (_stub.VerifyChangedOnce("String")) { _stub.Int = 1; } _stub.String.ShouldBe("1"); using (_stub.VerifyChangedOnce("String")) { _stub.String2 = "a"; } _stub.String.ShouldBe("a"); } }
public void ShouldNotOverrideBindingRulesIfDoNotOverrideSpecified() { _binder.Bind(x => x.Int.ToString()).To(x => x.String); _binder.Bind(x => x.String2).DoNotOverride().To(x => x.String); _stub = new UniversalStub(); using (_binder.Attach(_stub)) { _stub.String.ShouldBe(null); using (_stub.VerifyChangedOnce("String")) { _stub.Int = 1; } _stub.String.ShouldBe("1"); using (_stub.VerifyChangedOnce("String")) { _stub.String2 = "a"; } _stub.String.ShouldBe("a"); } }
public void ModifiedClonedBindersShouldNotAffectOriginalOnes() { _binder.Bind(x => x.Int.ToString()).To(x => x.String); var binder2 = _binder.Clone<UniversalStub>(); binder2.Bind(x => x.Flag.ToString()).To(x => x.String2); using (_binder.Attach(_stub)) { _stub.String.ShouldBe("0"); using (_stub.VerifyChangedOnce("String")) { _stub.Int = 1; } _stub.String.ShouldBe("1"); _stub.String2.ShouldBe(null); using (_stub.VerifyNotChanged("String2")) { _stub.Flag = true; } _stub.String2.ShouldBe(null); } _stub = new UniversalStub(); using (binder2.Attach(_stub)) { _stub.String.ShouldBe("0"); using (_stub.VerifyChangedOnce("String")) { _stub.Int = 1; } _stub.String.ShouldBe("1"); _stub.String2.ShouldBe("False"); using (_stub.VerifyChangedOnce("String2")) { _stub.Flag = true; } _stub.String2.ShouldBe("True"); } }
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 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 ShouldOverrideBindingRules() { _binder.Bind(x => x.Int.ToString()).To(x => x.String); _binder.Bind(x => x.String2).To(x => x.String); _stub = new UniversalStub(); using (_binder.Attach(_stub)) { _stub.String.ShouldBe(null); using (_stub.VerifyNotChanged("String")) { _stub.Int = 1; } _stub.String2.ShouldBe(null); using (_stub.VerifyChangedOnce("String")) { _stub.String2 = "a"; } _stub.String2.ShouldBe("a"); } }
public void ShouldOverrideConditionalBindingRulesByCustomKey() { _binder.BindIf(x => true, x => x.Int.ToString()).OverrideKey("mykey").To((x, v) => x.String = v); _binder.BindIf(x => true, x => x.String2).OverrideKey("mykey").To((x, v) => x.String = v); _stub = new UniversalStub(); using (_binder.Attach(_stub)) { _stub.String.ShouldBe(null); using (_stub.VerifyNotChanged("String")) { _stub.Int = 1; } _stub.String2.ShouldBe(null); using (_stub.VerifyChangedOnce("String")) { _stub.String2 = "a"; } _stub.String2.ShouldBe("a"); } }