Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding more comprehensive tests #28

Open
wants to merge 22 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Added some libraries
  • Loading branch information
mattleibow committed Mar 15, 2024
commit ce6468bba767278bcb429bd421d7c5e127c2b75a
14 changes: 14 additions & 0 deletions DeviceRunners.sln
Original file line number Diff line number Diff line change
@@ -43,6 +43,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DeviceRunners.UITesting.Mau
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DeviceTestingKitApp", "sample\DeviceTestingKitApp\DeviceTestingKitApp.csproj", "{D9094DA2-3D7F-4613-9569-CCF71629AA1D}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DeviceTestingKitApp.MauiLibrary", "sample\DeviceTestingKitApp.MauiLibrary\DeviceTestingKitApp.MauiLibrary.csproj", "{DBAB5271-347E-4C0E-B326-045723583A07}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DeviceTestingKitApp.Library", "sample\DeviceTestingKitApp.Library\DeviceTestingKitApp.Library.csproj", "{D4350725-949D-4F7B-ABED-E4F493952D14}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -121,6 +125,14 @@ Global
{D9094DA2-3D7F-4613-9569-CCF71629AA1D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D9094DA2-3D7F-4613-9569-CCF71629AA1D}.Release|Any CPU.Build.0 = Release|Any CPU
{D9094DA2-3D7F-4613-9569-CCF71629AA1D}.Release|Any CPU.Deploy.0 = Release|Any CPU
{DBAB5271-347E-4C0E-B326-045723583A07}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{DBAB5271-347E-4C0E-B326-045723583A07}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DBAB5271-347E-4C0E-B326-045723583A07}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DBAB5271-347E-4C0E-B326-045723583A07}.Release|Any CPU.Build.0 = Release|Any CPU
{D4350725-949D-4F7B-ABED-E4F493952D14}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D4350725-949D-4F7B-ABED-E4F493952D14}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D4350725-949D-4F7B-ABED-E4F493952D14}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D4350725-949D-4F7B-ABED-E4F493952D14}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@@ -143,6 +155,8 @@ Global
{7040FAB6-5FD1-4D37-9DEB-1529802E2D34} = {DBF1C119-C96C-4DD3-810B-52451603475C}
{1D67F157-3201-49D4-AA58-40716D7D00EC} = {DBF1C119-C96C-4DD3-810B-52451603475C}
{D9094DA2-3D7F-4613-9569-CCF71629AA1D} = {46348E44-C1A8-4923-B3E9-7B9217BA5792}
{DBAB5271-347E-4C0E-B326-045723583A07} = {46348E44-C1A8-4923-B3E9-7B9217BA5792}
{D4350725-949D-4F7B-ABED-E4F493952D14} = {46348E44-C1A8-4923-B3E9-7B9217BA5792}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {2DABD41C-B083-429E-AE1E-971CFF8DC199}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<RootNamespace>DeviceTestingKitApp</RootNamespace>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.2.2" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace DeviceTestingKitApp.Features;

