Skip to content
Open
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
6 changes: 6 additions & 0 deletions Directory.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<Project>
<!-- Shared version property for all projects -->
<PropertyGroup>
<Version>2.1.8</Version>
</PropertyGroup>
</Project>
6 changes: 4 additions & 2 deletions TrackOMatic.Logic.Test/TrackOMatic.Logic.Test.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<Import Project="../Directory.props" />

<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
Expand All @@ -22,4 +24,4 @@
<Using Include="Xunit" />
</ItemGroup>

</Project>
</Project>
4 changes: 3 additions & 1 deletion TrackOMatic.Logic/TrackOMatic.Logic.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<Import Project="../Directory.props" />

<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
Expand Down
6 changes: 4 additions & 2 deletions TrackOMatic.Services.Test/TrackOMatic.Services.Test.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<Import Project="../Directory.props" />

<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
Expand All @@ -22,4 +24,4 @@
<Using Include="Xunit" />
</ItemGroup>

</Project>
</Project>
120 changes: 120 additions & 0 deletions TrackOMatic.Services.Test/VersionServiceTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
namespace TrackOMatic.Services.Test;

public class VersionServiceTests
{
private readonly VersionService _sut = new();

[Fact]
public void GetApplicationVersion_ReturnsValidVersion()
{
// Arrange & Act
var version = _sut.GetApplicationVersion();

Assert.Multiple(() =>
{
// Assert
Assert.NotNull(version);
Assert.True(version.Major >= 0, "Major version should be non-negative");
});
}

[Fact]
public void GetApplicationVersion_ComponentsAreNonNegative()
{
// Arrange & Act
var version = _sut.GetApplicationVersion();

Assert.Multiple(() =>
{
// Assert
Assert.True(version.Major >= 0, "Major version should be non-negative");
Assert.True(version.Minor >= 0, "Minor version should be non-negative");
Assert.True(version.Build >= 0, "Build version should be non-negative");
Assert.True(version.Revision >= 0, "Revision should be non-negative");
});
}

[Fact]
public void GetVersionString_ReturnsFormattedString()
{
// Arrange & Act
var versionString = _sut.GetVersionString();

// Assert
Assert.Multiple(() =>
{
Assert.NotNull(versionString);
Assert.NotEmpty(versionString);
Assert.Matches(@"^\d+\.\d+\.\d+$", versionString); // Matches Major.Minor.Build format
});
}

[Fact]
public void GetVersionString_FormatsAsExpected()
{
// Arrange & Act
var version = _sut.GetApplicationVersion();
var versionString = _sut.GetVersionString();
var expectedFormat = $"{version.Major}.{version.Minor}.{version.Build}";

// Assert
Assert.Equal(expectedFormat, versionString);
}

[Fact]
public void GetVersionString_DoesNotIncludeRevision()
{
// Arrange & Act
var version = _sut.GetApplicationVersion();
var versionString = _sut.GetVersionString();

// Assert
// Should have exactly 2 dots for Major.Minor.Build format
var dotCount = versionString.Count(c => c == '.');
Assert.Equal(2, dotCount);
}

[Fact]
public void GetApplicationVersion_ConsistentBetweenCalls()
{
// Arrange & Act
var version1 = _sut.GetApplicationVersion();
var version2 = _sut.GetApplicationVersion();

// Assert
Assert.Equal(version1, version2);
}

[Fact]
public void GetVersionString_ConsistentBetweenCalls()
{
// Arrange & Act
var versionString1 = _sut.GetVersionString();
var versionString2 = _sut.GetVersionString();

// Assert
Assert.Equal(versionString1, versionString2);
}

[Fact]
public void GetVersionString_VersionStringAndApplicationVersionAreConsistent()
{
// Arrange & Act
var appVersion = _sut.GetApplicationVersion();
var versionString = _sut.GetVersionString();

// Parse the version string to verify it matches the application version
var parts = versionString.Split('.');
var parsedMajor = int.Parse(parts[0]);
var parsedMinor = int.Parse(parts[1]);
var parsedBuild = int.Parse(parts[2]);

// Assert
Assert.Multiple(() =>
{
Assert.Equal(appVersion.Major, parsedMajor);
Assert.Equal(appVersion.Minor, parsedMinor);
Assert.Equal(appVersion.Build, parsedBuild);
});
}
}
8 changes: 8 additions & 0 deletions TrackOMatic.Services/IVersionService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace TrackOMatic.Services;

public interface IVersionService
{
public Version GetApplicationVersion();

public string GetVersionString();
}
20 changes: 20 additions & 0 deletions TrackOMatic.Services/ServiceLocator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using Microsoft.Extensions.DependencyInjection;

namespace TrackOMatic.Services;

