-
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.
Merge pull request #56 from David032/47-module-tests
#47 Module Tests added
- Loading branch information
Showing
42 changed files
with
812 additions
and
165 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
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
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,7 @@ | ||
namespace CoreTests | ||
{ | ||
public class FileManagerTests | ||
{ | ||
|
||
} | ||
} |
File renamed without changes.
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,12 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace CoreTests | ||
{ | ||
internal class LoggerTests | ||
{ | ||
} | ||
} |
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,17 @@ | ||
using skullOS.Core; | ||
|
||
namespace CoreTests | ||
{ | ||
public class SettingsTests | ||
{ | ||
[Fact] | ||
public void TestSettingsLoader() | ||
{ | ||
var result = SettingsLoader.LoadConfig(@"TestData/TestSettings.txt"); | ||
Assert.NotNull(result); | ||
Assert.Single(result); | ||
result.TryGetValue("Worked", out string response); | ||
Assert.Equal("True", response); | ||
} | ||
} | ||
} |
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 @@ | ||
Worked=True |
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,51 @@ | ||
using Moq; | ||
using skullOS.Core; | ||
using skullOS.HardwareServices.Interfaces; | ||
using skullOS.Modules; | ||
using skullOS.Modules.Exceptions; | ||
|
||
namespace ModuleTests | ||
{ | ||
public class AdventureTest | ||
{ | ||
Mock<ICameraService> cameraMock; | ||
Adventure sut; | ||
public AdventureTest() | ||
{ | ||
FileManager.CreateSkullDirectory(false, true); | ||
|
||
cameraMock = new(); | ||
cameraMock.Setup(camera => camera.TakePictureAsync(It.IsAny<string>())).Returns(Task.FromResult("Pass")); | ||
sut = new(cameraMock.Object); | ||
} | ||
|
||
[Fact] | ||
public void CanCreateAdventureModule() | ||
{ | ||
Assert.NotNull(sut); | ||
} | ||
[Fact] | ||
public void OnEnableThrowsException() | ||
{ | ||
Assert.Throws<OnEnableException>(() => sut.OnEnable(It.IsAny<string[]>())); | ||
} | ||
[Fact] | ||
public void OnActionThrowsException() | ||
{ | ||
Assert.Throws<OnActionException>(() => sut.OnAction(It.IsAny<object>(), It.IsAny<EventArgs>())); | ||
} | ||
[Fact] | ||
public void NameReturnsCorrect() | ||
{ | ||
Assert.Equal("Adventure", sut.ToString()); | ||
} | ||
|
||
//Timelapse settings should probably be moved to read from file? | ||
[Fact] | ||
public void TimerHasCorrectDuration() | ||
{ | ||
var timer = sut.GetTimelapseController(); | ||
Assert.Equal(30000, timer.Interval); | ||
} | ||
} | ||
} |
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,54 @@ | ||
using Moq; | ||
using skullOS.HardwareServices.Interfaces; | ||
using skullOS.Modules; | ||
using skullOS.Modules.Exceptions; | ||
using skullOS.Modules.Interfaces; | ||
|
||
namespace ModuleTests | ||
{ | ||
public class BuzzerTest | ||
{ | ||
Buzzer sut; | ||
Mock<IMelodyPlayer> buzzerPlayer; | ||
|
||
public BuzzerTest() | ||
{ | ||
Mock<IBuzzerService> buzzerHardware = new(); | ||
buzzerPlayer = new(); | ||
buzzerPlayer.Setup(x => x.Play(It.IsAny<IList<MelodyElement>>(), It.IsAny<int>())).Verifiable(); | ||
|
||
sut = new Buzzer(buzzerHardware.Object, 13, buzzerPlayer.Object); | ||
} | ||
|
||
[Fact] | ||
public void CanCreateBuzzer() | ||
{ | ||
Assert.NotNull(sut); | ||
} | ||
|
||
[Fact] | ||
public void CanPlayTune() | ||
{ | ||
sut.PlayTune(BuzzerLibrary.Tunes.AlphabetSong); | ||
|
||
Mock.Verify([buzzerPlayer]); | ||
} | ||
|
||
[Fact] | ||
public void NameReturnsCorrect() | ||
{ | ||
Assert.Equal("Buzzer", sut.ToString()); | ||
} | ||
|
||
[Fact] | ||
public void OnEnableThrowsException() | ||
{ | ||
Assert.Throws<OnEnableException>(() => sut.OnEnable(It.IsAny<string[]>())); | ||
} | ||
[Fact] | ||
public void OnActionThrowsException() | ||
{ | ||
Assert.Throws<OnActionException>(() => sut.OnAction(It.IsAny<object>(), It.IsAny<EventArgs>())); | ||
} | ||
} | ||
} |
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,44 @@ | ||
using Moq; | ||
using skullOS.HardwareServices.Interfaces; | ||
using skullOS.Modules; | ||
|
||
namespace ModuleTests | ||
{ | ||
public class CameraTest | ||
{ | ||
Mock<ICameraService> camMock = new(); | ||
Mock<IMicrophoneService> micMock = new(); | ||
Mock<IBuzzerService> buzzerMock = new(); | ||
Mock<ISpeakerService> speakerMock = new(); | ||
Mock<ILedService> LedMock = new(); | ||
|
||
[Fact] | ||
public void CanCreate() | ||
{ | ||
Camera sut = new Camera(camMock.Object, micMock.Object, speakerMock.Object, LedMock.Object, buzzerMock.Object, @"TestData/CameraSettings.txt"); | ||
Assert.NotNull(sut); | ||
} | ||
|
||
[Fact] | ||
public async void CanTakePicture() | ||
{ | ||
camMock.Setup(camera => camera.TakePictureAsync(It.IsAny<string>())).Returns(Task.FromResult("Pass")).Verifiable(); | ||
|
||
Camera sut = new Camera(camMock.Object, micMock.Object, speakerMock.Object, LedMock.Object, buzzerMock.Object, @"TestData/CameraSettings.txt"); | ||
|
||
await sut.TakePicture(); | ||
Mock.Verify(camMock); | ||
} | ||
[Fact] | ||
public async void CanRecordVideo() | ||
{ | ||
camMock.Setup(camera => | ||
camera.RecordShortVideoAsync(It.IsAny<string>(), It.IsAny<bool>())).Returns(Task.FromResult("Pass")).Verifiable(); | ||
|
||
Camera sut = new Camera(camMock.Object, micMock.Object, speakerMock.Object, LedMock.Object, buzzerMock.Object, @"TestData/CameraSettings.txt"); | ||
|
||
await sut.RecordShortVideo(); | ||
Mock.Verify(camMock); | ||
} | ||
} | ||
} |
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 @@ | ||
global using Xunit; |
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,43 @@ | ||
<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="Microsoft.NET.Test.Sdk" Version="17.6.0" /> | ||
<PackageReference Include="Moq" Version="4.20.70" /> | ||
<PackageReference Include="xunit" Version="2.4.2" /> | ||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5"> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageReference> | ||
<PackageReference Include="coverlet.collector" Version="6.0.0"> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageReference> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\skullOS.Core\skullOS.Core.csproj" /> | ||
<ProjectReference Include="..\skullOS.HardwareServices\skullOS.HardwareServices.csproj" /> | ||
<ProjectReference Include="..\skullOS.Modules\skullOS.Modules.csproj" /> | ||
<ProjectReference Include="..\skullOS.Tests\skullOS.Tests.csproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<Folder Include="TestData\" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<None Update="TestData\PropSettings.txt"> | ||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
</None> | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
using Moq; | ||
using skullOS.HardwareServices.Interfaces; | ||
using skullOS.Modules; | ||
using skullOS.Modules.Exceptions; | ||
|
||
namespace ModuleTests | ||
{ | ||
public class PropTest | ||
{ | ||
Prop sut; | ||
string pathToTestData = @"TestData/PropSettings.txt"; | ||
|
||
public PropTest() | ||
{ | ||
Mock<ISpeakerService> speakerMock = new(); | ||
speakerMock.Setup(speaker => speaker.PlayAudio(It.IsAny<string>())).Returns(Task.CompletedTask); | ||
Mock<ILedService> ledMock = new(); | ||
|
||
sut = new Prop(speakerMock.Object, ledMock.Object, pathToTestData); | ||
} | ||
|
||
[Fact] | ||
public void CanCreateProp() | ||
{ | ||
Assert.NotNull(sut); | ||
} | ||
|
||
[Fact] | ||
public void NameReturnsCorrect() | ||
{ | ||
Assert.Equal("Prop", sut.ToString()); | ||
} | ||
|
||
[Fact] | ||
public void OnEnableThrowsException() | ||
{ | ||
Assert.Throws<OnEnableException>(() => sut.OnEnable(It.IsAny<string[]>())); | ||
} | ||
[Fact] | ||
public void OnActionThrowsException() | ||
{ | ||
Assert.Throws<OnActionException>(() => sut.OnAction(It.IsAny<object>(), It.IsAny<EventArgs>())); | ||
} | ||
} | ||
} |
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,44 @@ | ||
using Moq; | ||
using skullOS.HardwareServices.Interfaces; | ||
using skullOS.Modules; | ||
using skullOS.Modules.Exceptions; | ||
using skullOS.Tests; | ||
using System.Device.Gpio; | ||
|
||
namespace ModuleTests | ||
{ | ||
public class SupportTest | ||
{ | ||
Support sut; | ||
public SupportTest() | ||
{ | ||
Mock<ISpeakerService> speakerMock = new(); | ||
speakerMock.Setup(speaker => speaker.PlayAudio(It.IsAny<string>())).Returns(Task.CompletedTask); | ||
Mock<MockableGpioDriver> gpioMock = new(); | ||
var ctrlr = new GpioController(PinNumberingScheme.Logical, gpioMock.Object); | ||
|
||
sut = new Support(ctrlr, speakerMock.Object, 4); | ||
} | ||
|
||
[Fact] | ||
public void CanCreateSupportModule() | ||
{ | ||
Assert.NotNull(sut); | ||
} | ||
[Fact] | ||
public void SupportOnEnableThrowsException() | ||
{ | ||
Assert.Throws<OnEnableException>(() => sut.OnEnable(It.IsAny<string[]>())); | ||
} | ||
[Fact] | ||
public void SupportOnActionThrowsException() | ||
{ | ||
Assert.Throws<OnActionException>(() => sut.OnAction(It.IsAny<object>(), It.IsAny<EventArgs>())); | ||
} | ||
[Fact] | ||
public void SupportReturnsCorrectName() | ||
{ | ||
Assert.Equal("Support", sut.ToString()); | ||
} | ||
} | ||
} |
Oops, something went wrong.