Exemple #1
0
        public void ShouldNotOverrideConditionalBindingsByAnotherConditionalIfDoNotOverrideSpecified()
        {
            _binder.BindIf(x => x.Flag, x => x.Int.ToString())
            .Else(x => x.Int.ToString() + "1")
            .To(x => x.String);

            var binder = _binder.Clone <UniversalStubEx>();

            binder.BindIf(x => true, x => x.String2).DoNotOverride().To(x => x.String);
            var stub = new UniversalStubEx();

            using (binder.Attach(stub))
            {
                stub.String = null;

                using (stub.VerifyChangedOnce("String"))
                {
                    stub.Int = 1;
                }
                stub.String = "11";

                using (stub.VerifyChangedOnce("String"))
                {
                    stub.String2 = "a";
                }
                stub.String = "a";
            }
        }
        public void ClonedBindersShouldCorrectlyMixDerivedActionsWithBaseOnes()
        {
            _binder.Bind(x => x.Int.ToString()).To(x => x.String);

            var binder2 = _binder.Clone <UniversalStubEx>();

            binder2.Bind(x => x.Int.ToString()).To(x => x.String3);

            var stub = new UniversalStubEx();

            using (binder2.Attach(stub))
            {
                stub.String.ShouldBe("0");
                stub.String3.ShouldBe("0");

                using (stub.VerifyChangedOnce("String"))
                    using (stub.VerifyChangedOnce("String3"))
                    {
                        stub.Int = 1;
                    }

                stub.String.ShouldBe("1");
                stub.String3.ShouldBe("1");
            }
        }
Exemple #3
0
        public void ShouldOverrideConditionalBindings()
        {
            _binder.BindIf(x => x.Flag, x => x.Int.ToString())
            .Else(x => x.Int.ToString() + "1")
            .To(x => x.String);

            var binder = _binder.Clone <UniversalStubEx>();

            binder.Bind(x => x.String2).To(x => x.String);
            var stub = new UniversalStubEx();

            using (binder.Attach(stub))
            {
                stub.String = null;

                using (stub.VerifyNotChanged("String"))
                {
                    stub.Flag = !stub.Flag;
                }

                using (stub.VerifyNotChanged("String"))
                {
                    stub.Int = 1;
                }

                using (stub.VerifyChangedOnce("String"))
                {
                    stub.String2 = "a";
                }
                stub.String = "a";
            }
        }
        public void ShouldNotDuplicateBindingsInClonedBinder()
        {
            int callCount = 0;

            _binder.Bind(x => x.Int.ToString()).To((x, v) =>
            {
                ++callCount;
                x.String = v;
            });

            var binderEx = _binder.Clone <UniversalStubEx>();
            var stub     = new UniversalStubEx();

            using (binderEx.Attach(stub))
            {
                stub.String.ShouldBe("0");
                callCount.ShouldBe(1);

                using (stub.VerifyChangedOnce("String"))
                {
                    stub.Int = 1;
                }
                stub.String.ShouldBe("1");
                callCount.ShouldBe(2);
            }
        }
        public void ClonedBindersShouldCorrectlyMixDerivedActionsWithBaseOnes()
        {
            _binder.Bind(x => x.Int.ToString()).To(x => x.String);

            var binder2 = _binder.Clone<UniversalStubEx>();
            binder2.Bind(x => x.Int.ToString()).To(x => x.String3);

            var stub = new UniversalStubEx();

            using (binder2.Attach(stub))
            {
                stub.String.ShouldBe("0");
                stub.String3.ShouldBe("0");

                using (stub.VerifyChangedOnce("String"))
                using (stub.VerifyChangedOnce("String3"))
                {
                    stub.Int = 1;
                }

                stub.String.ShouldBe("1");
                stub.String3.ShouldBe("1");
            }
        }
Exemple #6
0
        public void ShouldRespectWithDependencyForPropertyBinding()
        {
            _binder.BindIf(x => x.Flag, x => x.Int.ToString())
            .Else(x => x.Int.ToString() + "1")
            .WithDependency(x => x.String)
            .To(x => x.String2);

            var stub = new UniversalStubEx();

            using (_binder.Attach(stub))
            {
                using (stub.VerifyChangedOnce("String2"))
                {
                    stub.Int = 1;
                }
            }
        }
        public void ShouldBindNestedMembersOfDerivedType()
        {
            var binderEx = _binder.Clone <UniversalStubEx>();

            binderEx.Bind(x => x.NestedEx.Int).To(x => x.Int);

            var stub = new UniversalStubEx {
                NestedEx = new UniversalStubEx {
                    Int = 1
                }
            };

            using (binderEx.Attach(stub))
            {
                stub.Int.ShouldBe(1);

                using (stub.VerifyChangedOnce("Int"))
                {
                    stub.NestedEx.Int = 2;
                }
                stub.Int.ShouldBe(2);
            }
        }
        public void ShouldNotOverrideConditionalBindingsByAnotherConditionalIfDoNotOverrideSpecified()
        {
            _binder.BindIf(x => x.Flag, x => x.Int.ToString())
                .Else(x => x.Int.ToString() + "1")
                .To(x => x.String);

            var binder = _binder.Clone<UniversalStubEx>();
            binder.BindIf(x => true, x => x.String2).DoNotOverride().To(x => x.String);
            var stub = new UniversalStubEx();

            using (binder.Attach(stub))
            {
                stub.String = null;

                using (stub.VerifyChangedOnce("String"))
                {
                    stub.Int = 1;
                }
                stub.String = "11";

                using (stub.VerifyChangedOnce("String"))
                {
                    stub.String2 = "a";
                }
                stub.String = "a";
            }
        }
        public void ShouldOverrideConditionalBindings()
        {
            _binder.BindIf(x => x.Flag, x => x.Int.ToString())
                .Else(x => x.Int.ToString() + "1")
                .To(x => x.String);

            var binder = _binder.Clone<UniversalStubEx>();
            binder.Bind(x => x.String2).To(x => x.String);
            var stub = new UniversalStubEx();

            using (binder.Attach(stub))
            {
                stub.String = null;

                using (stub.VerifyNotChanged("String"))
                {
                    stub.Flag = !stub.Flag;
                }

                using (stub.VerifyNotChanged("String"))
                {
                    stub.Int = 1;
                }

                using (stub.VerifyChangedOnce("String"))
                {
                    stub.String2 = "a";
                }
                stub.String = "a";
            }
        }
        public void ShouldNotDuplicateBindingsInClonedBinder()
        {
            int callCount = 0;
            _binder.Bind(x => x.Int.ToString()).To((x, v) =>
            {
                ++callCount;
                x.String = v;
            });

            var binderEx = _binder.Clone<UniversalStubEx>();
            var stub = new UniversalStubEx();

            using (binderEx.Attach(stub))
            {
                stub.String.ShouldBe("0");
                callCount.ShouldBe(1);

                using (stub.VerifyChangedOnce("String"))
                {
                    stub.Int = 1;
                }
                stub.String.ShouldBe("1");
                callCount.ShouldBe(2);
            }
        }
        public void ShouldBindNestedMembersOfDerivedType()
        {
            var binderEx = _binder.Clone<UniversalStubEx>();
            binderEx.Bind(x => x.NestedEx.Int).To(x => x.Int);

            var stub = new UniversalStubEx { NestedEx = new UniversalStubEx { Int = 1 } };

            using (binderEx.Attach(stub))
            {
                stub.Int.ShouldBe(1);

                using (stub.VerifyChangedOnce("Int"))
                {
                    stub.NestedEx.Int = 2;
                }
                stub.Int.ShouldBe(2);
            }
        }