예제 #1
0
        void Ex01(TestAvaloniaControllers.ITestAvaloniaController controller)
        {
            Given("a data context", () => DataContext   = new object());
            Given("a child element", () => ChildElement = new Button {
                Name = "ChildElement"
            });
            Given("an element that has the child element", () => Element = new TestElement {
                Name = "element", Content = ChildElement, DataContext = DataContext
            });

            When("the controller is added", () => AvaloniaController.GetControllers(Element).Add(controller));
            When("the controller is attached to the element", () => AvaloniaController.GetControllers(Element).AttachTo(Element));

            Then("the data context of the controller should be set", () => controller.DataContext == DataContext);
            Then("the element of the controller should be null", () => controller.Element == null);
            Then("the child element of the controller should be null", () => controller.ChildElement == null);

            When("the element is attached to the logical tree", () => Element.AttachToLogicalTree());

            Then("the data context of the controller should be set", () => controller.DataContext == DataContext);
            Then("the element of the controller should be set", () => controller.Element == Element);
            Then("the child element of the controller should be set", () => controller.ChildElement == ChildElement);

            EventHandled = false;
            When("the Click event of the child element is raised", () => ChildElement.RaiseEvent(new RoutedEventArgs(Button.ClickEvent, ChildElement)));

            Then("the Click event should be handled", () => EventHandled);
        }
        public void Dispose()
        {
            if (Extension == null)
            {
                return;
            }

            AvaloniaController.RemoveExtension(Extension);
        }
 void Ex04()
 {
     Given("an element that contains the data context", () => Element = new TestElement {
         DataContext = new TestDataContexts.AttachingTestDataContext()
     });
     When("the AvaloniaController is enabled for the element", () => AvaloniaController.SetIsEnabled(Element, true));
     Then("the data context of the controller should be set", () => Element.GetController <TestAvaloniaControllers.TestController>().DataContext == Element.DataContext);
     When("another data context is set for the element", () => Element.DataContext = new object());
     Then("the data context of the controller should be set", () => Element.GetController <TestAvaloniaControllers.TestController>().DataContext == Element.DataContext);
 }
 void Ex02(object dataContext, IEnumerable <Type> expectedControllerTypes)
 {
     Given("an element that does not contain the data context", () => Element = new TestElement());
     When("the AvaloniaController is enabled for the element", () => AvaloniaController.SetIsEnabled(Element, true));
     When("a data context of the element is set", () => Element.DataContext = dataContext);
     Then("the controller should be attached to the element", () =>
          AvaloniaController.GetControllers(Element).Select(controller => controller.GetType()).SequenceEqual(expectedControllerTypes) &&
          AvaloniaController.GetControllers(Element).OfType <TestAvaloniaControllers.TestController>().All(controller => controller.DataContext == Element.DataContext)
          );
 }
 void Ex02()
 {
     When("the Changed event is raised using the EventHandlerBase", async() =>
          await AvaloniaController.EventHandlersOf(new TestAvaloniaControllers.TestAvaloniaController {
         ChangedAssertionHandler = () => ChangedEventHandled = true
     })
          .GetBy("Element")
          .RaiseAsync("Changed")
          );
     Then("the Changed event should be handled", () => ChangedEventHandled);
 }
        void Ex01()
        {
            When("an extension is added to the AvaloniaController", () => AvaloniaController.AddExtension(Extension));
            When("the AvaloniaController is enabled for the element", () => AvaloniaController.SetIsEnabled(Element, true));

            When("the element is attached to the logical tree", () => Element.AttachToLogicalTree());
            Then("the extension should be attached", () => Extension.Attached);

            When("the element is detached from the logical tree", () => Element.DetachFromLogicalTree());
            Then("the extension should be detached", () => Extension.Detached);
        }
 void Ex01()
 {
     When("the AvaloniaController is enabled for the element", () => AvaloniaController.SetIsEnabled(Element, true));
     When("the element is attached to the logical tree", () => Element.AttachToLogicalTree());
     When("the Click event of the button is raised", () =>
     {
         Element.GetController <TestAvaloniaControllers.TestAvaloniaController>().ButtonClickAssertionHandler += () => ClickEventHandled = true;
         Button.RaiseEvent(new RoutedEventArgs(Button.ClickEvent, Button));
     });
     Then("the Click event should be handled", () => ClickEventHandled);
 }
 void Ex03()
 {
     Given("an element that contains the data context", () => Element = new TestElement {
         DataContext = new TestDataContexts.KeyAttachingTestDataContext()
     });
     When("the key of the element is set using the AvaloniaController", () => AvaloniaController.SetKey(Element, "TestElement"));
     Then("the AvaloniaController should be enabled for the element", () => AvaloniaController.GetIsEnabled(Element));
     Then("the controller should be attached to the element", () =>
          AvaloniaController.GetControllers(Element).Select(controller => controller.GetType()).SequenceEqual(new[] { typeof(TestAvaloniaControllers.KeyTestDataContextController) }) &&
          AvaloniaController.GetControllers(Element).OfType <TestAvaloniaControllers.TestController>().All(controller => controller.DataContext == Element.DataContext)
          );
 }
