コード例 #1
0
        public virtual void Parameters()
        {
            string xaml = @"
<Grid x:Name=""root"">
    <Grid.Resources>
        <Style x:Key=""st"" TargetType=""TextBox"">
            <Setter Property=""Text"" Value=""{b:DXBinding IntProp+$test:BindingTests_a.StaticIntProp,
                                        BackExpr='IntProp=int.Parse(@v)-$test:BindingTests_a.StaticIntProp'}""/>
        </Style>
    </Grid.Resources>
    <test:EventTests_visual x:Name=""bt1"" CustomEvent=""{b:DXEvent 'Do3(@args, @e(bt2), @sender)'}""/>
    <test:EventTests_visual x:Name=""bt2"" CustomEvent=""{b:DXEvent 'Do3(@args, @e(bt1), @sender)'}""/>
</Grid>";

            var  vm    = EventTests_a.Create();
            Grid panel = BindingTestHelper.LoadXaml <Grid>(xaml);
            var  bt1   = (EventTests_visual)panel.Children[0];
            var  bt2   = (EventTests_visual)panel.Children[1];

            panel.DataContext = vm;
            BindingTestHelper.DoEvents(panel);
            bt1.RaiseCustomEvent();
            Assert.AreEqual(bt2, vm.Do3Parameter);
            Assert.AreEqual(EventArgs.Empty, vm.Do3EventArgs);
            Assert.AreEqual(bt1, vm.Do3Sender);
            bt2.RaiseCustomEvent();
            Assert.AreEqual(bt1, vm.Do3Parameter);
            Assert.AreEqual(EventArgs.Empty, vm.Do3EventArgs);
            Assert.AreEqual(bt2, vm.Do3Sender);
        }
コード例 #2
0
        public virtual void EventInDataTemplate()
        {
            string xaml  = @"
<Grid>
    <Grid.Resources>
        <DataTemplate x:Key=""temp"">
            <test:EventTests_visual CustomEvent=""{b:DXEvent 'Do4($test:BindingTests_a.StaticIntProp)'}""/>
        </DataTemplate>
    </Grid.Resources>
    <ContentControl Content=""{b:DXBinding}"" ContentTemplate=""{StaticResource temp}""/>
    <ContentControl Content=""{b:DXBinding}"" ContentTemplate=""{StaticResource temp}""/>
</Grid>
";
            var    panel = BindingTestHelper.LoadXaml <Grid>(xaml);

            BindingTestHelper.VisualTest(panel, () => {
                BindingTests_a.Static(2);
                var vm            = EventTests_a.Create();
                var tb1           = LayoutTreeHelper.GetVisualChildren(panel.Children[0]).OfType <EventTests_visual>().First();
                var tb2           = LayoutTreeHelper.GetVisualChildren(panel.Children[1]).OfType <EventTests_visual>().First();
                panel.DataContext = vm;
                BindingTestHelper.DoEvents(panel);
                tb1.RaiseCustomEvent();
                tb2.RaiseCustomEvent();
                Assert.AreEqual(2, vm.Do4Counter);
            });
        }
コード例 #3
0
        public void OneExecute()
        {
            var vm = CommandTests_a.Create();
            var bt = BindingTestHelper.BindAssert <Button>("Button", "Command", "{b:DXCommand Do1()}", null, vm);

            BindingTestHelper.DoCommand(bt);
            Assert.AreEqual(1, vm.Do1Counter);
            BindingTestHelper.DoCommand(bt);
            Assert.AreEqual(2, vm.Do1Counter);

            vm             = CommandTests_a.Create();
            vm.CanDo1Value = true;
            bt             = BindingTestHelper.BindAssert <Button>("Button", "Command", "{b:DXCommand Do1(), CanExecute='CanDo1()'}", null, vm);
            Assert.AreEqual(1, vm.CanDo1Counter);

            vm = CommandTests_a.Create();
            bt = BindingTestHelper.BindAssert <Button>("Button", "Command", "{b:DXCommand Do1(), CanExecute='CanDo1()'}", null, vm);
            Assert.AreEqual(1, vm.CanDo1Counter);
            Assert.AreEqual(false, BindingTestHelper.CanDoCommand(bt));
            Assert.AreEqual(2, vm.CanDo1Counter);
            Assert.AreEqual(0, vm.Do1Counter);
            vm.CanDo1Value = true;
            Assert.AreEqual(true, BindingTestHelper.CanDoCommand(bt));
            Assert.AreEqual(3, vm.CanDo1Counter);
            BindingTestHelper.DoCommand(bt);
            Assert.AreEqual(1, vm.Do1Counter);
        }
