-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(test): added tests for shutdown class
- Loading branch information
Showing
3 changed files
with
277 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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."); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters