Пример #1
0
        public async Task NavigateAsync_ShouldWaitForAnimationEnd()
        {
            await Test(async (wpfnav, _) =>
            {
                var vm = new VM();
                wpfnav.Should().NotBeNull();

                _NavigationBuilder.Register <VM>(GetRelativePath(TestContext.AnimatedNavigation));

                wpfnav.UseINavigable = true;

                DateTime?opened   = null;
                DisplayEvent de   = null;
                wpfnav.OnDisplay += (o, e) => { opened = DateTime.Now; de = e; };

                await wpfnav.NavigateAsync(vm);
                var nav = DateTime.Now;

                await Task.Delay(3000);

                de.Should().NotBeNull();
                de.DisplayedViewModel.Should().Be(vm);
                opened.HasValue.Should().BeTrue();
                opened.Value.Subtract(nav).Should().BeCloseTo(TimeSpan.FromSeconds(2), 100);
            });
        }
        public void Basic_Option_Simple()
        {
            Test((c, w) =>
            {
                var mre = new ManualResetEvent(false);

                DisplayEvent de = null;
                EventHandler <DisplayEvent> ea = null;
                ea           = (o, e) => { de = e; c.OnDisplay -= ea; };
                c.OnDisplay += ea;
                var dc       = new Person();

                w.RunOnUIThread(() =>
                {
                    c.Mode               = JavascriptBindingMode.OneWay;
                    string relp          = "javascript\\navigation_1.html";
                    c.Uri                = new Uri(string.Format("{0}\\{1}", Assembly.GetAssembly(typeof(Test_HTMLViewControl)).GetPath(), relp));
                    w.Window.DataContext = dc;
                    mre.Set();
                });

                mre.WaitOne();

                Thread.Sleep(2500);
                de.Should().NotBeNull();
                de.DisplayedViewModel.Should().Be(dc);
            });
        }
Пример #3
0
        public void Test_WPFBrowserNavigator_Simple()
        {
            var vm = new VM();

            TestNavigation((wpfnav, WindowTest)
                           =>
            {
                wpfnav.Should().NotBeNull();
                _INavigationBuilder.Register <VM>("Navigation data\\index.html");
                wpfnav.UseINavigable = true;

                var mre         = new ManualResetEvent(false);
                DateTime?nav    = null;
                DateTime?Opened = null;
                DisplayEvent de = null;

                wpfnav.OnDisplay += (o, e) => { Opened = DateTime.Now; de = e; };

                WindowTest.RunOnUIThread(
                    () =>
                {
                    wpfnav.NavigateAsync(vm).ContinueWith
                    (
                        t =>
                    {
                        vm.Navigation.Should().Be(wpfnav);
                        nav = DateTime.Now;
                        mre.Set();
                    });
                });

                mre.WaitOne();
                mre = new ManualResetEvent(false);
                Thread.Sleep(4500);

                de.Should().NotBeNull();
                de.DisplayedViewModel.Should().Be(vm);
                Opened.HasValue.Should().BeTrue();
                Opened.Value.Subtract(nav.Value).Should().BeGreaterThan(TimeSpan.FromSeconds(2)).
                And.BeLessOrEqualTo(TimeSpan.FromSeconds(3));

                WindowTest.RunOnUIThread(
                    () =>
                {
                    wpfnav.NavigateAsync(vm).ContinueWith
                    (
                        t =>
                    {
                        mre.Set();
                    });
                });

                mre.WaitOne();
                Thread.Sleep(500);
                vm.Navigation.Should().Be(wpfnav);
            });
        }
        public void Basic_Option_Simple_UsingRelativePath_AfterDataContext()
        {
            Test((c, w) =>
            {
                var mre = new ManualResetEvent(false);

                DisplayEvent de = null;
                EventHandler <DisplayEvent> ea = null;
                ea           = (o, e) => { de = e; c.OnDisplay -= ea; };
                c.OnDisplay += ea;
                var dc       = new Person();

                string relp = "javascript\\navigation_1.html";
                string path = string.Format("{0}\\{1}", typeof(HTMLViewControl).Assembly.GetPath(), relp);
                var jvs     = PrepareFiles();

                //<script src="src\knockout.js" type="text/javascript"></script>
                //<script src="src\Ko_Extension.js" type="text/javascript"></script>
                //<script src="src\Ko_register.js" type="text/javascript"></script>

                w.RunOnUIThread(() =>
                {
                    c.Mode = JavascriptBindingMode.OneWay;
                    w.Window.DataContext = dc;
                    c.RelativeSource     = relp;
                    mre.Set();
                });

                mre.WaitOne();

                Thread.Sleep(2000);
                foreach (string jv in jvs)
                {
                    string p = string.Format("{0}\\javascript\\src\\{1}", typeof(HTMLViewControl).Assembly.GetPath(), jv);
                    File.Delete(p);
                }
                File.Delete(path);
                de.Should().NotBeNull();
                de.DisplayedViewModel.Should().Be(dc);
            });
        }