Skip to content

Commit

Permalink
Add some unit tests
Browse files Browse the repository at this point in the history
(very very bad and very very random)
  • Loading branch information
Lamparter committed Oct 5, 2024
1 parent aa34ae4 commit 9caa691
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 7 deletions.
4 changes: 2 additions & 2 deletions Rebound/Rebound/Pages/ControlPanel/SystemAndSecurity.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public SystemAndSecurity()
CheckDefenderStatus();
}

void CheckDefenderStatus()
public void CheckDefenderStatus()
{
try
{
Expand Down Expand Up @@ -194,7 +194,7 @@ public static int UACStatus()
}
}

string DecodeProductState(int productState)
public string DecodeProductState(int productState)
{
// Define the bit masks
const int ProductStateMask = 0xF000;
Expand Down
8 changes: 4 additions & 4 deletions Rebound/UninstallationWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ public UninstallationWindow()
Load();
}

double currentStep = 0;
double totalSteps = 0;
double currentSubstep = 0;
double totalSubsteps = 0;
public double currentStep = 0;
public double totalSteps = 0;
public double currentSubstep = 0;
public double totalSubsteps = 0;

public async void Load()
{
Expand Down
35 changes: 35 additions & 0 deletions Tests/ControlPanel/SystemAndSecurity.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Rebound.Rebound.Pages.ControlPanel;
using System.Linq;
using Windows.ApplicationModel.Core;
using Microsoft.UI.Xaml.Controls;
using System.Management;

namespace Rebound.Tests.ControlPanel
{
[TestClass]
public class SystemAndSecurityTests
{
private SystemAndSecurity _systemAndSecurity;

[TestInitialize]
public void Setup()
{
_systemAndSecurity = new SystemAndSecurity();
}

[TestMethod]
public void Test_UACStatus()
{
int status = SystemAndSecurity.UACStatus();
Assert.IsTrue(status >= -1000 && status <= 3, "UACStatus should return a value between -1000 and 3.");
}

[TestMethod]
public void Test_DecodeProductState()
{
string state = _systemAndSecurity.DecodeProductState(0x10000);
Assert.AreEqual("B", state, "DecodeProductState should correctly decode the product state.");
}
}
}
6 changes: 5 additions & 1 deletion Tests/Rebound.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="MSTest.Sdk/3.5.1">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net8.0-windows10.0.22621.0</TargetFramework>
<LangVersion>latest</LangVersion>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
Expand All @@ -12,4 +12,8 @@
<TestingPlatformShowTestsFailure>true</TestingPlatformShowTestsFailure>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\Rebound\Rebound.csproj" />
</ItemGroup>

</Project>
39 changes: 39 additions & 0 deletions Tests/Rebound/UninstallationWindow.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Rebound;
using System.Threading.Tasks;

namespace Rebound.Tests.Rebound
{
[TestClass]
public class UninstallationWindowTests
{
private UninstallationWindow _uninstallationWindow;

[TestInitialize]
public void Setup()
{
_uninstallationWindow = new UninstallationWindow();
}

[TestMethod]
public async Task Test_UninstallAppPackage()
{
await _uninstallationWindow.UninstallAppPackage("packageFamilyName", "displayAppName", "lnkFile", "lnkDestination", "lnkDisplayName");
Assert.AreEqual(3, _uninstallationWindow.currentStep, "currentStep should be 3 after UninstallAppPackage is called.");
}

[TestMethod]
public async Task Test_DeleteShortcut()
{
await _uninstallationWindow.DeleteShortcut("displayAppName", "lnkDestination", "lnkDisplayName");
Assert.AreEqual(1, _uninstallationWindow.currentStep, "currentStep should be 1 after DeleteShortcut is called.");
}

[TestMethod]
public async Task Test_ReplaceShortcut()
{
await _uninstallationWindow.ReplaceShortcut("displayAppName", "lnkFile", "lnkDestination", "lnkDisplayName");
Assert.AreEqual(1, _uninstallationWindow.currentStep, "currentStep should be 1 after ReplaceShortcut is called.");
}
}
}

0 comments on commit 9caa691

Please sign in to comment.