Skip to content

Commit 9382723

Browse files
committed
👾 Update to .NET 5 and add unit tests
1 parent 56dbf6b commit 9382723

10 files changed

+114
-34
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
using System;
2+
using Xunit;
3+
4+
namespace YoutubeDl.Wpf.Tests
5+
{
6+
public class OutputParsingTests
7+
{
8+
}
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net5.0</TargetFramework>
5+
6+
<IsPackable>false</IsPackable>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.8.3" />
11+
<PackageReference Include="xunit" Version="2.4.1" />
12+
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
13+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
14+
<PrivateAssets>all</PrivateAssets>
15+
</PackageReference>
16+
<PackageReference Include="coverlet.collector" Version="1.3.0">
17+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
18+
<PrivateAssets>all</PrivateAssets>
19+
</PackageReference>
20+
</ItemGroup>
21+
22+
</Project>

‎YoutubeDl.Wpf/FodyWeavers.xml

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<Weavers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FodyWeavers.xsd">
2+
<ReactiveUI />
3+
</Weavers>

‎YoutubeDl.Wpf/FodyWeavers.xsd

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
3+
<!-- This file was generated by Fody. Manual changes to this file will be lost when your project is rebuilt. -->
4+
<xs:element name="Weavers">
5+
<xs:complexType>
6+
<xs:all>
7+
<xs:element name="ReactiveUI" minOccurs="0" maxOccurs="1" type="xs:anyType" />
8+
</xs:all>
9+
<xs:attribute name="VerifyAssembly" type="xs:boolean">
10+
<xs:annotation>
11+
<xs:documentation>'true' to run assembly verification (PEVerify) on the target assembly after all weavers have been executed.</xs:documentation>
12+
</xs:annotation>
13+
</xs:attribute>
14+
<xs:attribute name="VerifyIgnoreCodes" type="xs:string">
15+
<xs:annotation>
16+
<xs:documentation>A comma-separated list of error codes that can be safely ignored in assembly verification.</xs:documentation>
17+
</xs:annotation>
18+
</xs:attribute>
19+
<xs:attribute name="GenerateXsd" type="xs:boolean">
20+
<xs:annotation>
21+
<xs:documentation>'false' to turn off automatic generation of the XML Schema file.</xs:documentation>
22+
</xs:annotation>
23+
</xs:attribute>
24+
</xs:complexType>
25+
</xs:element>
26+
</xs:schema>

‎YoutubeDl.Wpf/ViewModels/DelegateCommand.cs

+6-6
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,24 @@ namespace YoutubeDl.Wpf.ViewModels
55
{
66
public class DelegateCommand : ICommand
77
{
8-
private readonly Action<object> _executeAction;
9-
private readonly Func<object, bool> _canExecuteAction;
8+
private readonly Action<object?> _executeAction;
9+
private readonly Func<object?, bool> _canExecuteAction;
1010

11-
public DelegateCommand(Action<object> executeAction)
11+
public DelegateCommand(Action<object?> executeAction)
1212
{
1313
_executeAction = executeAction;
1414
_canExecuteAction = x => true;
1515
}
1616

17-
public DelegateCommand(Action<object> executeAction, Func<object, bool> canExecuteAction)
17+
public DelegateCommand(Action<object?> executeAction, Func<object?, bool> canExecuteAction)
1818
{
1919
_executeAction = executeAction;
2020
_canExecuteAction = canExecuteAction;
2121
}
2222

23-
public void Execute(object parameter) => _executeAction(parameter);
23+
public void Execute(object? parameter) => _executeAction(parameter);
2424

25-
public bool CanExecute(object parameter) => _canExecuteAction?.Invoke(parameter) ?? true;
25+
public bool CanExecute(object? parameter) => _canExecuteAction?.Invoke(parameter) ?? true;
2626

2727
public event EventHandler? CanExecuteChanged;
2828

‎YoutubeDl.Wpf/ViewModels/HomeViewModel.cs

+18-12
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public HomeViewModel(ISnackbarMessageQueue snackbarMessageQueue)
5454
_openFolder = new DelegateCommand(OnOpenFolder, CanOpenFolder);
5555
_startDownload = new DelegateCommand(OnStartDownload, CanStartDownload);
5656
_listFormats = new DelegateCommand(OnListFormats, CanStartDownload);
57-
_abortDl = new DelegateCommand(OnAbortDl, (object commandParameter) => _freezeButton);
57+
_abortDl = new DelegateCommand(OnAbortDl, (object? commandParameter) => _freezeButton);
5858

5959
ContainerList = new ObservableCollection<string>()
6060
{
@@ -232,8 +232,14 @@ private void DlProcess_Exited(object? sender, EventArgs e)
232232
Application.Current.Dispatcher.Invoke(UpdateButtons);
233233
}
234234

235-
private void OnBrowseFolder(object commandParameter)
235+
private void OnBrowseFolder(object? commandParameter)
236236
{
237+
if (commandParameter == null)
238+
throw new ArgumentNullException(nameof(commandParameter));
239+
240+
if (commandParameter is not string parameter)
241+
throw new ArgumentException("Command parameter is not a string.", nameof(commandParameter));
242+
237243
Microsoft.Win32.OpenFileDialog folderDialog = new Microsoft.Win32.OpenFileDialog
238244
{
239245
FileName = "Folder Selection.",
@@ -242,19 +248,19 @@ private void OnBrowseFolder(object commandParameter)
242248
CheckPathExists = true
243249
};
244250

245-
if ((string)commandParameter == "DownloadPath")
251+
if (parameter == "DownloadPath")
246252
folderDialog.InitialDirectory = DownloadPath;
247253

248254
bool? result = folderDialog.ShowDialog();
249255

250256
if (result == true)
251257
{
252-
if ((string)commandParameter == "DownloadPath")
258+
if (parameter == "DownloadPath")
253259
DownloadPath = Path.GetDirectoryName(folderDialog.FileName) ?? "";
254260
}
255261
}
256262

257-
private void OnOpenFolder(object commandParameter)
263+
private void OnOpenFolder(object? commandParameter)
258264
{
259265
try
260266
{
@@ -266,7 +272,7 @@ private void OnOpenFolder(object commandParameter)
266272
}
267273
}
268274

269-
private void OnStartDownload(object commandParameter)
275+
private void OnStartDownload(object? commandParameter)
270276
{
271277
FreezeButton = true;
272278
DownloadButtonProgressIndeterminate = true;
@@ -344,7 +350,7 @@ private void OnStartDownload(object commandParameter)
344350
}
345351
}
346352

347-
private void OnListFormats(object commandParameter)
353+
private void OnListFormats(object? commandParameter)
348354
{
349355
FreezeButton = true;
350356
FormatsButtonProgressIndeterminate = true;
@@ -379,7 +385,7 @@ private void OnListFormats(object commandParameter)
379385
}
380386
}
381387

382-
private void OnAbortDl(object commandParameter)
388+
private void OnAbortDl(object? commandParameter)
383389
{
384390
try
385391
{
@@ -401,12 +407,12 @@ private void OnAbortDl(object commandParameter)
401407
}
402408
}
403409

404-
private bool CanOpenFolder(object commandParameter)
410+
private bool CanOpenFolder(object? commandParameter)
405411
{
406412
return !String.IsNullOrEmpty(_downloadPath) && Directory.Exists(_downloadPath);
407413
}
408414

409-
private bool CanStartDownload(object commandParameter)
415+
private bool CanStartDownload(object? commandParameter)
410416
{
411417
return !String.IsNullOrEmpty(_link) && !String.IsNullOrEmpty(_container) && !String.IsNullOrEmpty(_format) && !String.IsNullOrEmpty(_settings.DlPath) && !_freezeButton;
412418
}
@@ -446,7 +452,7 @@ private void UpdateDl()
446452
}
447453
}
448454

