void Ex10()
        {
            var pointerPressedHandler      = Substitute.For <Action <PointerDeviceType> >();
            var dependencyArgumentsHandler = Substitute.For <Action <TestUwpControllers.IDependency1, TestUwpControllers.IDependency2, TestUwpControllers.IDependency3> >();
            var dependency1 = new TestUwpControllers.Dependency1();
            var dependency2 = new TestUwpControllers.Dependency2();
            var dependency3 = new TestUwpControllers.Dependency3();

            TestUwpControllers.DependencyParameterControllerAsync controller = null;
            Given("a controller", () => controller = new TestUwpControllers.DependencyParameterControllerAsync {
                PointerPressedHandler = pointerPressedHandler, DependencyArgumentsHandler = dependencyArgumentsHandler
            });
            When("the PointerPressed event is raised asynchronously using the EventHandlerBase", async() =>
                 await UwpController.Using(Substitute.For <IPointerRoutedEventArgsResolver>(), typeof(PointerRoutedEventArgsWrapper))
                 .Apply(resolver => resolver.Pointer(Arg.Any <PointerRoutedEventArgs>()).Returns((Pointer)null))
                 .Using(Substitute.For <IPointerResolver>(), typeof(PointerWrapper))
                 .Apply(resolver => resolver.PointerDeviceType(Arg.Any <Pointer>()).Returns(PointerDeviceType.Mouse))
                 .EventHandlersOf(controller)
                 .GetBy("Element")
                 .Resolve <TestUwpControllers.IDependency1>(() => dependency1)
                 .Resolve <TestUwpControllers.IDependency2>(() => dependency2)
                 .Resolve <TestUwpControllers.IDependency3>(() => dependency3)
                 .RaiseAsync("PointerPressed")
                 );
            Then("the PointerPressed event should be handled", () => pointerPressedHandler.Received(1).Invoke(PointerDeviceType.Mouse));
            Then("the dependency arguments should be injected", () => dependencyArgumentsHandler.Received(1).Invoke(dependency1, dependency2, dependency3));
        }
 void Ex02()
 {
     Extension = new TestExtension();
     Given("a controller", () => Controller = new TestUwpControllers.TestUwpController());
     When("an extension is added", () => UwpController.AddExtension(Extension));
     Then("the container of the extension should be retrieved", () => UwpController.Retrieve <TestExtension, object>(Controller) == TestExtension.TestExtensionContainer);
 }
        void Ex04()
        {
            var keyDownHandler             = Substitute.For <Action <VirtualKey> >();
            var dependencyArgumentsHandler = Substitute.For <Action <TestUwpControllers.IDependency1, TestUwpControllers.IDependency2, TestUwpControllers.IDependency3> >();
            var dependency1 = new TestUwpControllers.Dependency1();
            var dependency2 = new TestUwpControllers.Dependency2();
            var dependency3 = new TestUwpControllers.Dependency3();

            TestUwpControllers.DependencyParameterController controller = null;
            Given("a controller", () => controller = new TestUwpControllers.DependencyParameterController {
                KeyDownAssertionHandler = keyDownHandler, DependencyArgumentsHandler = dependencyArgumentsHandler
            });
            When("the KeyDown event is raised using the EventHandlerBase", () =>
                 UwpController.Using(Substitute.For <IKeyRoutedEventArgsResolver>(), typeof(KeyRoutedEventArgsWrapper))
                 .Apply(resolver => resolver.Key(Arg.Any <KeyRoutedEventArgs>()).Returns(VirtualKey.Enter))
                 .EventHandlersOf(controller)
                 .GetBy("Element")
                 .Resolve <TestUwpControllers.IDependency1>(() => dependency1)
                 .Resolve <TestUwpControllers.IDependency2>(() => dependency2)
                 .Resolve <TestUwpControllers.IDependency3>(() => dependency3)
                 .Raise("KeyDown")
                 );
            Then("the KeyDown event should be handled", () => keyDownHandler.Received(1).Invoke(VirtualKey.Enter));
            Then("the dependency arguments should be injected", () => dependencyArgumentsHandler.Received(1).Invoke(dependency1, dependency2, dependency3));
        }
        public void Dispose()
        {
            if (Extension == null)
            {
                return;
            }

            UwpController.RemoveExtension(Extension);
        }
        async Task Ex07()
        {
            var dataContextChangedHandled = new[] { false, false, false };
            var loadedEventHandled        = new[] { false, false, false };
            var changedEventHandled       = new[] { false, false, false };

            await RunAsync(() =>
            {
                Given("an element that contains the data context", () => Element = new TestElement {
                    Name = "Element", DataContext = new TestUwpControllers.MultiTestDataContext()
                });
                When("the UwpController is enabled for the element", () =>
                {
                    UwpController.SetIsEnabled(Element, true);
                    GetController <TestUwpControllers.MultiTestUwpControllerA>(Element).DataContextChangedAssertionHandler = () => dataContextChangedHandled[0] = true;
                    GetController <TestUwpControllers.MultiTestUwpControllerA>(Element).LoadedAssertionHandler             = () => loadedEventHandled[0] = true;
                    GetController <TestUwpControllers.MultiTestUwpControllerA>(Element).ChangedAssertionHandler            = () => changedEventHandled[0] = true;

                    GetController <TestUwpControllers.MultiTestUwpControllerB>(Element).DataContextChangedAssertionHandler = () => dataContextChangedHandled[1] = true;
                    GetController <TestUwpControllers.MultiTestUwpControllerB>(Element).LoadedAssertionHandler             = () => loadedEventHandled[1] = true;
                    GetController <TestUwpControllers.MultiTestUwpControllerB>(Element).ChangedAssertionHandler            = () => changedEventHandled[1] = true;

                    GetController <TestUwpControllers.MultiTestUwpControllerC>(Element).DataContextChangedAssertionHandler = () => dataContextChangedHandled[2] = true;
                    GetController <TestUwpControllers.MultiTestUwpControllerC>(Element).LoadedAssertionHandler             = () => loadedEventHandled[2] = true;
                    GetController <TestUwpControllers.MultiTestUwpControllerC>(Element).ChangedAssertionHandler            = () => changedEventHandled[2] = true;
                });
                Then("the data context of the controller should be set", () => UwpController.GetControllers(Element).Cast <TestUwpControllers.TestUwpControllerBase>().All(controller => controller.DataContext == Element.DataContext));
            });

            When("the element is set for the content of the window", async() => await SetWindowContent(Element));

            await RunAsync(() =>
            {
                Then("the element of the controller should be set", () => UwpController.GetControllers(Element).Cast <TestUwpControllers.TestUwpControllerBase>().All(controller => controller.Element == Element));

                Then("the DataContextChanged event should be handled", () => dataContextChangedHandled.All(h => h));
                Then("the Loaded event should be handled", () => loadedEventHandled.All(h => h));

                When("the Changed event of the element is raised", () => Element.RaiseChanged());
                Then("the Changed event should be handled", () => changedEventHandled.All(h => h));
            });

            When("the content of the window is cleared in order to unload the element", async() => await ClearWindowContent());

            await RunAsync(() =>
            {
                Then("the data context of the controller should be null", () => UwpController.GetControllers(Element).Cast <TestUwpControllers.TestUwpControllerBase>().All(controller => controller.DataContext == null));
                Then("the element of the controller should be null", () => UwpController.GetControllers(Element).Cast <TestUwpControllers.TestUwpControllerBase>().All(controller => controller.Element == null));

                for (int index = 0; index < changedEventHandled.Length; index++)
                {
                    changedEventHandled[index] = false;
                }
                When("the Changed event of the element is raised", () => Element.RaiseChanged());
                Then("the Changed event should not be handled", () => changedEventHandled.All(h => !h));
            });
        }