public static class ServiceLocator
{
private static IServiceProvider? _provider;

public static void Initialize(IServiceProvider provider) => _provider = provider;

public static T GetService<T>() where T : notnull
{
if (_provider == null)
{
throw new InvalidOperationException("ServiceLocator not initialized");
}

return _provider.GetRequiredService<T>();
}
}
4 changes: 3 additions & 1 deletion TrackOMatic.Services/TrackOMatic.Services.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<Import Project="../Directory.props" />

<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
Expand Down
18 changes: 18 additions & 0 deletions TrackOMatic.Services/VersionService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System.Reflection;

namespace TrackOMatic.Services;

public class VersionService : IVersionService
{
public Version GetApplicationVersion()
{
var version = Assembly.GetExecutingAssembly().GetName().Version;
return version ?? new(0, 0, 0, 0);
}

public string GetVersionString()
{
var version = GetApplicationVersion();
return $"{version.Major}.{version.Minor}.{version.Build}";
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<Import Project="../Directory.props" />

<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
Expand All @@ -22,4 +24,4 @@
<Using Include="Xunit" />
</ItemGroup>

</Project>
</Project>
4 changes: 3 additions & 1 deletion TrackOMatic.ViewModels/TrackOMatic.ViewModels.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<Import Project="../Directory.props" />

<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
Expand Down
3 changes: 1 addition & 2 deletions TrackOMatic/App.xaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
<Application x:Class="TrackOMatic.App"
<Application x:Class="TrackOMatic.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:TrackOMatic"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
StartupUri="MainWindow.xaml"
Exit="App_Exit">
<Application.Resources>
<ResourceDictionary>
Expand Down
86 changes: 47 additions & 39 deletions TrackOMatic/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,52 +1,60 @@
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;

using Microsoft.Extensions.DependencyInjection;

using TrackOMatic.Properties;
using TrackOMatic.Services;

namespace TrackOMatic;

namespace TrackOMatic
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
private readonly IServiceProvider _serviceProvider;

App()
{
var services = new ServiceCollection();
services.AddSingleton<IVersionService, VersionService>();

App()
{
Dispatcher.UnhandledException += OnDispatcherUnhandledException;
}
_serviceProvider = services.BuildServiceProvider();
ServiceLocator.Initialize(_serviceProvider);
Dispatcher.UnhandledException += OnDispatcherUnhandledException;
}

private void App_Exit(object sender, ExitEventArgs e)
{
}
private void App_Exit(object sender, ExitEventArgs e)
{
}

void OnDispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e)
{
}
void OnDispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e)
{
}

protected override void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);
UpdatePadBarrelImages();
}
protected override void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);

var versionService = _serviceProvider.GetRequiredService<IVersionService>();
MainWindow mainWindow = new(versionService);
mainWindow.Show();

public void UpdatePadBarrelImages()
UpdatePadBarrelImages();
}

public void UpdatePadBarrelImages()
{
var dicts = Resources.MergedDictionaries;
dicts.Clear();
dicts.Add(new ResourceDictionary
{
Source = new Uri("Dictionary1.xaml", UriKind.Relative)
});
var path = Settings.Default.ColoredBarrelPadMoves ? "ColoredBarrelPadImages.xaml" : "BaseBarrelPadImages.xaml";
dicts.Add(new ResourceDictionary
{
var dicts = Resources.MergedDictionaries;
dicts.Clear();
dicts.Add(new ResourceDictionary
{
Source = new Uri("Dictionary1.xaml", UriKind.Relative)
});
var path = Settings.Default.ColoredBarrelPadMoves ? "ColoredBarrelPadImages.xaml" : "BaseBarrelPadImages.xaml";
dicts.Add(new ResourceDictionary
{
Source = new Uri(path, UriKind.Relative)
});
}
Source = new Uri(path, UriKind.Relative)
});
}
}
1 change: 1 addition & 0 deletions TrackOMatic/AutoUpdateInfo.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
<changelog>https://github.com/Brian0255/Track-O-Matic/releases</changelog>
<mandatory>false</mandatory>
</item>

5 changes: 4 additions & 1 deletion TrackOMatic/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,10 @@
<MenuItem Name="BroadcastSongDisplay" Header="Song Display" IsCheckable="True" StaysOpenOnClick="True" IsChecked="{Binding Source={x:Static properties:Settings.Default}, Path=BroadcastSongDisplay}" Click="BroadcastSongDisplayToggle"/>
</MenuItem>
</MenuItem>
<MenuItem Header="Version 2.1.8" IsHitTestVisible="False" Focusable="False" HorizontalAlignment="Right"/>
<MenuItem Header="{Binding ApplicationVersion, StringFormat='Version {0}'}"
IsHitTestVisible="False"
Focusable="False"
HorizontalAlignment="Right"/>
</Menu>
<Grid>
<Grid.ColumnDefinitions>
Expand Down
Loading