Files
SpdUp/SpdUp.Tests/ObservableObjectTests.cs
Phil-icyou 19ba425e79 Initial commit: SpdUp Windows Gaming Booster v1.0.0
- .NET 8 WPF app with full MVVM architecture
- One-click boost: CPU, RAM, GPU, network, services, timer resolution
- Real-time system monitor (LibreHardwareMonitor)
- Auto game detection (30+ games)
- RAM optimizer with kernel-level cleanup
- Network optimizer (TCP registry tweaks)
- Service manager, process manager, shader cache cleaner
- Desktop widget overlay
- Debug log viewer
- Custom dark gaming theme with trans pride colors
- 84 unit tests (xUnit)
- Inno Setup installer script
- Landing page website
2026-03-08 17:34:45 +01:00

94 lines
2.3 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using System.ComponentModel;
using SpdUp.Core;
namespace SpdUp.Tests;
/// <summary>
/// Tests for ObservableObject base class.
/// </summary>
public class ObservableObjectTests
{
private sealed class TestObservable : ObservableObject
{
private string _name = string.Empty;
public string Name
{
get => _name;
set => SetProperty(ref _name, value);
}
private int _count;
public int Count
{
get => _count;
set => SetProperty(ref _count, value);
}
}
[Fact]
public void SetProperty_NewValue_RaisesPropertyChanged()
{
var obj = new TestObservable();
string? changedProp = null;
obj.PropertyChanged += (_, e) => changedProp = e.PropertyName;
obj.Name = "hello";
Assert.Equal("Name", changedProp);
Assert.Equal("hello", obj.Name);
}
[Fact]
public void SetProperty_SameValue_DoesNotRaisePropertyChanged()
{
var obj = new TestObservable { Name = "hello" };
bool raised = false;
obj.PropertyChanged += (_, _) => raised = true;
obj.Name = "hello";
Assert.False(raised);
}
[Fact]
public void SetProperty_ReturnsTrue_WhenValueChanged()
{
var obj = new TestObservable();
string? changedProp = null;
obj.PropertyChanged += (_, e) => changedProp = e.PropertyName;
obj.Count = 42;
Assert.Equal("Count", changedProp);
Assert.Equal(42, obj.Count);
}
[Fact]
public void SetProperty_ReturnsFalse_WhenValueUnchanged()
{
var obj = new TestObservable { Count = 5 };
bool raised = false;
obj.PropertyChanged += (_, _) => raised = true;
obj.Count = 5;
Assert.False(raised);
}
[Fact]
public void MultipleProperties_OnlyNotifyChanged()
{
var obj = new TestObservable();
var notifications = new List<string>();
obj.PropertyChanged += (_, e) => notifications.Add(e.PropertyName!);
obj.Name = "a";
obj.Count = 1;
obj.Name = "a"; // same no notification
obj.Count = 2;
Assert.Equal(3, notifications.Count);
Assert.Equal(["Name", "Count", "Count"], notifications);
}
}