Added unit test project for UWP with example tests for MockProvider

This commit is contained in:
Shane Weaver 2021-03-23 14:01:57 -07:00
Родитель 7a148f7c72
Коммит d0debf88fc
17 изменённых файлов: 767 добавлений и 0 удалений

Двоичные данные
UnitTests/UnitTests.UWP/Assets/LockScreenLogo.scale-200.png Normal file

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 1.4 KiB

Двоичные данные
UnitTests/UnitTests.UWP/Assets/SplashScreen.scale-200.png Normal file

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 7.5 KiB

Двоичные данные
UnitTests/UnitTests.UWP/Assets/Square150x150Logo.scale-200.png Normal file

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 2.9 KiB

Двоичные данные
UnitTests/UnitTests.UWP/Assets/Square44x44Logo.scale-200.png Normal file

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 1.6 KiB

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 1.2 KiB

Двоичные данные
UnitTests/UnitTests.UWP/Assets/StoreLogo.png Normal file

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 1.4 KiB

Двоичные данные
UnitTests/UnitTests.UWP/Assets/Wide310x150Logo.scale-200.png Normal file

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 3.1 KiB

Просмотреть файл

@ -0,0 +1,46 @@
<?xml version="1.0" encoding="utf-8"?>
<Package
xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10"
xmlns:mp="http://schemas.microsoft.com/appx/2014/phone/manifest"
xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10"
IgnorableNamespaces="uap mp">
<Identity Name="c089351a-4c91-4cb0-afa7-b976ac715456"
Publisher="CN=shweaver"
Version="1.0.0.0" />
<mp:PhoneIdentity PhoneProductId="c089351a-4c91-4cb0-afa7-b976ac715456" PhonePublisherId="00000000-0000-0000-0000-000000000000"/>
<Properties>
<DisplayName>UnitTests.UWP</DisplayName>
<PublisherDisplayName>WCT</PublisherDisplayName>
<Logo>Assets\StoreLogo.png</Logo>
</Properties>
<Dependencies>
<TargetDeviceFamily Name="Windows.Universal" MinVersion="10.0.0.0" MaxVersionTested="10.0.0.0" />
</Dependencies>
<Resources>
<Resource Language="x-generate" />
</Resources>
<Applications>
<Application Id="vstest.executionengine.universal.App"
Executable="$targetnametoken$.exe"
EntryPoint="UnitTests.UWP.App">
<uap:VisualElements
DisplayName="UnitTests.UWP"
Square150x150Logo="Assets\Square150x150Logo.png"
Square44x44Logo="Assets\Square44x44Logo.png"
Description="UnitTests.UWP"
BackgroundColor="transparent">
<uap:DefaultTile Wide310x150Logo="Assets\Wide310x150Logo.png"/>
<uap:SplashScreen Image="Assets\SplashScreen.png" />
</uap:VisualElements>
</Application>
</Applications>
<Capabilities>
<Capability Name="internetClientServer" />
<Capability Name="privateNetworkClientServer" />
</Capabilities>
</Package>

Просмотреть файл

@ -0,0 +1,21 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System.Reflection;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("UnitTests")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("UnitTests")]
[assembly: AssemblyCopyright("Copyright © 2021")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: AssemblyMetadata("TargetPlatform", "UAP")]
[assembly: ComVisible(false)]

Просмотреть файл

@ -0,0 +1,29 @@
<!--
This file contains Runtime Directives used by .NET Native. The defaults here are suitable for most
developers. However, you can modify these parameters to modify the behavior of the .NET Native
optimizer.
Runtime Directives are documented at https://go.microsoft.com/fwlink/?LinkID=391919
To fully enable reflection for App1.MyClass and all of its public/private members
<Type Name="App1.MyClass" Dynamic="Required All"/>
To enable dynamic creation of the specific instantiation of AppClass<T> over System.Int32
<TypeInstantiation Name="App1.AppClass" Arguments="System.Int32" Activate="Required Public" />
Using the Namespace directive to apply reflection policy to all the types in a particular namespace
<Namespace Name="DataClasses.ViewModels" Serialize="All" />
-->
<Directives xmlns="http://schemas.microsoft.com/netfx/2013/01/metadata">
<Application>
<!--
An Assembly element with Name="*Application*" applies to all assemblies in
the application package. The asterisks are not wildcards.
-->
<Assembly Name="*Application*" Dynamic="Required All" />
<!-- Add your application specific runtime directives here. -->
</Application>
</Directives>