コード例 #4
0
        public virtual void CommandInDataTemplate()
        {
            string xaml  = @"
<Grid>
    <Grid.Resources>
        <DataTemplate x:Key=""temp"">
            <Button Command=""{b:DXCommand 'Method($test:BindingTests_a.StaticIntProp)'}""/>
        </DataTemplate>
    </Grid.Resources>
    <ContentControl Content=""{b:DXBinding}"" ContentTemplate=""{StaticResource temp}""/>
    <ContentControl Content=""{b:DXBinding}"" ContentTemplate=""{StaticResource temp}""/>
</Grid>
";
            var    panel = BindingTestHelper.LoadXaml <Grid>(xaml);

            BindingTestHelper.VisualTest(panel, () => {
                BindingTests_a.Static(2);
                var vm            = CommandTests_a.Create();
                var tb1           = LayoutTreeHelper.GetVisualChildren(panel.Children[0]).OfType <Button>().First();
                var tb2           = LayoutTreeHelper.GetVisualChildren(panel.Children[1]).OfType <Button>().First();
                panel.DataContext = vm;
                BindingTestHelper.DoEvents(panel);
                BindingTestHelper.DoCommand(tb1);
                Assert.AreEqual(1, vm.MethodCounter);
                BindingTestHelper.DoCommand(tb2);
                Assert.AreEqual(2, vm.MethodCounter);
            });
        }
コード例 #5
0
        public virtual void TwoExecute()
        {
            var vm = CommandTests_a.Create();
            var bt = BindingTestHelper.BindAssert <Button>("Button", "Command", "{b:DXCommand Execute='Do1(); Do2()'}", null, vm);

            BindingTestHelper.DoCommand(bt);
            Assert.AreEqual(1, vm.Do1Counter);
            Assert.AreEqual(1, vm.Do2Counter);
            BindingTestHelper.DoCommand(bt);
            Assert.AreEqual(2, vm.Do1Counter);
            Assert.AreEqual(2, vm.Do2Counter);

            vm = CommandTests_a.Create();
            bt = BindingTestHelper.BindAssert <Button>("Button", "Command", "{b:DXCommand Execute='Do1(); Do2()', CanExecute='CanDo1() &amp;&amp; CanDo2()'}", null, vm);
            Assert.AreEqual(false, BindingTestHelper.CanDoCommand(bt));
            Assert.AreEqual(2, vm.CanDo1Counter);
            Assert.AreEqual(0, vm.CanDo2Counter);
            vm.CanDo1Value = true;
            Assert.AreEqual(false, BindingTestHelper.CanDoCommand(bt));
            Assert.AreEqual(3, vm.CanDo1Counter);
            Assert.AreEqual(1, vm.CanDo2Counter);
            vm.CanDo2Value = true;
            Assert.AreEqual(true, BindingTestHelper.CanDoCommand(bt));
            Assert.AreEqual(4, vm.CanDo1Counter);
            Assert.AreEqual(2, vm.CanDo2Counter);
            BindingTestHelper.DoCommand(bt);
            Assert.AreEqual(1, vm.Do1Counter);
            Assert.AreEqual(1, vm.Do2Counter);
        }
コード例 #6
0
        public void RaiseCustomRoutedEvent()
        {
            RoutedEventArgs newEventArgs = new RoutedEventArgs(CustomRoutedEventProperty);

            RaiseEvent(newEventArgs);
            BindingTestHelper.DoEvents(this);
        }
コード例 #7
0
        public virtual void NoDataContextTest_T543513()
        {
            var bt = BindingTestHelper.BindAssert <EventTests_visual>("test:EventTests_visual", "CustomEvent", "{b:DXEvent Do1()}", null, null);

            bt.RaiseCustomEvent();

            bt = BindingTestHelper.BindAssert <EventTests_visual>("test:EventTests_visual", "CustomEvent", "{b:DXEvent 'Do1(@sender, @args)'}", null, null);
            bt.RaiseCustomEvent();
        }
コード例 #8
0
        public virtual void TwoMethods()
        {
            var vm = EventTests_a.Create();
            var bt = BindingTestHelper.BindAssert <EventTests_visual>("test:EventTests_visual", "CustomEvent", "{b:DXEvent 'Do1(); Do2()'}", null, vm);

            bt.RaiseCustomEvent();
            Assert.AreEqual(1, vm.Do1Counter);
            Assert.AreEqual(1, vm.Do2Counter);
        }
コード例 #9
0
        public void T983298()
        {
            var vm = EventTests_a.Create();
            var bt = BindingTestHelper.BindAssert <EventTests_visual>(
                "test:EventTests_visual",
                "CustomEvent",
                "{b:DXEvent Do6(null)}", null, vm);

            bt.RaiseCustomEvent();
            Assert.AreEqual(1, vm.Do6Counter);
        }
