Skip to content

Commit

Permalink
feat(test): added tests for shutdown class
Browse files Browse the repository at this point in the history
  • Loading branch information
sikelio committed Aug 2, 2024
1 parent fc520e4 commit 93bd911
Show file tree
Hide file tree
Showing 3 changed files with 277 additions and 0 deletions.
244 changes: 244 additions & 0 deletions System.Test/ShutdownTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,244 @@
using FrApp42.System.Computer.Shutdown;

namespace System.Test
{
[TestClass]
public class ShutdownTest
{
private readonly string _hostname = "machine.local";

[TestMethod]
public void ClassicShutdown()
{
Shutdown shutdown = new();
shutdown
.SetMachine(_hostname)
.ShutdownComputer();

string command = shutdown.GetCommand();
string expectedCommand = $" /m {_hostname} /s";

Assert.AreEqual(expectedCommand, command, "The generated command does not match the expected command.");
}

[TestMethod]
public void LogOffUser()
{
Shutdown shutdown = new();
shutdown
.LogoutUser();

string command = shutdown.GetCommand();
string expectedCommand = $" /l";

Assert.AreEqual(expectedCommand, command, "The generated command does not match the expected command.");
}

[TestMethod]
public void ShutdownAndSignOnAuto()
{
Shutdown shutdown = new();
shutdown
.ShutdownAndSignOn();

string command = shutdown.GetCommand();
string expectedCommand = $" /sg";

Assert.AreEqual(expectedCommand, command, "The generated command does not match the expected command.");
}

[TestMethod]
public void TimeOutAndComment()
{
Shutdown shutdown = new();
shutdown
.SetMachine(_hostname)
.SetTimeOut(60)
.SetComment("Scheduled maintenance")
.ShutdownComputer();

string command = shutdown.GetCommand();
string expectedCommand = $" /m {_hostname} /t 60 /c \"Scheduled maintenance\" /s";

Assert.AreEqual(expectedCommand, command, "The generated command does not match the expected command.");
}

[TestMethod]
public void RebootComputer()
{
Shutdown shutdown = new();
shutdown
.SetMachine(_hostname)
.Reboot();

string command = shutdown.GetCommand();
string expectedCommand = $" /m {_hostname} /r";

Assert.AreEqual(expectedCommand, command, "The generated command does not match the expected command.");
}

[TestMethod]
public void HibernateComputer()
{
Shutdown shutdown = new();
shutdown
.SetMachine(_hostname)
.Hibernate();

string command = shutdown.GetCommand();
string expectedCommand = $" /m {_hostname} /h";

Assert.AreEqual(expectedCommand, command, "The generated command does not match the expected command.");
}

[TestMethod]
public void SoftShutdown()
{
Shutdown shutdown = new();
shutdown
.SetMachine(_hostname)
.ShutdownComputer()
.Soft();

string command = shutdown.GetCommand();
string expectedCommand = $" /m {_hostname} /s /soft";

Assert.AreEqual(expectedCommand, command, "The generated command does not match the expected command.");
}

[TestMethod]
public void OpenBootOptionsTest()
{
Shutdown shutdown = new();
shutdown
.SetMachine(_hostname)
.Reboot()
.OpenBootOptions();

string command = shutdown.GetCommand();
string expectedCommand = $" /m {_hostname} /r /o";

Assert.AreEqual(expectedCommand, command, "The generated command does not match the expected command.");
}

[TestMethod]
public void ForceShutdownComputer()
{
Shutdown shutdown = new();
shutdown
.SetMachine(_hostname)
.ShutdownComputer()
.ForceShutdown();

string command = shutdown.GetCommand();
string expectedCommand = $" /m {_hostname} /s /f";

Assert.AreEqual(expectedCommand, command, "The generated command does not match the expected command.");
}

[TestMethod]
public void ShutdownWithComment()
{
Shutdown shutdown = new();
shutdown
.SetMachine(_hostname)
.ShutdownComputer()
.SetComment("End of day shutdown");

string command = shutdown.GetCommand();
string expectedCommand = $" /m {_hostname} /s /c \"End of day shutdown\"";

Assert.AreEqual(expectedCommand, command, "The generated command does not match the expected command.");
}

[TestMethod]
public void LogoutNotWithMachine()
{
Shutdown shutdown = new();
shutdown
.SetMachine(_hostname)
.LogoutUser();

string command = shutdown.GetCommand();
string expectedCommand = $" /m {_hostname}";

Assert.AreEqual(expectedCommand, command, "The command should not contain /l when /m is present.");
}

[TestMethod]
public void LogoutNotWithTimeout()
{
Shutdown shutdown = new();
shutdown
.SetTimeOut(60)
.LogoutUser();

string command = shutdown.GetCommand();
string expectedCommand = $" /t 60";

Assert.AreEqual(expectedCommand, command, "The command should not contain /l when /t is present.");
}

[TestMethod]
public void MachineNotWithLogout()
{
Shutdown shutdown = new();
shutdown
.LogoutUser()
.SetMachine(_hostname);

string command = shutdown.GetCommand();
string expectedCommand = $" /l";

Assert.AreEqual(expectedCommand, command, "The command should not contain /m when /l is present.");
}

[TestMethod]
public void TimeoutNotWithLogout()
{
Shutdown shutdown = new();
shutdown
.LogoutUser()
.SetTimeOut(60);

string command = shutdown.GetCommand();
string expectedCommand = $" /l";

Assert.AreEqual(expectedCommand, command, "The command should not contain /t when /l is present.");
}

[TestMethod]
public void NoDuplicateArguments()
{
Shutdown shutdown = new();
shutdown
.SetMachine(_hostname)
.SetMachine(_hostname);

string command = shutdown.GetCommand();
string expectedCommand = $" /m {_hostname}";

Assert.AreEqual(expectedCommand, command, "The command should not contain duplicated /m arguments.");

shutdown = new Shutdown();
shutdown
.SetTimeOut(60)
.SetTimeOut(60);

command = shutdown.GetCommand();
expectedCommand = $" /t 60";

Assert.AreEqual(expectedCommand, command, "The command should not contain duplicated /t arguments.");

shutdown = new Shutdown();
shutdown
.ShutdownComputer()
.ShutdownComputer();

command = shutdown.GetCommand();
expectedCommand = $" /s";

Assert.AreEqual(expectedCommand, command, "The command should not contain duplicated /s arguments.");
}
}
}
27 changes: 27 additions & 0 deletions System.Test/System.Test.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<Project Sdk="Microsoft.NET.Sdk">

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