public interface ISemanticAnnouncer
{
void Announce(string message);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
using CommunityToolkit.Mvvm.ComponentModel;

namespace DeviceTestingKitApp.ViewModels;

public class BaseViewModel : ObservableObject
{
}
16 changes: 16 additions & 0 deletions sample/DeviceTestingKitApp.Library/ViewModels/CounterViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;

namespace DeviceTestingKitApp.ViewModels;

public partial class CounterViewModel : BaseViewModel
{
[ObservableProperty]
private int _count;

[RelayCommand]
private void Increment()
{
Count++;
}
}
20 changes: 20 additions & 0 deletions sample/DeviceTestingKitApp.MauiLibrary/Controls/CounterView.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8" ?>
<ContentView xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:viewmodels="clr-namespace:DeviceTestingKitApp.ViewModels;assembly=DeviceTestingKitApp.Library"
xmlns:converters="clr-namespace:DeviceTestingKitApp.Converters"
x:Class="DeviceTestingKitApp.Controls.CounterView"
x:DataType="viewmodels:CounterViewModel">

<ContentView.Resources>
<ResourceDictionary>
<converters:CounterValueConverter x:Key="CounterValue" />
</ResourceDictionary>
</ContentView.Resources>

<Button
Text="{Binding Count, Converter={StaticResource CounterValue}}"
Command="{Binding IncrementCommand}"
SemanticProperties.Hint="Counts the number of times you click" />

</ContentView>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace DeviceTestingKitApp.Controls;

public partial class CounterView : ContentView
{
public CounterView()
{
InitializeComponent();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System.Globalization;

namespace DeviceTestingKitApp.Converters;

public class CounterValueConverter : IValueConverter
{
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
{
if (value is not int count)
throw new NotSupportedException();

return count switch
{
0 => "Click me!",
1 => $"Clicked {count} time",
_ => $"Clicked {count} times"
};
}

public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture) =>
throw new NotSupportedException();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net8.0-android;net8.0-ios;net8.0-maccatalyst</TargetFrameworks>
<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">$(TargetFrameworks);net8.0-windows10.0.19041.0</TargetFrameworks>
<!-- Uncomment to also build the tizen app. You will need to install tizen by following this: https://github.com/Samsung/Tizen.NET -->
<!-- <TargetFrameworks>$(TargetFrameworks);net8.0-tizen</TargetFrameworks> -->
<UseMaui>true</UseMaui>
<SingleProject>true</SingleProject>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<RootNamespace>DeviceTestingKitApp</RootNamespace>

<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'ios'">11.0</SupportedOSPlatformVersion>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'maccatalyst'">13.1</SupportedOSPlatformVersion>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'android'">21.0</SupportedOSPlatformVersion>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.17763.0</SupportedOSPlatformVersion>
<TargetPlatformMinVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.17763.0</TargetPlatformMinVersion>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'tizen'">6.5</SupportedOSPlatformVersion>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Maui.Controls" Version="$(MauiVersion)" />
<PackageReference Include="Microsoft.Maui.Controls.Compatibility" Version="$(MauiVersion)" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\DeviceTestingKitApp.Library\DeviceTestingKitApp.Library.csproj" />
</ItemGroup>

<ItemGroup>
<MauiXaml Update="Controls\CounterView.xaml">
<Generator>MSBuild:Compile</Generator>
</MauiXaml>
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
namespace DeviceTestingKitApp.Features;

public class MauiSemanticAnnouncer : ISemanticAnnouncer
{
private readonly ISemanticScreenReader _platformScreenReader;

public MauiSemanticAnnouncer(ISemanticScreenReader platformScreenReader)
{
_platformScreenReader = platformScreenReader;
}

public void Announce(string message)
{
_platformScreenReader.Announce(message);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace DeviceTestingKitApp.MauiLibrary
{
// All the code in this file is only included on Android.
public class PlatformClass1
{
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace DeviceTestingKitApp.MauiLibrary
{
// All the code in this file is only included on Mac Catalyst.
public class PlatformClass1
{
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using System;

namespace DeviceTestingKitApp.MauiLibrary
{
// All the code in this file is only included on Tizen.
public class PlatformClass1
{
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace DeviceTestingKitApp.MauiLibrary
{
// All the code in this file is only included on Windows.
public class PlatformClass1
{
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace DeviceTestingKitApp.MauiLibrary
{
// All the code in this file is only included on iOS.
public class PlatformClass1
{
}
}
5 changes: 5 additions & 0 deletions sample/DeviceTestingKitApp/DeviceTestingKitApp.csproj
Original file line number Diff line number Diff line change
@@ -62,4 +62,9 @@
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="8.0.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\DeviceTestingKitApp.Library\DeviceTestingKitApp.Library.csproj" />
<ProjectReference Include="..\DeviceTestingKitApp.MauiLibrary\DeviceTestingKitApp.MauiLibrary.csproj" />
</ItemGroup>

</Project>
16 changes: 9 additions & 7 deletions sample/DeviceTestingKitApp/MainPage.xaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="DeviceTestingKitApp.MainPage">
xmlns:mauilib="clr-namespace:DeviceTestingKitApp.Controls;assembly=DeviceTestingKitApp.MauiLibrary"
xmlns:local="clr-namespace:DeviceTestingKitApp"
x:Class="DeviceTestingKitApp.MainPage"
x:DataType="local:MainPage">

<ScrollView>
<VerticalStackLayout
Padding="30,0"
Spacing="25">

<Image
Source="dotnet_bot.png"
HeightRequest="185"
@@ -24,12 +28,10 @@
SemanticProperties.HeadingLevel="Level2"
SemanticProperties.Description="Welcome to dot net Multi platform App U I" />

<Button
x:Name="CounterBtn"
Text="Click me"
SemanticProperties.Hint="Counts the number of times you click"
Clicked="OnCounterClicked"
HorizontalOptions="Fill" />
<mauilib:CounterView
HorizontalOptions="Fill"
BindingContext="{Binding Counter}" />

</VerticalStackLayout>
</ScrollView>

25 changes: 9 additions & 16 deletions sample/DeviceTestingKitApp/MainPage.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,24 +1,17 @@
namespace DeviceTestingKitApp;
using DeviceTestingKitApp.ViewModels;

namespace DeviceTestingKitApp;

public partial class MainPage : ContentPage
{
int count = 0;

public MainPage()
public MainPage(CounterViewModel counterViewModel)
{
InitializeComponent();
}
Counter = counterViewModel;

private void OnCounterClicked(object sender, EventArgs e)
{
count++;

if (count == 1)
CounterBtn.Text = $"Clicked {count} time";
else
CounterBtn.Text = $"Clicked {count} times";
InitializeComponent();

SemanticScreenReader.Announce(CounterBtn.Text);
BindingContext = this;
}
}

public CounterViewModel Counter { get; }
}
15 changes: 14 additions & 1 deletion sample/DeviceTestingKitApp/MauiProgram.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
using Microsoft.Extensions.Logging;
using DeviceTestingKitApp.Features;
using DeviceTestingKitApp.ViewModels;

using Microsoft.Extensions.Logging;

namespace DeviceTestingKitApp;

@@ -19,6 +22,16 @@ public static MauiApp CreateMauiApp()
builder.Logging.AddDebug();
#endif

// app pages
builder.Services.AddTransient<MainPage>();

// maui class library
builder.Services.AddTransient<ISemanticAnnouncer, MauiSemanticAnnouncer>();
builder.Services.AddTransient<ISemanticScreenReader>(_ => SemanticScreenReader.Default);

// plain class library
builder.Services.AddTransient<CounterViewModel>();

return builder.Build();
}
}