コード例 #10
0
        public void AttachedPropertyTest()
        {
            var bt = BindingTestHelper.BindAssert <Button>(
                "Button", "Command",
                @"{b:DXCommand 
                    Execute='@s.($test:CommandTests_a.AttachedProp) = true'}",
                null, null, false);

            Assert.AreEqual(null, CommandTests_a.GetAttachedProp(bt));
            BindingTestHelper.DoCommand(bt); BindingTestHelper.DoEvents(bt);
            Assert.AreEqual(true, CommandTests_a.GetAttachedProp(bt));
        }
コード例 #11
0
        public virtual void StaticMethod()
        {
            CommandTests_a.DoValue = 0;
            var bt = BindingTestHelper.BindAssert <Button>("Button", "Command", "{b:DXCommand '$test:CommandTests_a.DoStatic()'}", null, null);

            BindingTestHelper.DoCommand(bt);
            Assert.AreEqual(1, CommandTests_a.DoValue);

            CommandTests_a.DoValue = 0;
            bt = BindingTestHelper.BindAssert <Button>("Button", "Command", "{b:DXCommand '$test:CommandTests_a.DoStatic()'}", null, new object());
            BindingTestHelper.DoCommand(bt);
            Assert.AreEqual(1, CommandTests_a.DoValue);
        }
コード例 #12
0
        public void AssignOperator_Static()
        {
            CommandTests_a.DoValue = 0;
            var bt = BindingTestHelper.BindAssert <Button>(
                "Button", "Command",
                @"{b:DXCommand 
                    Execute='$test:CommandTests_a.DoValue = $test:CommandTests_a.DoValue + 1'}",
                null, null);

            Assert.AreEqual(0, CommandTests_a.DoValue);
            BindingTestHelper.DoCommand(bt); BindingTestHelper.DoEvents(bt);
            Assert.AreEqual(1, CommandTests_a.DoValue);
        }
コード例 #13
0
        public virtual void StaticMethod()
        {
            EventTests_a.DoValue = 0;
            var bt = BindingTestHelper.BindAssert <EventTests_visual>("test:EventTests_visual", "CustomEvent", "{b:DXEvent '$test:EventTests_a.DoStatic()'}", null, null);

            bt.RaiseCustomEvent();
            Assert.AreEqual(1, EventTests_a.DoValue);

            EventTests_a.DoValue = 0;
            bt = BindingTestHelper.BindAssert <EventTests_visual>("test:EventTests_visual", "CustomEvent", "{b:DXEvent '$test:EventTests_a.DoStatic()'}", null, new object());
            bt.RaiseCustomEvent();
            Assert.AreEqual(1, EventTests_a.DoValue);
        }
コード例 #14
0
        public virtual void OneMethod()
        {
            var vm = EventTests_a.Create();
            var bt = BindingTestHelper.BindAssert <EventTests_visual>("test:EventTests_visual", "CustomRoutedEvent", "{b:DXEvent Do1()}", null, vm);

            Assert.AreEqual(0, vm.Do1Counter);
            bt.RaiseCustomRoutedEvent();
            Assert.AreEqual(1, vm.Do1Counter);

            bt = BindingTestHelper.BindAssert <EventTests_visual>("test:EventTests_visual", "CustomEvent", "{b:DXEvent Do1()}", null, vm);
            bt.RaiseCustomEvent();
            Assert.AreEqual(2, vm.Do1Counter);
        }
        public void T709285()
        {
            var vm = new T709285_VM();

            ((T709285_VM_Base)vm).Prop = "1";
            var bt = BindingTestHelper.BindAssert <EventTests_visual>(
                "test:EventTests_visual",
                "CustomRoutedEvent",
                "{b:DXEvent Do(Prop)}", null, vm);

            Assert.AreEqual(null, vm.ResProp);
            bt.RaiseCustomRoutedEvent();
            Assert.AreEqual("1", vm.ResProp);
        }
コード例 #16
0
        public void NewOperator()
        {
            var vm = EventTests_a.Create();
            var bt = BindingTestHelper.BindAssert <EventTests_visual>(
                "test:EventTests_visual",
                "CustomRoutedEvent",
                "{b:DXEvent Do5(new $Thickness(@s.Margin.Left))}", null, vm);

            bt.RaiseCustomRoutedEvent();
            Assert.AreEqual(new Thickness(), vm.Do5V);
            bt.Margin = new Thickness(1);
            bt.RaiseCustomRoutedEvent();
            Assert.AreEqual(new Thickness(1), vm.Do5V);
        }