Просмотреть файл

@ -0,0 +1,168 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using Microsoft.Toolkit.Graph.Providers;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Net.Http;
using System.Threading.Tasks;
namespace UnitTests.UWP.Providers
{
[TestClass]
public class Test_MockProvider
{
/// <summary>
/// Create a new instance of the MockProvider and check that is has the proper default state.
/// </summary>
[TestCategory("Providers")]
[TestMethod]
public void Test_MockProvider_Default()
{
IProvider provider = new MockProvider();
Assert.AreEqual(ProviderState.SignedIn, provider.State);
}
/// <summary>
/// Create a new instance of the MockProvider and initiates login.
/// The test checks that the appropriate events are fired and that the provider transitions
/// through the different states as expected.
/// </summary>
[TestCategory("Providers")]
[TestMethod]
public async Task Test_MockProvider_LoginAsync()
{
// Create the new provider, pre-signed out.
IProvider provider = new MockProvider(false);
// The newly created provider should be in a logged out state.
Assert.AreEqual(ProviderState.SignedOut, provider.State);
// Listen for changes in the provider state and count them.
int eventCount = 0;
provider.StateChanged += (s, e) =>
{
eventCount += 1;
// Ensure that the states are properly reported through the StateChanged event.
switch (e.OldState)
{
case ProviderState.SignedOut:
// Login has been initiated, the provider should now be loading.
Assert.AreEqual(ProviderState.Loading, e.NewState);
// Loading should be the first event fired.
Assert.AreEqual(eventCount, 1);
break;
case ProviderState.Loading:
// The provider has completed login, the provider should now be signed in.
Assert.AreEqual(ProviderState.SignedIn, e.NewState);
// SignedIn should be the second event fired.
Assert.AreEqual(eventCount, 2);
break;
default:
// This is unexpected, something went wrong during the test.
Assert.Fail("The provider has transitioned from an unexpected state: " + Enum.GetName(typeof(ProviderState), e.OldState));
break;
}
};
// Initiate logout.
await provider.LoginAsync();
// Logout has completed, the provider should be signed out.
Assert.AreEqual(ProviderState.SignedIn, provider.State);
// Ensure the proper number of events were fired.
Assert.AreEqual(eventCount, 2);
}
/// <summary>
/// Create a new instance of the MockProvider and initiates logout.
/// The test checks that the appropriate events are fired and that the provider transitions
/// through the different states as expected.
/// </summary>
[TestCategory("Providers")]
[TestMethod]
public async Task Test_MockProvider_LogoutAsync()
{
// Create the new provider, pre-signed in.
IProvider provider = new MockProvider(true);
// The newly created provider should be in a logged in state.
Assert.AreEqual(ProviderState.SignedIn, provider.State);
// Listen for changes in the provider state and count them.
int eventCount = 0;
provider.StateChanged += (s, e) =>
{
eventCount += 1;
// Ensure that the states are properly reported through the StateChanged event.
switch (e.OldState)
{
case ProviderState.SignedIn:
// Logout has been initiated, the provider should now be loading.
Assert.AreEqual(ProviderState.Loading, e.NewState);
// Loading should be the first event fired.
Assert.AreEqual(eventCount, 1);
break;
case ProviderState.Loading:
// The provider has completed logout, the provider should now be signed out.
Assert.AreEqual(ProviderState.SignedOut, e.NewState);
// SignedOut should be the second event fired.
Assert.AreEqual(eventCount, 2);
break;
default:
// This is unexpected, something went wrong during the test.
Assert.Fail("The provider has transitioned from an unexpected state: " + Enum.GetName(typeof(ProviderState), e.OldState));
break;
}
};
// Initiate logout.
await provider.LogoutAsync();
// Logout has completed, the provider should be signed out.
Assert.AreEqual(ProviderState.SignedOut, provider.State);
// Ensure the proper number of events were fired.
Assert.AreEqual(eventCount, 2);
}
/// <summary>
/// Authenticate an empty request and detect that the approapriate headers have been added.
/// </summary>
[TestCategory("Providers")]
[TestMethod]
public async Task Test_MockProvider_AuthenticateRequestAsync()
{
// Create a new instance of the MockProvider.
IProvider provider = new MockProvider(true);
// Create an empty message to authenticate.
var message = new HttpRequestMessage();
// Use the provider to authenticate the message.
await provider.AuthenticateRequestAsync(message);
// Check for the absence of the SdkVersion header value on the empty message.
bool sdkVersionHeaderExists = message.Headers.TryGetValues("SdkVersion", out _);
Assert.IsFalse(sdkVersionHeaderExists, "SdkVersion header values should not exist on an empty request that does not originate from the SDK.");
// Check for the authorization header
Assert.IsNotNull(message.Headers.Authorization, "Authorization header was not found.");
Assert.AreEqual("Bearer", message.Headers.Authorization.Scheme);
Assert.AreEqual("{token:https://graph.microsoft.com/}", message.Headers.Authorization.Parameter);
}
}
}

