Exemple #1
0
        ProfileMetric Profile2()
        {
            DateTime startTime = DateTime.UtcNow;

            var path = nameof(ViewModelTestClass.NestedClass1)
                       + "." + "Bool2";

            for (int i = 0; i < iterations; i++)
            {
                var applicator = new BindingApplicator();

                var bindingExpression = new BindingExpression
                {
                    Path   = path,
                    Target = nameof(ViewTestClass.Bool1)
                };

                var target = new ViewTestClass();
                var source = new ViewModelTestClass();

                applicator.ApplyBinding(bindingExpression, target, source);
            }

            DateTime endTime  = DateTime.UtcNow;
            var      duration = endTime - startTime;

            var metric = new ProfileMetric();

            metric.Name     = "Nested";
            metric.TimeSpan = new TimeSpan(duration.Ticks / iterations);

            return(metric);
        }
Exemple #2
0
        ProfileMetric Profile1()
        {
            DateTime startTime = DateTime.UtcNow;

            for (int i = 0; i < iterations; i++)
            {
                var applicator = new BindingApplicator();

                var bindingExpression = new BindingExpression
                {
                    //Converter = "BooleanToVisibilityConverter",
                    //ConverterParameter = "Visible,Hidden,Hidden",
                    Path   = nameof(ViewModelTestClass.Bool1),
                    Target = nameof(ViewTestClass.Bool1)
                };

                var target = new ViewTestClass();
                var source = new ViewModelTestClass();

                applicator.ApplyBinding(bindingExpression, target, source);
            }

            DateTime endTime  = DateTime.UtcNow;
            var      duration = endTime - startTime;

            var metric = new ProfileMetric();

            metric.Name     = "Simple";
            metric.TimeSpan = new TimeSpan(duration.Ticks / iterations);

            return(metric);
        }
Exemple #3
0
        ProfileMetric Profile3()
        {
            var converter = new DummyBooleanToVisibilityConverter();

            DateTime startTime = DateTime.UtcNow;

            for (int i = 0; i < iterations; i++)
            {
                var applicator = new BindingApplicator();

                var bindingExpression = new BindingExpression
                {
                    Path   = nameof(ViewModelTestClass.Bool1),
                    Target = nameof(ViewTestClass.Visibility),
                    //Converter = "Codon.UI.Data.DummyBooleanToVisibilityConverter, Codon.ApiProfiling"
                };

                var target = new ViewTestClass();
                var source = new ViewModelTestClass();

                applicator.ApplyBinding(bindingExpression, target, source, converter);
            }

            DateTime endTime  = DateTime.UtcNow;
            var      duration = endTime - startTime;

            var metric = new ProfileMetric();

            metric.Name     = "Converter";
            metric.TimeSpan = new TimeSpan(duration.Ticks / iterations);

            return(metric);
        }
Exemple #4
0
        public void ShouldUnbind()
        {
            var applicator = new BindingApplicator();

            var bindingExpression = new BindingExpression
            {
                Path   = nameof(ViewModelTestClass.Bool1),
                Target = nameof(ViewTestClass.Bool1)
            };

            var target = new ViewTestClass();
            var source = new ViewModelTestClass();

            var unbindAction = applicator.ApplyBinding(bindingExpression, target, source);

            source.Bool1 = true;
            Assert.IsTrue(target.Bool1, "Changing binding value to true should update Bool1.");
            source.Bool1 = false;
            Assert.IsFalse(target.Bool1, "Changing binding value to false should update Bool1.");

            Assert.IsNotNull(unbindAction);
            unbindAction();
            Assert.IsFalse(target.Bool1, "Unbinding should not change value.");
            source.Bool1 = true;
            Assert.IsFalse(target.Bool1, "Changing source value after unbind should have no effect.");
        }
Exemple #5
0
        public void BindingShouldAllowUpdate()
        {
            var applicator = new BindingApplicator();

            var bindingExpression = new BindingExpression
            {
                //ConverterParameter = "Visible,Hidden,Hidden",
                Path   = nameof(ViewModelTestClass.Bool1),
                Target = nameof(ViewTestClass.Bool1)
            };

            var target = new ViewTestClass();
            var source = new ViewModelTestClass();

            applicator.ApplyBinding(bindingExpression, target, source);

            source.Bool1 = true;
            Assert.IsTrue(target.Bool1, "Changing binding value to true should update Bool1.");
            source.Bool1 = false;
            Assert.IsFalse(target.Bool1, "Changing binding value to false should update Bool1.");
        }
Exemple #6
0
        public void ValueConverterShouldApplyValue()
        {
            var applicator = new BindingApplicator();

            var bindingExpression = new BindingExpression
            {
                Path   = nameof(ViewModelTestClass.Bool1),
                Target = nameof(ViewTestClass.Visibility)
            };

            var target = new ViewTestClass();
            var source = new ViewModelTestClass();

            var converter = new DummyBooleanToVisibilityConverter();

            applicator.ApplyBinding(bindingExpression, target, source, converter);

            source.Bool1 = true;
            Assert.AreEqual(DummyVisibility.Visible, target.Visibility, "Changing binding value to true should update Visibility.");
            source.Bool1 = false;
            Assert.AreEqual(DummyVisibility.Invisible, target.Visibility, "Changing binding value to false should update Visibility.");
        }