コード例 #17
0
        public void AssignOperator_ElementName()
        {
            string xaml   = @"
<Grid x:Name=""panel"" Tag=""{b:DXBinding '1'}"">
    <test:EventTests_visual CustomRoutedEvent=""{b:DXEvent Handler='@e(panel).Tag = @e(panel).Tag + 1'}""/>
</Grid>
";
            var    panel  = BindingTestHelper.LoadXaml <Grid>(xaml);
            var    visual = (EventTests_visual)panel.Children[0];

            Assert.AreEqual(1, panel.Tag);
            visual.RaiseCustomRoutedEvent();
            Assert.AreEqual(2, panel.Tag);
        }
コード例 #18
0
        public void AssignOperator_ElementName()
        {
            string xaml  = @"
<Grid x:Name=""panel"" Tag=""{b:DXBinding '1'}"">
    <Button Command=""{b:DXCommand Execute='@e(panel).Tag = @e(panel).Tag + 1'}""/>
</Grid>
";
            var    panel = BindingTestHelper.LoadXaml <Grid>(xaml);
            var    bt    = (Button)panel.Children[0];

            Assert.AreEqual(1, panel.Tag);
            BindingTestHelper.DoCommand(bt); BindingTestHelper.DoEvents(bt);
            Assert.AreEqual(2, panel.Tag);
        }
コード例 #19
0
        public virtual void Arguments()
        {
            var vm = CommandTests_a.Create();
            var bt = BindingTestHelper.BindAssert <Button>("Button", "Command",
                                                           "{b:DXCommand Execute='Do3(@s.Tag.Parameter, @parameter);', CanExecute='CanDo3(@s.Tag.CanDo)'}", null, vm);

            Assert.AreEqual(false, BindingTestHelper.CanDoCommand(bt));
            bt.Tag = new { CanDo = true }; BindingTestHelper.DoEvents(bt);
            Assert.AreEqual(false, BindingTestHelper.CanDoCommand(bt));
            bt.Tag = new { CanDo = true, Parameter = 1 }; BindingTestHelper.DoEvents(bt);
            Assert.AreEqual(false, BindingTestHelper.CanDoCommand(bt));
            bt.CommandParameter = 1; BindingTestHelper.DoEvents(bt);
            Assert.AreEqual(true, BindingTestHelper.CanDoCommand(bt));
            BindingTestHelper.DoCommand(bt);
            Assert.AreEqual(2, vm.Do3Value);
        }
コード例 #20
0
        public void AssignOperators()
        {
            var vm = new CommandTests_b()
            {
                IntProp = 0
            };
            var bt = BindingTestHelper.BindAssert <Button>(
                "Button", "Command",
                @"{b:DXCommand 
                    Execute='IntProp = IntProp + 1; IntProp = IntProp + 1;;'}",
                null, vm);

            Assert.AreEqual(0, vm.IntProp);
            BindingTestHelper.DoCommand(bt); BindingTestHelper.DoEvents(bt);
            Assert.AreEqual(2, vm.IntProp);
        }
コード例 #21
0
        public void T684511()
        {
            var vm = new CommandTests_b();
            var bt = BindingTestHelper.BindAssert <Button>(
                "Button", "Command",
                @"{b:DXCommand Execute='DoException()'}",
                null, vm);

            Assert.DoesNotThrow(() => BindingTestHelper.DoCommand(bt));

            bt = BindingTestHelper.BindAssert <Button>(
                "Button", "Command",
                @"{b:DXCommand Execute='DoException()', CatchExceptions=False}",
                null, vm);
            var e = Assert.Throws <TargetInvocationException>(() => BindingTestHelper.DoCommand(bt));

            Assert.AreEqual("DoException", e.InnerException.Message);
        }
コード例 #22
0
        public virtual void CommandInStyleSetter()
        {
            string xaml1 = @"
<Grid>
    <Grid.Resources>
        <Style x:Key=""st"" TargetType=""Button"">
            <Setter Property=""Command"" Value=""{b:DXCommand Method($test:BindingTests_a.StaticIntProp)}""/>
        </Style>
    </Grid.Resources>
    <Button Style=""{StaticResource st}""/>
    <Button Style=""{StaticResource st}""/>
</Grid>
";
            string xaml2 = @"
<Grid>
    <Grid.Resources>
        <Style TargetType=""Button"">
            <Setter Property=""Command"" Value=""{b:DXCommand Method($test:BindingTests_a.StaticIntProp)}""/>
        </Style>
    </Grid.Resources>
    <Button/>
    <Button/>
</Grid>
";

            Action <string> test = xamlStr => {
                BindingTests_a.Static(2);
                var panel = BindingTestHelper.LoadXaml <Grid>(xamlStr);
                var tb1   = (Button)panel.Children[0];
                var tb2   = (Button)panel.Children[1];
                var vm    = CommandTests_a.Create();
                panel.DataContext = vm;
                BindingTestHelper.DoEvents(panel);
                BindingTestHelper.DoCommand(tb1);
                Assert.AreEqual(2, vm.MethodValue);
                BindingTests_a.Static(3);
                BindingTestHelper.DoCommand(tb2);
                Assert.AreEqual(3, vm.MethodValue);
            };

            test(xaml1);
            test(xaml2);
        }