예제 #9
0
        void Ex01()
        {
            ExceptionHandled = true;

            When("the controller is added", () => AvaloniaController.GetControllers(Element).Add(Controller));
            When("the controller is attached to the element", () => AvaloniaController.GetControllers(Element).AttachTo(Element));

            When("the element is attached to the logical tree", () => Element.AttachToLogicalTree());

            When("the Changed event of the element is raised", () => Element.RaiseChanged());
            Then("the unhandled exception should be handled", () => UnhandledException != null);
        }
        void Ex06()
        {
            Given("an element that contains the data context", () => Element = new TestElement {
                Name = "Element", DataContext = new TestDataContexts.TestDataContext()
            });

            When("the AvaloniaController is enabled for the element", () =>
            {
                AvaloniaController.SetIsEnabled(Element, true);
                Controller = Element.GetController <TestAvaloniaControllers.TestAvaloniaController>();
            });
            Then("the data context of the controller should be set", () => Controller.DataContext == Element.DataContext);

            When("the element is attached to the logical tree", () =>
            {
                Controller.AttachedToLogicalTreeAssertionHandler = () => AttachedToLogicalTreeEventHandled = true;
                Element.AttachToLogicalTree();
            });
            Then("the element of the controller should be set", () => Controller.Element == Element);
            Then("the AttachedToLogicalTree event should be handled", () => AttachedToLogicalTreeEventHandled);

            When("the Changed event is raised", () =>
            {
                Controller.ChangedAssertionHandler = () => ChangedEventHandled = true;
                Element.RaiseChanged();
            });
            Then("the Changed event should be handled", () => ChangedEventHandled);

            When("the element is detached from the logical tree", () => Element.DetachFromLogicalTree());
            When("the AvaloniaController is disabled for the element", () => AvaloniaController.SetIsEnabled(Element, false));
            Then("the controller should be detached", () => !AvaloniaController.GetControllers(Element).Any());
            Then("the data context of the controller should be null", () => Controller.DataContext == null);
            Then("the element of the controller should be null", () => Controller.Element == null);

            When("the element is attached to the logical tree", () =>
            {
                AttachedToLogicalTreeEventHandled = false;
                Element.AttachToLogicalTree();
            });
            Then("the AttachedToLogicalTree event should not be handled", () => !AttachedToLogicalTreeEventHandled);
            Then("the controller should not be attached", () => !AvaloniaController.GetControllers(Element).Any());

            When("the Changed event is raised", () =>
            {
                ChangedEventHandled = false;
                Element.RaiseChanged();
            });
            Then("the Changed event should not be handled", () => !ChangedEventHandled);
        }
        void Ex07()
        {
            Given("an element that contains the data context", () => Element = new TestElement {
                Name = "Element", DataContext = new TestDataContexts.MultiTestDataContext()
            });

            When("the AvaloniaController is enabled for the element", () =>
            {
                AvaloniaController.SetIsEnabled(Element, true);
                Controllers = new TestAvaloniaControllers.TestAvaloniaControllerBase[]
                {
                    Element.GetController <TestAvaloniaControllers.MultiTestAvaloniaControllerA>(),
                    Element.GetController <TestAvaloniaControllers.MultiTestAvaloniaControllerB>(),
                    Element.GetController <TestAvaloniaControllers.MultiTestAvaloniaControllerC>()
                };
                AttachedToLogicalTreeEventsHandled = new[] { false, false, false };
                ChangedEventsHandled = new[] { false, false, false };
            });
            Then("the data context of the controller should be set", () => Controllers.All(controller => controller.DataContext == Element.DataContext));

            When("the element is attached to the logical tree", () =>
            {
                for (var index = 0; index < Controllers.Length; index++)
                {
                    var eventHandledIndex = index;
                    Controllers[index].AttachedToLogicalTreeAssertionHandler = () => AttachedToLogicalTreeEventsHandled[eventHandledIndex] = true;
                }
                Element.AttachToLogicalTree();
            });
            Then("the element of the controller should be set", () => Controllers.All(controller => controller.Element == Element));
            Then("the AttachedToLogicalTree event should be handled", () => AttachedToLogicalTreeEventsHandled.All(handled => handled));

            When("the Changed event is raised", () =>
            {
                for (var index = 0; index < Controllers.Length; index++)
                {
                    var eventHandledIndex = index;
                    Controllers[index].ChangedAssertionHandler = () => ChangedEventsHandled[eventHandledIndex] = true;
                }
                Element.RaiseChanged();
            });
            Then("the Changed event should be handled", () => ChangedEventsHandled.All(handled => handled));

            When("the element is detached from the logical tree", () => Element.DetachFromLogicalTree());
            Then("the data context of the controller should be null", () => Controllers.All(controller => controller.DataContext == null));
            Then("the element of the controller should be null", () => Controllers.All(controller => controller.Element == null));

            When("the element is attached to the logical tree", () =>
            {
                for (var index = 0; index < AttachedToLogicalTreeEventsHandled.Length; index++)
                {
                    AttachedToLogicalTreeEventsHandled[index] = false;
                }
                Element.AttachToLogicalTree();
            });
            Then("the AttachedToLogicalTree event should not be handled", () => AttachedToLogicalTreeEventsHandled.All(handled => !handled));

            When("the Changed event is raised", () =>
            {
                for (var index = 0; index < ChangedEventsHandled.Length; index++)
                {
                    ChangedEventsHandled[index] = false;
                }
                Element.RaiseChanged();
            });
            Then("the Changed event should not be handled", () => ChangedEventsHandled.All(handled => !handled));
        }
