Skip to content

Commit

Permalink
Improve the code a bit more
Browse files Browse the repository at this point in the history
  • Loading branch information
mattleibow committed Jul 3, 2023
1 parent 191e1bb commit 944ce83
Show file tree
Hide file tree
Showing 24 changed files with 123 additions and 93 deletions.
4 changes: 2 additions & 2 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ root = true
indent_style = space

# Xml files
[*.{xml,csproj}]
[*.{xml,csproj,targets,props}]
indent_size = 2
tab_width = 2

Expand All @@ -19,7 +19,7 @@ indent_size = 4
tab_width = 4

# New line preferences
end_of_line = crlf
end_of_line = lf
insert_final_newline = true

#### .NET Coding Conventions ####
Expand Down
13 changes: 10 additions & 3 deletions Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
<Project>
<PropertyGroup>
<MauiVersion>7.0.92</MauiVersion>
</PropertyGroup>

<PropertyGroup>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<PropertyGroup>
<MauiVersion>7.0.92</MauiVersion>
</PropertyGroup>

</Project>
19 changes: 8 additions & 11 deletions Directory.Build.targets
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
<Project>
<PropertyGroup>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'ios'">14.2</SupportedOSPlatformVersion>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'maccatalyst'">14.0</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>
<PropertyGroup>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'ios'">14.2</SupportedOSPlatformVersion>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'maccatalyst'">14.0</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>
</Project>
8 changes: 3 additions & 5 deletions sample/SampleMauiApp/SampleMauiApp.csproj
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net7.0-android;net7.0-ios;net7.0-maccatalyst;net7.0-tizen</TargetFrameworks>
<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">$(TargetFrameworks);net7.0-windows10.0.19041.0</TargetFrameworks>
<TargetFrameworks>net7.0-maccatalyst</TargetFrameworks>
<!-- <TargetFrameworks>net7.0-android;net7.0-ios;net7.0-maccatalyst</TargetFrameworks> -->
<!-- <TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">$(TargetFrameworks);net7.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);net7.0-tizen</TargetFrameworks> -->
<OutputType>Exe</OutputType>
<RootNamespace>SampleMauiApp</RootNamespace>
<UseMaui>true</UseMaui>
<SingleProject>true</SingleProject>
<ImplicitUsings>enable</ImplicitUsings>
<IsPackable>false</IsPackable>

<!-- Display name -->
<ApplicationTitle>SampleMauiApp</ApplicationTitle>
Expand Down
5 changes: 3 additions & 2 deletions sample/SampleMauiApp/Tests/UITests/DynamicUITests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Collections;

using Microsoft.Maui.Handlers;
using Microsoft.Maui.Platform;
using System.Collections;

namespace SampleMauiApp;