コード例 #23
0
        public void AssignOperator()
        {
            var vm = new CommandTests_b()
            {
                IntProp = 0
            };
            var bt = BindingTestHelper.BindAssert <Button>(
                "Button", "Command",
                @"{b:DXCommand 
                    Execute='IntProp = IntProp + 1'}",
                null, vm);

            Assert.AreEqual(0, vm.IntProp);
            BindingTestHelper.DoCommand(bt); BindingTestHelper.DoEvents(bt);
            Assert.AreEqual(1, vm.IntProp);

            vm.IntProp = 0;
            bt         = BindingTestHelper.BindAssert <Button>(
                "Button", "Command",
                @"{b:DXCommand 
                    Execute='IntProp = IntProp + @parameter'}",
                null, vm);
            bt.CommandParameter = 1;
            Assert.AreEqual(0, vm.IntProp);
            BindingTestHelper.DoCommand(bt); BindingTestHelper.DoEvents(bt);
            Assert.AreEqual(1, vm.IntProp);
            bt.CommandParameter = 2;
            BindingTestHelper.DoCommand(bt); BindingTestHelper.DoEvents(bt);
            Assert.AreEqual(3, vm.IntProp);

            bt = BindingTestHelper.BindAssert <Button>(
                "Button", "Command",
                @"{b:DXCommand 
                    Execute='@s.Tag = @parameter'}",
                null, null);
            bt.CommandParameter = 1;
            BindingTestHelper.DoCommand(bt); BindingTestHelper.DoEvents(bt);
            Assert.AreEqual(1, bt.Tag);
            bt.CommandParameter = 2;
            BindingTestHelper.DoCommand(bt); BindingTestHelper.DoEvents(bt);
            Assert.AreEqual(2, bt.Tag);
        }
コード例 #24
0
        public void NewOperator()
        {
            var vm = new CommandTests_b();
            var bt = BindingTestHelper.BindAssert <Button>(
                "Button", "Command",
                @"{b:DXCommand 
                    Execute='Do(@s.Margin);', 
                    CanExecute='new $Thickness(@s.Margin.Bottom).Left == 1'}",
                null, vm);

            Assert.AreEqual(false, BindingTestHelper.CanDoCommand(bt));
            Assert.AreEqual(0, vm.DoubleProp);

            bt.Margin = new Thickness(1, 0, 0, 0); BindingTestHelper.DoEvents(bt);
            Assert.AreEqual(false, BindingTestHelper.CanDoCommand(bt));
            Assert.AreEqual(0, vm.DoubleProp);

            bt.Margin = new Thickness(1, 0, 0, 1); BindingTestHelper.DoEvents(bt);
            Assert.AreEqual(true, BindingTestHelper.CanDoCommand(bt));
            BindingTestHelper.DoCommand(bt); BindingTestHelper.DoEvents(bt);
            Assert.AreEqual(1, vm.DoubleProp);
        }
コード例 #25
0
 public virtual void Init()
 {
     BindingListener.Enable();
     BindingTestHelper.TestsSetUp();
     BindingTestHelper.SetResolvingMode(DXBindingResolvingMode.LegacyStaticTyping);
 }
コード例 #26
0
 public void Init()
 {
     BindingListener.Enable();
     BindingTestHelper.TestsSetUp();
 }
コード例 #27
0
 public void TearDown()
 {
     BindingTestHelper.TestsTearDown();
     BindingListener.Disable();
 }
コード例 #28
0
 public override void Init()
 {
     base.Init();
     BindingTestHelper.SetResolvingMode(DXBindingResolvingMode.DynamicTyping);
 }
コード例 #29
0
 public virtual void TearDown()
 {
     BindingTestHelper.TestsTearDown();
     BindingListener.Disable();
     BindingTestHelper.ClearResolvingMode();
 }
コード例 #30
0
 public override void TearDown()
 {
     base.TearDown();
     BindingTestHelper.ClearResolvingMode();
 }