Updating the WalksMainPage code-behind using C#

Now that we have created the CreateNewTrailDetails class that will be responsible for handling the automated UI testing using the UITest framework, our next step is to begin updating the underlying C# code within our WalksMainPage code-behind file in order to disable displaying our TwitterSignInPage ViewModel.

Let's take a look at how we can achieve this by following these steps:

  1. Locate and open the WalksMainPage.xaml.cs file which is located within the Views folder, ensuring that it is displayed within the code editor, and enter the following highlighted code sections:
    //
// WalksMainPage.xaml.cs
// Displays Walk Information within a ListView control from an array//
// Created by Steven F. Daniel on 14/05/2018
// Copyright © 2018 GENIESOFT STUDIOS. All rights reserved.
//
using System;
using TrackMyWalks.Models;
using TrackMyWalks.Services;
using TrackMyWalks.ViewModels;
using Xamarin.Forms;

namespace TrackMyWalks.Views
{
public partial class WalksMainPage : ContentPage
{
// Return the Binding Context for the ViewModel
WalksMainPageViewModel _viewModel => BindingContext as WalksMainPageViewModel;

public WalksMainPage()
{
InitializeComponent();
...
...
}
...
...
// Method to initialise our View Model when the ContentPage appears
protected override async void OnAppearing()
{
base.OnAppearing();

// Perform a check to see if we have logged into Twitter already
if (_viewModel != null)
{
// Call the Init method to initialise the ViewModel
await _viewModel.Init();
/*
if (!TwitterAuthDetails.isLoggedIn)
{
// We need to Navigate and display our Twitter
Sign In Page
await _viewModel.Navigation.NavigateTo<
TwitterSignInPageViewModel>();
}
*/
}
...
...
  1. In the preceding code snippet, we started by modifying the OnAppearing method by commenting out the code that checks the isLoggedIn property within our TwitterAuthDetails class in order to determine if the user has already signed into our app. Then, we navigated to our TwitterSignInPageViewModel using the Navigation property of our _viewModel and the NavigateTo instance method.

If you have configured your Twitter account to use Two-Factor Authentication, you will need to comment out the preceding code within the code snippet, as this will cause problems when running the UITests, as you'll need to manually enter in the code that is generated and provided by Twitter. Alternatively, if you are not using Two-Factor Authentication, you can skip this section altogether.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.133.82.244