Пример #1
0
        public async Task ResolvesParentElementFrom_EventToCommandBehavior()
        {
            var app = CreateMockApplication();

            Log.Listeners.Clear();
            var logObserver = new FormsLogObserver();

            Log.Listeners.Add(logObserver);

            var behavior = new EventToCommandBehavior()
            {
                EventName = "ItemTapped"
            };
            var layout = new ListView();

            layout.Behaviors.Add(behavior);

            var serviceProvider = new XamlServiceProvider();

            serviceProvider.Add(typeof(IProvideValueTarget), new XamlValueTargetProvider(behavior, "Command"));

            var navigateExtension = new NavigateToExtension()
            {
                Name = "/AutowireView"
            };

            navigateExtension.ProvideValue(serviceProvider);

            app.MainPage = new NavigationPage(new ContentPage
            {
                Content = layout
            });

            Assert.NotNull(layout.Parent);
            Assert.IsType <ContentPage>(layout.Parent);

            Assert.NotNull(navigateExtension.SourcePage);
            Assert.True(navigateExtension.CanExecute(null));
            var ex = await Record.ExceptionAsync(async() =>
            {
                navigateExtension.Execute(null);
                if (navigateExtension.IsNavigating)
                {
                    await Task.Delay(100);
                }
            });

            Assert.Null(ex);
            Assert.Empty(logObserver.Logs);

            Assert.IsType <AutowireView>(app.MainPage);
        }
Пример #2
0
        public async Task LogsNavigationErrors_WithoutThrowingException()
        {
            var app = CreateMockApplication();

            Log.Listeners.Clear();
            var logObserver = new FormsLogObserver();

            Log.Listeners.Add(logObserver);

            var layout          = new Button();
            var serviceProvider = new XamlServiceProvider();

            serviceProvider.Add(typeof(IProvideValueTarget), new XamlValueTargetProvider(layout, "Command"));

            var navigateExtension = new NavigateToExtension()
            {
                Name = "/NonExistentPage"
            };

            navigateExtension.ProvideValue(serviceProvider);

            app.MainPage = new NavigationPage(new ContentPage
            {
                Content = layout
            });

            Assert.NotNull(layout.Parent);
            Assert.IsType <ContentPage>(layout.Parent);

            Assert.NotNull(navigateExtension.SourcePage);
            Assert.True(navigateExtension.CanExecute(null));
            var ex = await Record.ExceptionAsync(async() =>
            {
                navigateExtension.Execute(null);
                if (navigateExtension.IsNavigating)
                {
                    await Task.Delay(100);
                }
            });

            Assert.Null(ex);
            Assert.NotEmpty(logObserver.Logs);

            Assert.IsType <NavigationPage>(app.MainPage);
        }