Exemplo n.º 6
0
        private void OnElementUnloaded(object sender, RoutedEventArgs e)
        {
            Detach();

            if (!(sender is FrameworkElement element))
            {
                return;
            }
            UwpController.ClearControllers(element);
        }
 async Task Ex02(object dataContext, Type[] expectedControllerTypes)
 {
     await RunAsync(() =>
     {
         Given("an element that does not contain the data context", () => Element = new TestElement());
         When("the UwpController is enabled for the element", () => UwpController.SetIsEnabled(Element, true));
         When("a data context of the element is set", () => Element.DataContext = dataContext);
         Then("the controller should be attached to the element", () =>
              UwpController.GetControllers(Element).Select(controller => controller.GetType()).SequenceEqual(expectedControllerTypes) &&
              UwpController.GetControllers(Element).Cast <TestController>().All(controller => controller.DataContext == dataContext)
              );
     });
 }
        async Task Ex06()
        {
            var dataContextChangedHandled = false;
            var loadedEventHandled        = false;
            var changedEventHandled       = false;

            TestUwpControllers.TestUwpController controller = null;

            await RunAsync(() =>
            {
                Given("an element that contains the data context", () => Element = new TestElement {
                    Name = "Element", DataContext = new TestUwpControllers.TestDataContext()
                });
                When("the UwpController is enabled for the element", () =>
                {
                    UwpController.SetIsEnabled(Element, true);
                    controller = GetController <TestUwpControllers.TestUwpController>(Element);
                    controller.DataContextChangedAssertionHandler = () => dataContextChangedHandled = true;
                    controller.LoadedAssertionHandler             = () => loadedEventHandled = true;
                    controller.ChangedAssertionHandler            = () => changedEventHandled = true;
                });
                Then("the data context of the controller should be set", () => GetController <TestUwpControllers.TestUwpController>(Element).DataContext == Element.DataContext);
            });

            When("the element is set for the content of the window", async() => await SetWindowContent(Element));

            await RunAsync(() =>
            {
                Then("the element of the controller should be set", () => GetController <TestUwpControllers.TestUwpController>(Element).Element == Element);

                Then("the DataContextChanged event should be handled", () => dataContextChangedHandled);
                Then("the Loaded event should be handled", () => loadedEventHandled);

                When("the UwpController is disabled for the element", () => UwpController.SetIsEnabled(Element, false));
                Then("the controller should be detached", () => !UwpController.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 Changed event of the element is raised", () => Element.RaiseChanged());
                Then("the Changed event should not be handled", () => !changedEventHandled);
            });

            When("the content of the window is cleared in order to unload the element", async() => await ClearWindowContent());

            When("the element is set for the content of the window", async() => await SetWindowContent(Element));

            await RunAsync(() =>
            {
                Then("the controller should not be attached", () => !UwpController.GetControllers(Element).Any());
            });
        }
 async Task Ex04()
 {
     await RunAsync(() =>
     {
         Given("a data context", () => DataContext = new AttachingTestDataContext());
         Given("an element that contains the data context", () => Element = new TestElement {
             DataContext = DataContext
         });
         When("the UwpController is enabled for the element", () => UwpController.SetIsEnabled(Element, true));
         Then("the data context of the controller should be set", () => GetController <TestController>(Element).DataContext == DataContext);
         When("another data context is set for the element", () => Element.DataContext = AnotherDataContext = new object());
         Then("the data context of the controller should be changed", () => GetController <TestController>(Element).DataContext == AnotherDataContext);
     });
 }
        void Ex01()
        {
            var loadedEventHandled = false;

            TestUwpControllers.TestUwpController controller = null;
            Given("a controller", () => controller = new TestUwpControllers.TestUwpController {
                LoadedAssertionHandler = () => loadedEventHandled = true
            });
            When("the Loaded event is raised using the EventHandlerBase", () =>
                 UwpController.EventHandlersOf(controller)
                 .GetBy("Element")
                 .Raise("Loaded")
                 );
            Then("the Loaded event should be handled", () => loadedEventHandled);
        }
        void Ex02()
        {
            var loadedEventHandled = false;

            TestUwpControllers.TestUwpControllerAsync controller = null;
            Given("a controller", () => controller = new TestUwpControllers.TestUwpControllerAsync {
                LoadedAssertionHandler = () => loadedEventHandled = true
            });
            When("the Loaded event is raised asynchronously using the EventHandlerBase", async() =>
                 await UwpController.EventHandlersOf(controller)
                 .GetBy("Element")
                 .RaiseAsync("Loaded")
                 );
            Then("the Loaded event should be handled", () => loadedEventHandled);
        }
        void Ex05()
        {
            var keyDownHandler = Substitute.For <Action <VirtualKey> >();

            TestUwpControllers.TestUwpControllerAsync controller = null;
            Given("a controller", () => controller = new TestUwpControllers.TestUwpControllerAsync {
                KeyDownAssertionHandler = keyDownHandler
            });
            When("the KeyDown event is raised asynchronously using the EventHandlerBase", async() =>
                 await UwpController.Using(Substitute.For <IKeyRoutedEventArgsResolver>(), typeof(KeyRoutedEventArgsWrapper))
                 .Apply(resolver => resolver.Key(Arg.Any <KeyRoutedEventArgs>()).Returns(VirtualKey.Enter))
                 .EventHandlersOf(controller)
                 .GetBy("Element")
                 .RaiseAsync("KeyDown")
                 );
            Then("the KeyDown event should be handled", () => keyDownHandler.Received(1).Invoke(VirtualKey.Enter));
        }
 async Task Ex03()
 {
     await RunAsync(() =>
     {
         Given("a data context", () => DataContext = new KeyAttachingTestDataContext());
         Given("an element that contains the data context", () => Element = new TestElement {
             DataContext = DataContext
         });
         When("the key of the element is set using the UwpController", () => UwpController.SetKey(Element, "TestElement"));
         Then("the UwpController should be enabled for the element", () => UwpController.GetIsEnabled(Element));
         Then("the controller should be attached to the element", () =>
              UwpController.GetControllers(Element).Count == 1 &&
              UwpController.GetControllers(Element)[0].GetType() == typeof(KeyTestDataContextController) &&
              (UwpController.GetControllers(Element)[0] as KeyTestDataContextController).DataContext == DataContext
              );
     });
 }
        void Ex09()
        {
            var pointerPressedHandler = Substitute.For <Action <PointerDeviceType> >();

            TestUwpControllers.TestUwpControllerAsync controller = null;
            Given("a controller", () => controller = new TestUwpControllers.TestUwpControllerAsync {
                PointerPressedHandler = pointerPressedHandler
            });
            When("the PointerPressed event is raised asynchronously using the EventHandlerBase", async() =>
                 await UwpController.Using(Substitute.For <IPointerRoutedEventArgsResolver>(), typeof(PointerRoutedEventArgsWrapper))
                 .Apply(resolver => resolver.Pointer(Arg.Any <PointerRoutedEventArgs>()).Returns((Pointer)null))
                 .Using(Substitute.For <IPointerResolver>(), typeof(PointerWrapper))
                 .Apply(resolver => resolver.PointerDeviceType(Arg.Any <Pointer>()).Returns(PointerDeviceType.Mouse))
                 .EventHandlersOf(controller)
                 .GetBy("Element")
                 .RaiseAsync("PointerPressed")
                 );
            Then("the PointerPressed event should be handled", () => pointerPressedHandler.Received(1).Invoke(PointerDeviceType.Mouse));
        }
Exemplo n.º 15
0
        async Task Ex01()
        {
            HandledException = true;

            await RunAsync(() =>
            {
                Given("a controller that has an event handler that throws an exception", () => Controller = new TestUwpControllers.ExceptionTestUwpController());
                Given("an element", () => Element = new TestElement());

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

            When("the element is set to the content of the window", async() => await SetWindowContent(Element));

            await RunAsync(() =>
            {
                When("the Changed event of the element is raised", () => Element.RaiseChanged());
                Then("the unhandled exception should be handled", () => UnhandledException != null);
            });
        }
        async Task Ex01()
        {
            Extension = Substitute.For <IUwpControllerExtension>();
            await RunAsync(() =>
            {
                Given("an element that contains a data context", () => Element = new TestElement {
                    DataContext = DataContext
                });
                When("the UwpController is enabled for the element", () =>
                {
                    UwpController.SetIsEnabled(Element, true);
                    Controller = UwpController.GetControllers(Element)[0] as TestUwpControllers.TestUwpController;
                });
                When("the extension is added", () => UwpController.AddExtension(Extension));
            });

            When("the element is set for the content of the window", async() => await SetWindowContent(Element));
            Then("the extension should be attached", () => Extension.Received().Attach(Controller, Element));

            When("the content of the window is cleared in order to unload the element", async() => await ClearWindowContent());
            Then("the extension should be detached", () => Extension.Received().Detach(Controller, Element));
        }
Exemplo n.º 17
0
        async Task Ex01(TestUwpControllers.ITestUwpController controller)
        {
            await RunAsync(() =>
            {
                Given("a data context", () => DataContext   = new object());
                Given("a child element", () => ChildElement = new TestElement {
                    Name = "childElement"
                });
                Given("an element that has the child element", () => Element = new TestElement {
                    Name = "element", Content = ChildElement, DataContext = DataContext
                });

                When("the controller is added", () => UwpController.GetControllers(Element).Add(controller));
                When("the controller is attached to the element", () => UwpController.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);
            });

            EventHandled = false;
            When("the element is set to the content of the window", async() => await SetWindowContent(Element));

            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);
            Then("the event should be handled", () => EventHandled);

            await RunAsync(() =>
            {
                EventHandled = false;
                When("the Changed event of the child element is raised", () => ChildElement.RaiseChanged());
                Then("the Changed event should be handled", () => EventHandled);

                EventHandled = false;
                When("the data context of the child element should be set", () => ChildElement.DataContext = new object());
                Then("the DataContextChanged event should be handled", () => EventHandled);
            });
        }
 T GetController <T>(FrameworkElement element) => UwpController.GetControllers(element).OfType <T>().FirstOrDefault();
Exemplo n.º 19
0
 /// <summary>
 /// Gets event handlers that the specified controller has.
 /// </summary>
 /// <param name="controller">The controller that has event handlers.</param>
 /// <returns>The event handlers that the specified controller has.</returns>
 public EventArgsResolverScopeEventHandlerBase <T> EventHandlersOf(object controller)
 => new EventArgsResolverScopeEventHandlerBase <T>(
     eventArgsResolvers,
     UwpController.Retrieve <UwpEventHandlerExtension, EventHandlerBase <FrameworkElement, UwpEventHandlerItem> >(controller)
     );
Exemplo n.º 20
0
 async Task Ex03(TestUwpControllers.ITestUwpController controller)
 {
     await RunAsync(() =>
     {
         Given("a data context", () => DataContext = new object());
         When("the data context is set to the controller using the UwpController", () => UwpController.SetDataContext(DataContext, controller));
         Then("the data context should be set to the controller", () => controller.DataContext == DataContext);
     });
 }
Exemplo n.º 21
0
 async Task Ex02(TestUwpControllers.ITestUwpController controller)
 {
     await RunAsync(() =>
     {
         Given("a child element", () => ChildElement = new TestElement {
             Name = "childElement"
         });
         Given("an element", () => Element = new TestElement {
             Name = "element"
         });
         When("the child element is set to the controller using the UwpController", () => UwpController.SetElement(ChildElement, controller, true));
         When("the element is set to the controller using the UwpController", () => UwpController.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);
     });
 }
Exemplo n.º 22
0
 public string FindKey(FrameworkElement element) => UwpController.GetKey(element);
Exemplo n.º 23
0
 protected override bool HandleUnhandledException(Exception exc) => UwpController.HandleUnhandledException(exc);