Просмотреть файл

@ -0,0 +1,22 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace UnitTests.UWP
{
/// <summary>
/// A super basic dummy test to make sure the test harness is prepared properly and ready for more tests.
/// </summary>
[TestClass]
public class SmokeTest
{
[TestCategory("SmokeTest")]
[TestMethod]
public void TrueIsTrue()
{
Assert.IsTrue(true);
}
}
}

Просмотреть файл

@ -0,0 +1,7 @@
<Application
x:Class="UnitTests.UWP.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:UnitTests.UWP">
</Application>

Просмотреть файл

@ -0,0 +1,124 @@
using System;
using Windows.ApplicationModel;
using Windows.ApplicationModel.Activation;
using Windows.ApplicationModel.Core;
using Windows.System;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Navigation;
namespace UnitTests.UWP
{
/// <summary>
/// Provides application-specific behavior to supplement the default Application class.
/// </summary>
public partial class App : Application
{
// Holder for test content to abstract Window.Current.Content
public static FrameworkElement ContentRoot
{
get
{
var rootFrame = Window.Current.Content as Frame;
return rootFrame.Content as FrameworkElement;
}
set
{
var rootFrame = Window.Current.Content as Frame;
rootFrame.Content = value;
}
}
// Abstract CoreApplication.MainView.DispatcherQueue
public static DispatcherQueue DispatcherQueue
{
get
{
return CoreApplication.MainView.DispatcherQueue;
}
}
/// <summary>
/// Initializes a new instance of the <see cref="App"/> class.
/// Initializes the singleton application object. This is the first line of authored code
/// executed, and as such is the logical equivalent of main() or WinMain().
/// </summary>
public App()
{
InitializeComponent();
Suspending += OnSuspending;
}
/// <summary>
/// Invoked when the application is launched normally by the end user. Other entry points
/// will be used such as when the application is launched to open a specific file.
/// </summary>
/// <param name="e">Details about the launch request and process.</param>
protected override void OnLaunched(LaunchActivatedEventArgs e)
{
#if DEBUG
if (System.Diagnostics.Debugger.IsAttached)
{
DebugSettings.EnableFrameRateCounter = true;
}
#endif
Frame rootFrame = Window.Current.Content as Frame;
// Do not repeat app initialization when the Window already has content,
// just ensure that the window is active
if (rootFrame == null)
{
// Create a Frame to act as the navigation context and navigate to the first page
rootFrame = new Frame()
{
CacheSize = 0 // Prevent any test pages from being cached
};
rootFrame.NavigationFailed += OnNavigationFailed;
if (e.PreviousExecutionState == ApplicationExecutionState.Terminated)
{
// TODO: Load state from previously suspended application
}
// Place the frame in the current Window
Window.Current.Content = rootFrame;
}
Microsoft.VisualStudio.TestPlatform.TestExecutor.UnitTestClient.CreateDefaultUI();
// Ensure the current window is active
Window.Current.Activate();
Microsoft.VisualStudio.TestPlatform.TestExecutor.UnitTestClient.Run(e.Arguments);
}
/// <summary>
/// Invoked when Navigation to a certain page fails
/// </summary>
/// <param name="sender">The Frame which failed navigation</param>
/// <param name="e">Details about the navigation failure</param>
private void OnNavigationFailed(object sender, NavigationFailedEventArgs e)
{
throw new Exception("Failed to load Page " + e.SourcePageType.FullName);
}
/// <summary>
/// Invoked when application execution is being suspended. Application state is saved
/// without knowing whether the application will be terminated or resumed with the contents
/// of memory still intact.
/// </summary>
/// <param name="sender">The source of the suspend request.</param>
/// <param name="e">Details about the suspend request.</param>
private void OnSuspending(object sender, SuspendingEventArgs e)
{
var deferral = e.SuspendingOperation.GetDeferral();
// TODO: Save application state and stop any background activity
deferral.Complete();
}
}
}