예제 #12
0
 void Ex02(TestAvaloniaControllers.ITestAvaloniaController controller)
 {
     Given("a child element", () => ChildElement = new Button {
         Name = "ChildElement"
     });
     Given("an element that has the child element", () => Element = new TestElement {
         Name = "element", Content = ChildElement
     });
     When("the child element is set to the controller using the AvaloniaController", () => AvaloniaController.SetElement(ChildElement, controller, true));
     When("the element is set to the controller using the AvaloniaController", () => AvaloniaController.SetElement(Element, controller, true));
     Then("the element should be set to the controller", () => controller.Element == Element);
     Then("the child element should be set to the controller", () => controller.ChildElement == ChildElement);
 }
 public string FindKey(StyledElement element) => AvaloniaController.GetKey(element);
 void Ex02()
 {
     When("an extension is added to the AvaloniaController", () => AvaloniaController.AddExtension(Extension));
     Then("the container of the extension should be retrieved", () => AvaloniaController.Retrieve <TestExtension, object>(Controller) == TestExtension.TestExtensionContainer);
 }
 public static T GetController <T>(this StyledElement element) => AvaloniaController.GetControllers(element).OfType <T>().FirstOrDefault();
 protected override bool HandleUnhandledException(Exception exc) => AvaloniaController.HandleUnhandledException(exc);
예제 #17
0
 void Ex03(TestAvaloniaControllers.ITestAvaloniaController controller)
 {
     Given("a data context", () => DataContext = new object());
     When("the data context is set to the controller using the AvaloniaController", () => AvaloniaController.SetDataContext(DataContext, controller));
     Then("the data context should be set to the controller", () => controller.DataContext == DataContext);
 }