-
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 #60 from David032/57-hardware-services-tests
Adding unit tests for Hardware services
- Loading branch information
Showing
16 changed files
with
262 additions
and
10 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using Iot.Device.Buzzer; | ||
using Moq; | ||
using skullOS.HardwareServices; | ||
|
||
namespace HardwareTests | ||
{ | ||
public class BuzzerTest : IHardwareServiceTest | ||
{ | ||
BuzzerService sut; | ||
|
||
[Fact(Skip = "Buzzer hard creates gpio driver")] | ||
public void CanCreate() | ||
{ | ||
Mock<Buzzer> mockedBuzzer = new Mock<Buzzer>([0]); | ||
|
||
sut = new BuzzerService(0, mockedBuzzer.Object); | ||
|
||
Assert.NotNull(sut); | ||
} | ||
} | ||
} |
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.HardwareServices; | ||
|
||
namespace HardwareTests | ||
{ | ||
public class CameraTest : IHardwareServiceTest | ||
{ | ||
CameraService sut; | ||
|
||
[Fact] | ||
public void CanCreate() | ||
{ | ||
CameraService service = new CameraService(); | ||
|
||
Assert.NotNull(service); | ||
} | ||
} | ||
} |
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,31 @@ | ||
<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.HardwareServices\skullOS.HardwareServices.csproj" /> | ||
<ProjectReference Include="..\skullOS.Tests\skullOS.Tests.csproj" /> | ||
</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,25 @@ | ||
using Moq; | ||
using skullOS.HardwareServices; | ||
using skullOS.Tests; | ||
using System.Device.Gpio; | ||
|
||
namespace HardwareTests | ||
{ | ||
public class LEDTest : IHardwareServiceTest | ||
{ | ||
[Fact] | ||
public void CanCreate() | ||
{ | ||
Mock<MockableGpioDriver> gpioMock = new(); | ||
var ctrlr = new GpioController(PinNumberingScheme.Logical, gpioMock.Object); | ||
Dictionary<string, int> testPins = new() | ||
{ | ||
{ "An Led", 6 }, | ||
{"Another led", 26 } | ||
}; | ||
LedService sut = new LedService(testPins, ctrlr); | ||
|
||
Assert.NotNull(sut); | ||
} | ||
} | ||
} |
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,20 @@ | ||
using Iot.Device.Media; | ||
using Moq; | ||
using skullOS.HardwareServices; | ||
|
||
namespace HardwareTests | ||
{ | ||
public class MicrophoneTest : IHardwareServiceTest | ||
{ | ||
[Fact] | ||
public void CanCreate() | ||
{ | ||
Mock<SoundDevice> SoundDevice = new Mock<SoundDevice>(); | ||
Mock<SoundConnectionSettings> SoundConnectionSettings = new Mock<SoundConnectionSettings>(); | ||
|
||
var sut = new MicrophoneService(mic: SoundDevice.Object); | ||
|
||
Assert.NotNull(sut); | ||
} | ||
} | ||
} |
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,21 @@ | ||
using Iot.Device.Ws28xx; | ||
using Moq; | ||
using skullOS.HardwareServices; | ||
using skullOS.Tests; | ||
|
||
namespace HardwareTests | ||
{ | ||
public class ProgrammableLedTest : IHardwareServiceTest | ||
{ | ||
[Fact(Skip = "SPI issue")] | ||
public void CanCreate() | ||
{ | ||
Mock<MockableSpiDevice> spiDevice = new Mock<MockableSpiDevice>(); | ||
Mock<Ws2812b> mockLed = new Mock<Ws2812b>(); | ||
|
||
var sut = new ProgrammableLedService(spiDevice.Object, 9, mockLed.Object); | ||
|
||
Assert.NotNull(sut); | ||
} | ||
} | ||
} |
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,15 @@ | ||
using skullOS.HardwareServices; | ||
|
||
namespace HardwareTests | ||
{ | ||
public class SpeakerTest : IHardwareServiceTest | ||
{ | ||
[Fact] | ||
public void CanCreate() | ||
{ | ||
var sut = new SpeakerService(); | ||
|
||
Assert.NotNull(sut); | ||
} | ||
} | ||
} |
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 HardwareTests | ||
{ | ||
public interface IHardwareServiceTest | ||
{ | ||
void CanCreate(); | ||
} | ||
} |
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,55 @@ | ||
using System.Device.Spi; | ||
|
||
namespace skullOS.Tests | ||
{ | ||
//Taken from: https://github.com/dotnet/iot/blob/main/src/devices/Board/tests/SpiDummyDevice.cs | ||
public class MockableSpiDevice : SpiDevice | ||
{ | ||
private bool _disposed; | ||
public MockableSpiDevice(SpiConnectionSettings connectionSettings, int[] pins) | ||
{ | ||
ConnectionSettings = connectionSettings; | ||
Pins = pins; | ||
_disposed = false; | ||
} | ||
|
||
public override SpiConnectionSettings ConnectionSettings { get; } | ||
public int[] Pins { get; } | ||
|
||
public override byte ReadByte() | ||
{ | ||
if (_disposed) | ||
{ | ||
throw new ObjectDisposedException(nameof(MockableSpiDevice)); | ||
} | ||
|
||
return 0xF8; | ||
} | ||
|
||
public override void Read(Span<byte> buffer) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
public override void WriteByte(byte value) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
public override void Write(ReadOnlySpan<byte> buffer) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
public override void TransferFullDuplex(ReadOnlySpan<byte> writeBuffer, Span<byte> readBuffer) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
protected override void Dispose(bool disposing) | ||
{ | ||
_disposed = true; | ||
base.Dispose(disposing); | ||
} | ||
} | ||
} |
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
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