Просмотреть файл

@ -0,0 +1,205 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
<ProjectGuid>{6B33B26C-008B-4ADB-B317-EF996CD6755B}</ProjectGuid>
<OutputType>AppContainerExe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>UnitTests.UWP</RootNamespace>
<AssemblyName>UnitTests.UWP</AssemblyName>
<DefaultLanguage>en-US</DefaultLanguage>
<TargetPlatformIdentifier>UAP</TargetPlatformIdentifier>
<TargetPlatformVersion>10.0.19041.0</TargetPlatformVersion>
<TargetPlatformMinVersion>10.0.17763.0</TargetPlatformMinVersion>
<MinimumVisualStudioVersion>14</MinimumVisualStudioVersion>
<FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{A5A43C5B-DE2A-4C0C-9213-0A381AF9435A};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<UnitTestPlatformVersion Condition="'$(UnitTestPlatformVersion)' == ''">$(VisualStudioVersion)</UnitTestPlatformVersion>
<AppxPackageSigningEnabled>false</AppxPackageSigningEnabled>
<LangVersion>9.0</LangVersion>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\x86\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE;NETFX_CORE;WINDOWS_UWP</DefineConstants>
<NoWarn>;2008</NoWarn>
<DebugType>full</DebugType>
<PlatformTarget>x86</PlatformTarget>
<UseVSHostingProcess>false</UseVSHostingProcess>
<ErrorReport>prompt</ErrorReport>
<Prefer32Bit>true</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'">
<OutputPath>bin\x86\Release\</OutputPath>
<DefineConstants>TRACE;NETFX_CORE;WINDOWS_UWP</DefineConstants>
<Optimize>true</Optimize>
<NoWarn>;2008</NoWarn>
<DebugType>pdbonly</DebugType>
<PlatformTarget>x86</PlatformTarget>
<UseVSHostingProcess>false</UseVSHostingProcess>
<ErrorReport>prompt</ErrorReport>
<Prefer32Bit>true</Prefer32Bit>
<UseDotNetNativeToolchain>true</UseDotNetNativeToolchain>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|ARM'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\ARM\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE;NETFX_CORE;WINDOWS_UWP</DefineConstants>
<NoWarn>;2008</NoWarn>
<DebugType>full</DebugType>
<PlatformTarget>ARM</PlatformTarget>
<UseVSHostingProcess>false</UseVSHostingProcess>
<ErrorReport>prompt</ErrorReport>
<Prefer32Bit>true</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|ARM'">
<OutputPath>bin\ARM\Release\</OutputPath>
<DefineConstants>TRACE;NETFX_CORE;WINDOWS_UWP</DefineConstants>
<Optimize>true</Optimize>
<NoWarn>;2008</NoWarn>
<DebugType>pdbonly</DebugType>
<PlatformTarget>ARM</PlatformTarget>
<UseVSHostingProcess>false</UseVSHostingProcess>
<ErrorReport>prompt</ErrorReport>
<Prefer32Bit>true</Prefer32Bit>
<UseDotNetNativeToolchain>true</UseDotNetNativeToolchain>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|ARM64'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\ARM64\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE;NETFX_CORE;WINDOWS_UWP</DefineConstants>
<NoWarn>;2008</NoWarn>
<DebugType>full</DebugType>
<PlatformTarget>ARM64</PlatformTarget>
<UseVSHostingProcess>false</UseVSHostingProcess>
<ErrorReport>prompt</ErrorReport>
<Prefer32Bit>true</Prefer32Bit>
<UseDotNetNativeToolchain>true</UseDotNetNativeToolchain>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|ARM64'">
<OutputPath>bin\ARM64\Release\</OutputPath>
<DefineConstants>TRACE;NETFX_CORE;WINDOWS_UWP</DefineConstants>
<Optimize>true</Optimize>
<NoWarn>;2008</NoWarn>
<DebugType>pdbonly</DebugType>
<PlatformTarget>ARM64</PlatformTarget>
<UseVSHostingProcess>false</UseVSHostingProcess>
<ErrorReport>prompt</ErrorReport>
<Prefer32Bit>true</Prefer32Bit>
<UseDotNetNativeToolchain>true</UseDotNetNativeToolchain>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\x64\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE;NETFX_CORE;WINDOWS_UWP</DefineConstants>
<NoWarn>;2008</NoWarn>
<DebugType>full</DebugType>
<PlatformTarget>x64</PlatformTarget>
<UseVSHostingProcess>false</UseVSHostingProcess>
<ErrorReport>prompt</ErrorReport>
<Prefer32Bit>true</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
<OutputPath>bin\x64\Release\</OutputPath>
<DefineConstants>TRACE;NETFX_CORE;WINDOWS_UWP</DefineConstants>
<Optimize>true</Optimize>
<NoWarn>;2008</NoWarn>
<DebugType>pdbonly</DebugType>
<PlatformTarget>x64</PlatformTarget>
<UseVSHostingProcess>false</UseVSHostingProcess>
<ErrorReport>prompt</ErrorReport>
<Prefer32Bit>true</Prefer32Bit>
<UseDotNetNativeToolchain>true</UseDotNetNativeToolchain>
</PropertyGroup>
<PropertyGroup>
<RestoreProjectStyle>PackageReference</RestoreProjectStyle>
</PropertyGroup>
<ItemGroup>
<SDKReference Include="TestPlatform.Universal, Version=$(UnitTestPlatformVersion)" />
</ItemGroup>
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Providers\Test_MockProvider.cs" />
<Compile Include="UnitTestApp.xaml.cs">
<DependentUpon>UnitTestApp.xaml</DependentUpon>
</Compile>
<Compile Include="SmokeTest.cs" />
<Compile Include="VisualUITestBase.cs" />
</ItemGroup>
<ItemGroup>
<ApplicationDefinition Include="UnitTestApp.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</ApplicationDefinition>
</ItemGroup>
<ItemGroup>
<AppxManifest Include="Package.appxmanifest">
<SubType>Designer</SubType>
</AppxManifest>
</ItemGroup>
<ItemGroup>
<Content Include="Properties\Default.rd.xml" />
<Content Include="Assets\LockScreenLogo.scale-200.png" />
<Content Include="Assets\SplashScreen.scale-200.png" />
<Content Include="Assets\Square150x150Logo.scale-200.png" />
<Content Include="Assets\Square44x44Logo.scale-200.png" />
<Content Include="Assets\Square44x44Logo.targetsize-24_altform-unplated.png" />
<Content Include="Assets\StoreLogo.png" />
<Content Include="Assets\Wide310x150Logo.scale-200.png" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyInjection">
<Version>3.1.5</Version>
</PackageReference>
<PackageReference Include="FluentAssertions">
<Version>5.10.3</Version>
</PackageReference>
<PackageReference Include="Microsoft.Graph.Core">
<Version>1.24.0</Version>
</PackageReference>
<PackageReference Include="Microsoft.NETCore.UniversalWindowsPlatform">
<Version>6.2.12</Version>
</PackageReference>
<PackageReference Include="Microsoft.Toolkit.Uwp">
<Version>7.0.0</Version>
</PackageReference>
<PackageReference Include="Microsoft.Toolkit.Uwp.UI">
<Version>7.0.0</Version>
</PackageReference>
<PackageReference Include="MSTest.TestAdapter">
<Version>2.1.2</Version>
</PackageReference>
<PackageReference Include="MSTest.TestFramework">
<Version>2.1.2</Version>
</PackageReference>
<PackageReference Include="Newtonsoft.Json">
<Version>10.0.3</Version>
<!-- DO NOT UPGRADE THIS PACKAGE FROM 10.0.3, this is used for upgrade testing between 6.1.1 and 7.0.0 for the Object Serializers -->
</PackageReference>
<PackageReference Include="System.Text.Json">
<Version>4.7.2</Version>
</PackageReference>
<PackageReference Include="System.Xml.XPath.XmlDocument">
<Version>4.3.0</Version>
</PackageReference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Microsoft.Toolkit.Graph\Microsoft.Toolkit.Graph.csproj">
<Project>{B2246169-0CD8-473C-AFF6-172310E2C3F6}</Project>
<Name>Microsoft.Toolkit.Graph</Name>
</ProjectReference>
</ItemGroup>
<PropertyGroup Condition=" '$(VisualStudioVersion)' == '' or '$(VisualStudioVersion)' &lt; '14.0' ">
<VisualStudioVersion>14.0</VisualStudioVersion>
</PropertyGroup>
<Import Project="$(MSBuildExtensionsPath)\Microsoft\WindowsXaml\v$(VisualStudioVersion)\Microsoft.Windows.UI.Xaml.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