<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="coverlet.collector" Version="6.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="MSTest.TestAdapter" Version="3.1.1" />
<PackageReference Include="MSTest.TestFramework" Version="3.1.1" />
</ItemGroup>

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

<ItemGroup>
<Using Include="Microsoft.VisualStudio.TestTools.UnitTesting" />
</ItemGroup>

</Project>
6 changes: 6 additions & 0 deletions Tools.sln
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "System", "System\System.csp
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Web", "Web\Web.csproj", "{3872357E-B751-4C1B-AFD7-E4883E2FBB4C}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "System.Test", "System.Test\System.Test.csproj", "{1501A81F-3308-4471-BCDF-113AC9BF13EA}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -21,6 +23,10 @@ Global
{3872357E-B751-4C1B-AFD7-E4883E2FBB4C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3872357E-B751-4C1B-AFD7-E4883E2FBB4C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3872357E-B751-4C1B-AFD7-E4883E2FBB4C}.Release|Any CPU.Build.0 = Release|Any CPU
{1501A81F-3308-4471-BCDF-113AC9BF13EA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1501A81F-3308-4471-BCDF-113AC9BF13EA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1501A81F-3308-4471-BCDF-113AC9BF13EA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1501A81F-3308-4471-BCDF-113AC9BF13EA}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down

0 comments on commit 93bd911

Please sign in to comment.