Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added UnitTests/UnitTests.UWP/Assets/StoreLogo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
46 changes: 46 additions & 0 deletions UnitTests/UnitTests.UWP/Package.appxmanifest
Original file line number Diff line number Diff line change
@@ -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>
21 changes: 21 additions & 0 deletions UnitTests/UnitTests.UWP/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -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)]
29 changes: 29 additions & 0 deletions UnitTests/UnitTests.UWP/Properties/Default.rd.xml
Original file line number Diff line number Diff line change
@@ -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>
168 changes: 168 additions & 0 deletions UnitTests/UnitTests.UWP/Providers/Test_MockProvider.cs
Original file line number Diff line number Diff line change
@@ -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 CommunityToolkit.Net.Authentication;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Net.Http;
using System.Threading.Tasks;

namespace UnitTests.UWP.Authentication
{
[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(HttpMethod.Get, new Uri("https://graph.microsoft.com/v1/me"));

// 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);
}
}
}
22 changes: 22 additions & 0 deletions UnitTests/UnitTests.UWP/SmokeTest.cs
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
7 changes: 7 additions & 0 deletions UnitTests/UnitTests.UWP/UnitTestApp.xaml
Original file line number Diff line number Diff line change
@@ -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>
Loading