Просмотреть файл

@ -0,0 +1,84 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using Microsoft.Toolkit.Uwp;
using Microsoft.Toolkit.Uwp.UI.Helpers;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Threading.Tasks;
using Windows.UI.Xaml;
namespace UnitTests.UWP
{
/// <summary>
/// Base class to be used in API tests which require UI layout or rendering to occur first.
/// For more E2E scenarios or testing components for user interation, see integration test suite instead.
/// Use this class when an API needs direct access to test functions of the UI itself in more simplistic scenarios (i.e. visual tree helpers).
/// </summary>
public class VisualUITestBase
{
/// <summary>
/// Sets the content of the test app to a simple <see cref="FrameworkElement"/> to load into the visual tree.
/// Waits for that element to be loaded and rendered before returning.
/// </summary>
/// <param name="content">Content to set in test app.</param>
/// <returns>When UI is loaded.</returns>
protected Task SetTestContentAsync(FrameworkElement content)
{
return App.DispatcherQueue.EnqueueAsync(() =>
{
var taskCompletionSource = new TaskCompletionSource<bool>();
async void Callback(object sender, RoutedEventArgs args)
{
content.Loaded -= Callback;
// Wait for first Render pass
await CompositionTargetHelper.ExecuteAfterCompositionRenderingAsync(() => { });
taskCompletionSource.SetResult(true);
}
// Going to wait for our original content to unload
content.Loaded += Callback;
// Trigger that now
try
{
App.ContentRoot = content;
}
catch (Exception e)
{
taskCompletionSource.SetException(e);
}
return taskCompletionSource.Task;
});
}
[TestCleanup]
public async Task Cleanup()
{
var taskCompletionSource = new TaskCompletionSource<bool>();
await App.DispatcherQueue.EnqueueAsync(() =>
{
// If we didn't set our content we don't have to do anything but complete here.
if (App.ContentRoot is null)
{
taskCompletionSource.SetResult(true);
return;
}
// Going to wait for our original content to unload
App.ContentRoot.Unloaded += (_, _) => taskCompletionSource.SetResult(true);
// Trigger that now
App.ContentRoot = null;
});
await taskCompletionSource.Task;
}
}
}