449-
private void DlOutputHandler(object sendingProcess, DataReceivedEventArgs outLine)
455+
private void DlOutputHandler(object? sendingProcess, DataReceivedEventArgs outLine)
450456
{
451457
if (!string.IsNullOrEmpty(outLine.Data))
452458
{
@@ -511,7 +517,7 @@ public string Container
511517
EnableFormatSelection = true;
512518
else
513519
{
514-
this.RaiseAndSetIfChanged(ref _format, "Auto", "Format");
520+
this.RaiseAndSetIfChanged(ref _format, "Auto", nameof(Format));
515521
_settings.Format = _format;
516522
EnableFormatSelection = false;
517523
}

‎YoutubeDl.Wpf/ViewModels/MainWindowViewModel.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public MainWindowViewModel(ISnackbarMessageQueue snackbarMessageQueue)
1414
{
1515
_drawerItems = GenerateItems(snackbarMessageQueue);
1616
_selectedItem = _drawerItems.First();
17-
_openAboutDialog = new DelegateCommand(OnOpenAboutDialog, (object commandParameter) => true);
17+
_openAboutDialog = new DelegateCommand(OnOpenAboutDialog, (object? commandParameter) => true);
1818
}
1919

2020
private ObservableCollection<DrawerItem> _drawerItems;
@@ -24,7 +24,7 @@ public MainWindowViewModel(ISnackbarMessageQueue snackbarMessageQueue)
2424

2525
public ICommand OpenAboutDialog => _openAboutDialog;
2626

27-
private async void OnOpenAboutDialog(object commandParameter)
27+
private async void OnOpenAboutDialog(object? commandParameter)
2828
{
2929
var aboutDialog = new AboutDialog
3030
{
@@ -45,7 +45,7 @@ public DrawerItem SelectedItem
4545
set => this.RaiseAndSetIfChanged(ref _selectedItem, value);
4646
}
4747

48-
private ObservableCollection<DrawerItem> GenerateItems(ISnackbarMessageQueue snackbarMessageQueue)
48+
private static ObservableCollection<DrawerItem> GenerateItems(ISnackbarMessageQueue snackbarMessageQueue)
4949
{
5050
if (snackbarMessageQueue == null)
5151
throw new ArgumentNullException(nameof(snackbarMessageQueue));

‎YoutubeDl.Wpf/ViewModels/SettingsViewModel.cs

+14-8
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public SettingsViewModel(ISnackbarMessageQueue snackbarMessageQueue)
5858
public ICommand ChangeColorMode => _changeColorMode;
5959
public ICommand BrowseExe => _browseExe;
6060

61-
private void OnChangeColorMode(object commandParameter)
61+
private void OnChangeColorMode(object? commandParameter)
6262
{
6363
ITheme theme = _paletteHelper.GetTheme();
6464
switch (commandParameter)
@@ -93,27 +93,33 @@ private void OnChangeColorMode(object commandParameter)
9393
}
9494
}
9595

96-
private void OnBrowseExe(object commandParameter)
96+
private void OnBrowseExe(object? commandParameter)
9797
{
98+
if (commandParameter == null)
99+
throw new ArgumentNullException(nameof(commandParameter));
100+
101+
if (commandParameter is not string parameter)
102+
throw new ArgumentException("Command parameter is not a string.", nameof(commandParameter));
103+
98104
Microsoft.Win32.OpenFileDialog openFileDialog = new Microsoft.Win32.OpenFileDialog
99105
{
100-
FileName = (string)commandParameter,
106+
FileName = parameter,
101107
DefaultExt = ".exe",
102108
Filter = "Executables (.exe)|*.exe"
103109
};
104110

105-
if ((string)commandParameter == "youtube-dl")
111+
if (parameter == "youtube-dl")
106112
openFileDialog.InitialDirectory = Path.GetDirectoryName(_dlPath);
107-
else if ((string)commandParameter == "ffmpeg")
113+
else if (parameter == "ffmpeg")
108114
openFileDialog.InitialDirectory = Path.GetDirectoryName(_ffmpegPath);
109115

110116
bool? result = openFileDialog.ShowDialog();
111117

112118
if (result == true)
113119
{
114-
if ((string)commandParameter == "youtube-dl")
120+
if (parameter == "youtube-dl")
115121
DlPath = openFileDialog.FileName;
116-
else if ((string)commandParameter == "ffmpeg")
122+
else if (parameter == "ffmpeg")
117123
FfmpegPath = openFileDialog.FileName;
118124
}
119125
}
@@ -134,7 +140,7 @@ private async Task LoadSettingsAsync()
134140
try
135141
{
136142
_settingsJson = new FileStream("Settings.json", FileMode.Open);
137-
_settings = await JsonSerializer.DeserializeAsync<SettingsJson>(_settingsJson);
143+
_settings = await JsonSerializer.DeserializeAsync<SettingsJson>(_settingsJson) ?? new();
138144
}
139145
catch
140146
{

‎YoutubeDl.Wpf/YoutubeDl.Wpf.csproj

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
1+
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
44
<OutputType>WinExe</OutputType>
5-
<TargetFramework>netcoreapp3.1</TargetFramework>
5+
<TargetFramework>net5.0-windows10.0.19041.0</TargetFramework>
66
<RootNamespace>YoutubeDl.Wpf</RootNamespace>
77
<UseWPF>true</UseWPF>
88
<ApplicationManifest>app.manifest</ApplicationManifest>
@@ -41,9 +41,11 @@
4141

4242
<ItemGroup>
4343
<PackageReference Include="MaterialDesignThemes" Version="3.2.0" />
44-
<PackageReference Include="PeanutButter.TinyEventAggregator" Version="1.2.378" />
45-
<PackageReference Include="ReactiveUI.Events.WPF" Version="11.5.35" />
46-
<PackageReference Include="ReactiveUI.WPF" Version="11.5.35" />
44+
<PackageReference Include="PeanutButter.TinyEventAggregator" Version="1.2.380" />
45+
<PackageReference Include="ReactiveUI.Events.WPF" Version="13.0.1" />
46+
<PackageReference Include="ReactiveUI.Fody" Version="13.0.1" />
47+
<PackageReference Include="ReactiveUI.Validation" Version="1.8.6" />
48+
<PackageReference Include="ReactiveUI.WPF" Version="13.0.1" />
4749
</ItemGroup>
4850

4951
<ItemGroup>

‎youtube-dl-wpf.sln

+6
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ VisualStudioVersion = 16.0.29721.120
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "YoutubeDl.Wpf", "YoutubeDl.Wpf\YoutubeDl.Wpf.csproj", "{D9BA13D1-3A0C-4A10-A785-EE49767BE872}"
77
EndProject
8+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "YoutubeDl.Wpf.Tests", "YoutubeDl.Wpf.Tests\YoutubeDl.Wpf.Tests.csproj", "{9C801388-1874-4317-B129-CF73024A02B3}"
9+
EndProject
810
Global
911
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1012
Debug|Any CPU = Debug|Any CPU
@@ -15,6 +17,10 @@ Global
1517
{D9BA13D1-3A0C-4A10-A785-EE49767BE872}.Debug|Any CPU.Build.0 = Debug|Any CPU
1618
{D9BA13D1-3A0C-4A10-A785-EE49767BE872}.Release|Any CPU.ActiveCfg = Release|Any CPU
1719
{D9BA13D1-3A0C-4A10-A785-EE49767BE872}.Release|Any CPU.Build.0 = Release|Any CPU
20+
{9C801388-1874-4317-B129-CF73024A02B3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
21+
{9C801388-1874-4317-B129-CF73024A02B3}.Debug|Any CPU.Build.0 = Debug|Any CPU
22+
{9C801388-1874-4317-B129-CF73024A02B3}.Release|Any CPU.ActiveCfg = Release|Any CPU
23+
{9C801388-1874-4317-B129-CF73024A02B3}.Release|Any CPU.Build.0 = Release|Any CPU
1824
EndGlobalSection
1925
GlobalSection(SolutionProperties) = preSolution
2026
HideSolutionNode = FALSE

0 commit comments

Comments
 (0)