Expand All @@ -15,7 +16,7 @@ public async Task ButtonIsPositionedCorrectlyInLayouts()
{
Background = Brush.White,
Children =
{
{
new Grid
{
WidthRequest = 50,
Expand Down
3 changes: 0 additions & 3 deletions sample/TestProject/TestProject.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
<TargetFrameworks>net7.0</TargetFrameworks>
<UseMaui>true</UseMaui>
<SingleProject>true</SingleProject>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>true</IsPackable>
</PropertyGroup>

<ItemGroup>
Expand Down
1 change: 1 addition & 0 deletions src/Xunit.Runner.Devices.Maui/AppHostBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public static MauiAppBuilder ConfigureRunner(this MauiAppBuilder appHostBuilder,
// register runner components
appHostBuilder.Services.AddSingleton(options);
appHostBuilder.Services.AddSingleton<ITestRunner, DeviceRunner>();
appHostBuilder.Services.AddSingleton<IDiagnosticsManager, DiagnosticsManager>();

// only register the "root" view models and the others are created by the ITestRunner
appHostBuilder.Services.AddSingleton<HomeViewModel>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class RunStatusToColorConverter : IValueConverter

return status switch
{
RunStatus.Ok => Application.Current.Resources["SuccessfulTestsColor"],
RunStatus.Passed => Application.Current.Resources["SuccessfulTestsColor"],
RunStatus.Failed => Application.Current.Resources["FailedTestsColor"],
RunStatus.NoTests => Application.Current.Resources["NoTestsColor"],
RunStatus.NotRun => Application.Current.Resources["NotRunTestsColor"],
Expand Down
1 change: 0 additions & 1 deletion src/Xunit.Runner.Devices.Maui/Pages/HomePage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ public HomePage(HomeViewModel homeViewModel)
ViewModel = homeViewModel;
}


public HomeViewModel? ViewModel
{
get => BindingContext as HomeViewModel;
Expand Down
4 changes: 2 additions & 2 deletions src/Xunit.Runner.Devices.Maui/TestRunnerAppShell.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@
<ShellContent
Title="Diagnostics"
ContentTemplate="{DataTemplate pages:DiagnosticsPage}"
Route="testrunner/diagnostics" />
Route="diagnostics" />

<ShellContent
Title="Credits"
ContentTemplate="{DataTemplate pages:CreditsPage}"
Route="testrunner/credits" />
Route="credits" />

</Shell>
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
<TargetFrameworks>net7.0</TargetFrameworks>
<UseMaui>true</UseMaui>
<SingleProject>true</SingleProject>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>true</IsPackable>
</PropertyGroup>

<ItemGroup>
Expand Down
11 changes: 6 additions & 5 deletions src/Xunit.Runner.Devices/DeviceRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,16 @@ public class DeviceRunner : ITestListener, ITestRunner
{
readonly SynchronizationContext context = SynchronizationContext.Current;
readonly AsyncLock executionLock = new();
readonly IDiagnosticsManager _diagnosticsManager;
readonly TestRunLogger _logger;
volatile bool cancelled;

public DeviceRunner(RunnerOptions options, ILogger<DeviceRunner> logger)
public DeviceRunner(RunnerOptions options, IDiagnosticsManager diagnosticsManager, ILogger<DeviceRunner> logger)
{
TestAssemblies = options.Assemblies;
_logger = new TestRunLogger(logger);
_diagnosticsManager = diagnosticsManager;

TestAssemblies = options.Assemblies;
}

public IReadOnlyCollection<Assembly> TestAssemblies { get; }
Expand Down Expand Up @@ -64,8 +67,6 @@ public async Task RunAsync(IReadOnlyList<AssemblyRunInfo> runInfos, string? mess
}
}

public event EventHandler<string>? DiagnosticMessageRecieved;

public Task<IReadOnlyList<TestAssemblyViewModel>> DiscoverAsync()
{
var tcs = new TaskCompletionSource<IReadOnlyList<TestAssemblyViewModel>>();
Expand Down Expand Up @@ -217,7 +218,7 @@ void RunTestsInAssembly(List<IDisposable> toDispose, AssemblyRunInfo runInfo)

var executionOptions = TestFrameworkOptions.ForExecution(runInfo.Configuration);

var diagSink = new DiagnosticMessageSink(d => context.Post(_ => DiagnosticMessageRecieved?.Invoke(this, d), null), runInfo.AssemblyFileName, executionOptions.GetDiagnosticMessagesOrDefault());
var diagSink = new DiagnosticMessageSink(d => context.Post(_ => _diagnosticsManager.PostDiagnosticMessage(d), null), runInfo.AssemblyFileName, executionOptions.GetDiagnosticMessagesOrDefault());

var deviceExecSink = new DeviceExecutionSink(xunitTestCases, this, context);

Expand Down
11 changes: 11 additions & 0 deletions src/Xunit.Runner.Devices/DiagnosticsManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace Xunit.Runner.Devices;

public class DiagnosticsManager : IDiagnosticsManager
{
public event EventHandler<string>? DiagnosticMessageRecieved;

public void PostDiagnosticMessage(string message)
{
DiagnosticMessageRecieved?.Invoke(this, message);
}
}
8 changes: 8 additions & 0 deletions src/Xunit.Runner.Devices/IDiagnosticsManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace Xunit.Runner.Devices;

public interface IDiagnosticsManager
{
void PostDiagnosticMessage(string message);

event EventHandler<string>? DiagnosticMessageRecieved;
}
2 changes: 0 additions & 2 deletions src/Xunit.Runner.Devices/ITestRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,4 @@ public interface ITestRunner
Task RunAsync(IEnumerable<TestCaseViewModel> tests, string? message = null);

Task RunAsync(IReadOnlyList<AssemblyRunInfo> runInfos, string? message = null);

event EventHandler<string> DiagnosticMessageRecieved;
}
6 changes: 3 additions & 3 deletions src/Xunit.Runner.Devices/Utils/FileSystemUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,16 @@ internal class FileSystemUtils
root = Path.Combine(root, "Contents", "Resources");
#endif
var file = Path.Combine(root, filename);
#endif

#if WINDOWS
#elif WINDOWS
// Windows: has 2 modes, packaged uses the Package API
if (IsPackagedApp.Value)
return Package.Current.InstalledLocation.OpenStreamForReadAsync(filename).Result;

// unpackaged is next to the executable
var root = AppContext.BaseDirectory;
var file = Path.Combine(root, filename);
#else
var file = filename;
#endif

// if the file exists, then open it
Expand Down
4 changes: 2 additions & 2 deletions src/Xunit.Runner.Devices/Utils/FilteredCollectionView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ protected virtual void OnItemChanged(T sender, PropertyChangedEventArgs args)
itemChanged?.Invoke(sender, args);
}

void DataSource_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
void DataSource_CollectionChanged(object? sender, NotifyCollectionChangedEventArgs e)
{
switch (e.Action)
{
Expand Down Expand Up @@ -230,7 +230,7 @@ void DataSource_CollectionChanged(object sender, NotifyCollectionChangedEventArg
}
}

void DataSource_ItemChanged(object sender, PropertyChangedEventArgs e)
void DataSource_ItemChanged(object? sender, PropertyChangedEventArgs e)
{
var item = (T)sender;
var index = filteredList.IndexOf(item);
Expand Down
19 changes: 7 additions & 12 deletions src/Xunit.Runner.Devices/ViewModels/DiagnosticsViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@ namespace Xunit.Runner.Devices;

public class DiagnosticsViewModel : AbstractBaseViewModel
{
readonly ITestRunner _runner;
readonly IDiagnosticsManager _diagnosticsManager;

string _messagesString = "";

public DiagnosticsViewModel(ITestRunner runner)
public DiagnosticsViewModel(IDiagnosticsManager diagnosticsManager)
{
_runner = runner;
_runner.DiagnosticMessageRecieved += OnDiagnosticMessageRecieved;
_diagnosticsManager = diagnosticsManager;
_diagnosticsManager.DiagnosticMessageRecieved += OnDiagnosticMessageRecieved;

Messages.CollectionChanged += OnDiagnosticMessagesCollectionChanged;

ClearMessagesCommand = new Command(Clear);
ClearMessagesCommand = new Command(ClearExecute);
}

public ICommand ClearMessagesCommand { get; }
Expand All @@ -30,19 +30,14 @@ public string MessagesString
private set => Set(ref _messagesString, value);
}

public void PostDiagnosticMessage(string message)
{
Messages.Add(message);
}

public void Clear()
void ClearExecute()
{
Messages.Clear();
}

void OnDiagnosticMessageRecieved(object? sender, string message)
{
PostDiagnosticMessage(message);
Messages.Add(message);
}

void OnDiagnosticMessagesCollectionChanged(object? sender, NotifyCollectionChangedEventArgs e)
Expand Down
Loading

0 comments on commit 944ce83

Please sign in to comment.