Просмотреть файл

@ -38,6 +38,10 @@ Project("{C7167F0D-BC9F-4E6E-AFE1-012C56B48DB5}") = "WPF-Packaged-App", "Samples
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Toolkit.Wpf.Graph.Providers", "Microsoft.Toolkit.Wpf.Graph.Providers\Microsoft.Toolkit.Wpf.Graph.Providers.csproj", "{8B9BFE42-F526-4961-A1FD-2D2B6AA0C305}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "UnitTests", "UnitTests", "{13F3F93C-1FB7-48D5-BB73-F5287A72217E}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UnitTests.UWP", "UnitTests\UnitTests.UWP\UnitTests.UWP.csproj", "{6B33B26C-008B-4ADB-B317-EF996CD6755B}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
CI|Any CPU = CI|Any CPU
@ -351,6 +355,62 @@ Global
{8B9BFE42-F526-4961-A1FD-2D2B6AA0C305}.Release|x64.Build.0 = Release|Any CPU
{8B9BFE42-F526-4961-A1FD-2D2B6AA0C305}.Release|x86.ActiveCfg = Release|Any CPU
{8B9BFE42-F526-4961-A1FD-2D2B6AA0C305}.Release|x86.Build.0 = Release|Any CPU
{6B33B26C-008B-4ADB-B317-EF996CD6755B}.CI|Any CPU.ActiveCfg = Debug|x86
{6B33B26C-008B-4ADB-B317-EF996CD6755B}.CI|Any CPU.Build.0 = Debug|x86
{6B33B26C-008B-4ADB-B317-EF996CD6755B}.CI|Any CPU.Deploy.0 = Debug|x86
{6B33B26C-008B-4ADB-B317-EF996CD6755B}.CI|ARM.ActiveCfg = Debug|ARM
{6B33B26C-008B-4ADB-B317-EF996CD6755B}.CI|ARM.Build.0 = Debug|ARM
{6B33B26C-008B-4ADB-B317-EF996CD6755B}.CI|ARM.Deploy.0 = Debug|ARM
{6B33B26C-008B-4ADB-B317-EF996CD6755B}.CI|ARM64.ActiveCfg = Debug|ARM64
{6B33B26C-008B-4ADB-B317-EF996CD6755B}.CI|ARM64.Build.0 = Debug|ARM64
{6B33B26C-008B-4ADB-B317-EF996CD6755B}.CI|ARM64.Deploy.0 = Debug|ARM64
{6B33B26C-008B-4ADB-B317-EF996CD6755B}.CI|x64.ActiveCfg = Debug|x64
{6B33B26C-008B-4ADB-B317-EF996CD6755B}.CI|x64.Build.0 = Debug|x64
{6B33B26C-008B-4ADB-B317-EF996CD6755B}.CI|x64.Deploy.0 = Debug|x64
{6B33B26C-008B-4ADB-B317-EF996CD6755B}.CI|x86.ActiveCfg = Debug|x86
{6B33B26C-008B-4ADB-B317-EF996CD6755B}.CI|x86.Build.0 = Debug|x86
{6B33B26C-008B-4ADB-B317-EF996CD6755B}.CI|x86.Deploy.0 = Debug|x86
{6B33B26C-008B-4ADB-B317-EF996CD6755B}.Debug|Any CPU.ActiveCfg = Debug|x86
{6B33B26C-008B-4ADB-B317-EF996CD6755B}.Debug|ARM.ActiveCfg = Debug|ARM
{6B33B26C-008B-4ADB-B317-EF996CD6755B}.Debug|ARM.Build.0 = Debug|ARM
{6B33B26C-008B-4ADB-B317-EF996CD6755B}.Debug|ARM.Deploy.0 = Debug|ARM
{6B33B26C-008B-4ADB-B317-EF996CD6755B}.Debug|ARM64.ActiveCfg = Debug|ARM64
{6B33B26C-008B-4ADB-B317-EF996CD6755B}.Debug|ARM64.Build.0 = Debug|ARM64
{6B33B26C-008B-4ADB-B317-EF996CD6755B}.Debug|ARM64.Deploy.0 = Debug|ARM64
{6B33B26C-008B-4ADB-B317-EF996CD6755B}.Debug|x64.ActiveCfg = Debug|x64
{6B33B26C-008B-4ADB-B317-EF996CD6755B}.Debug|x64.Build.0 = Debug|x64
{6B33B26C-008B-4ADB-B317-EF996CD6755B}.Debug|x64.Deploy.0 = Debug|x64
{6B33B26C-008B-4ADB-B317-EF996CD6755B}.Debug|x86.ActiveCfg = Debug|x86
{6B33B26C-008B-4ADB-B317-EF996CD6755B}.Debug|x86.Build.0 = Debug|x86
{6B33B26C-008B-4ADB-B317-EF996CD6755B}.Debug|x86.Deploy.0 = Debug|x86
{6B33B26C-008B-4ADB-B317-EF996CD6755B}.Native|Any CPU.ActiveCfg = Debug|x86
{6B33B26C-008B-4ADB-B317-EF996CD6755B}.Native|Any CPU.Build.0 = Debug|x86
{6B33B26C-008B-4ADB-B317-EF996CD6755B}.Native|Any CPU.Deploy.0 = Debug|x86
{6B33B26C-008B-4ADB-B317-EF996CD6755B}.Native|ARM.ActiveCfg = Debug|ARM
{6B33B26C-008B-4ADB-B317-EF996CD6755B}.Native|ARM.Build.0 = Debug|ARM
{6B33B26C-008B-4ADB-B317-EF996CD6755B}.Native|ARM.Deploy.0 = Debug|ARM
{6B33B26C-008B-4ADB-B317-EF996CD6755B}.Native|ARM64.ActiveCfg = Debug|ARM64
{6B33B26C-008B-4ADB-B317-EF996CD6755B}.Native|ARM64.Build.0 = Debug|ARM64
{6B33B26C-008B-4ADB-B317-EF996CD6755B}.Native|ARM64.Deploy.0 = Debug|ARM64
{6B33B26C-008B-4ADB-B317-EF996CD6755B}.Native|x64.ActiveCfg = Debug|x64
{6B33B26C-008B-4ADB-B317-EF996CD6755B}.Native|x64.Build.0 = Debug|x64
{6B33B26C-008B-4ADB-B317-EF996CD6755B}.Native|x64.Deploy.0 = Debug|x64
{6B33B26C-008B-4ADB-B317-EF996CD6755B}.Native|x86.ActiveCfg = Debug|x86
{6B33B26C-008B-4ADB-B317-EF996CD6755B}.Native|x86.Build.0 = Debug|x86
{6B33B26C-008B-4ADB-B317-EF996CD6755B}.Native|x86.Deploy.0 = Debug|x86
{6B33B26C-008B-4ADB-B317-EF996CD6755B}.Release|Any CPU.ActiveCfg = Release|x86
{6B33B26C-008B-4ADB-B317-EF996CD6755B}.Release|ARM.ActiveCfg = Release|ARM
{6B33B26C-008B-4ADB-B317-EF996CD6755B}.Release|ARM.Build.0 = Release|ARM
{6B33B26C-008B-4ADB-B317-EF996CD6755B}.Release|ARM.Deploy.0 = Release|ARM
{6B33B26C-008B-4ADB-B317-EF996CD6755B}.Release|ARM64.ActiveCfg = Release|ARM64
{6B33B26C-008B-4ADB-B317-EF996CD6755B}.Release|ARM64.Build.0 = Release|ARM64
{6B33B26C-008B-4ADB-B317-EF996CD6755B}.Release|ARM64.Deploy.0 = Release|ARM64
{6B33B26C-008B-4ADB-B317-EF996CD6755B}.Release|x64.ActiveCfg = Release|x64
{6B33B26C-008B-4ADB-B317-EF996CD6755B}.Release|x64.Build.0 = Release|x64
{6B33B26C-008B-4ADB-B317-EF996CD6755B}.Release|x64.Deploy.0 = Release|x64
{6B33B26C-008B-4ADB-B317-EF996CD6755B}.Release|x86.ActiveCfg = Release|x86
{6B33B26C-008B-4ADB-B317-EF996CD6755B}.Release|x86.Build.0 = Release|x86
{6B33B26C-008B-4ADB-B317-EF996CD6755B}.Release|x86.Deploy.0 = Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@ -360,6 +420,7 @@ Global
{053BC0AF-FF48-45EC-B201-D80546A46587} = {DC168678-D7E0-4383-B05B-9953CEBE0257}
{B766A515-51F8-478E-B1B2-93794864C66A} = {DC168678-D7E0-4383-B05B-9953CEBE0257}
{FE713229-AEE5-489A-9251-C346A82C1AC3} = {DC168678-D7E0-4383-B05B-9953CEBE0257}
{6B33B26C-008B-4ADB-B317-EF996CD6755B} = {13F3F93C-1FB7-48D5-BB73-F5287A72217E}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {20641689-5BDE-4F6F-8889-CCDD2CC2685E}