Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#67 Code coverage improvements #69

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,23 @@ jobs:
- name: Build
run: dotnet build --no-restore
- name: Test
run: dotnet test --no-build --verbosity normal
run: dotnet test --no-build --verbosity normal --collect:"XPlat Code Coverage" --results-directory ./coverage
- name: Code Coverage Report
uses: irongut/[email protected]
with:
filename: coverage/**/coverage.cobertura.xml
badge: true
fail_below_min: true
format: markdown
hide_branch_rate: false
hide_complexity: true
indicators: true
output: both
thresholds: '33 66'

- name: Add Coverage PR Comment
uses: marocchino/sticky-pull-request-comment@v2
if: github.event_name == 'pull_request'
with:
recreate: true
path: code-coverage-results.md
1 change: 1 addition & 0 deletions Source/Tests/CoreTests/CoreTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

<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>
Expand Down
44 changes: 44 additions & 0 deletions Source/Tests/CoreTests/LoggerTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using skullOS.Core;
using skullOS.Core.Interfaces;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Moq;

namespace CoreTests
{
public class LoggerTest
{
ISkullLogger SkullLogger;

public LoggerTest()
{
FileManager.CreateSkullDirectory(isTest: true);
SkullLogger = new SkullLogger();
}

[Fact]
public void CanCreateLogger()
{
Assert.NotNull(SkullLogger);
}

[Fact]
public void LogIsLocatable()
{
Assert.Equal(It.IsAny<string>(), SkullLogger.GetLogLocation());
}

[Fact]
public void CanAddToLog()
{
var logContentsBefore = File.ReadAllText(SkullLogger.GetLogLocation());
SkullLogger.LogMessage("FooBar!");
var logContentsAfter = File.ReadAllText(SkullLogger.GetLogLocation());

Assert.NotEqual(logContentsBefore, logContentsAfter);
}
}
}
12 changes: 0 additions & 12 deletions Source/Tests/CoreTests/LoggerTests.cs

This file was deleted.

46 changes: 46 additions & 0 deletions Source/Tests/ModuleTests/CameraTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,51 @@ public async void CanRecordVideo()
await sut.RecordShortVideo();
Mock.Verify(camMock);
}

[Fact]
public void CreateThrowsException()
{
Camera sut = new Camera(camMock.Object, micMock.Object, speakerMock.Object, LedMock.Object, buzzerMock.Object, @"TestData/CameraSettings.txt");
Assert.Throws<NotImplementedException>(() => sut.Create());
}

[Fact]
public void ToStringReturnsName()
{
Camera sut = new Camera(camMock.Object, micMock.Object, speakerMock.Object, LedMock.Object, buzzerMock.Object, @"TestData/CameraSettings.txt");
Assert.Equal("Camera", sut.ToString());
}

[Fact]
public void OnEnableSetsModeCorrectly()
{
Camera sut = new Camera(camMock.Object, micMock.Object, speakerMock.Object, LedMock.Object, buzzerMock.Object, @"TestData/CameraSettings.txt");
sut.OnEnable(["ShortVideo"]);
Assert.Equal(CameraMode.ShortVideo, sut.CameraMode);
}

[Fact]
public void OnActionExecutesCorrectlyWithPicture()
{
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");

sut.CameraMode = CameraMode.Image;
sut.OnAction(It.IsAny<object>(), It.IsAny<EventArgs>());

Mock.Verify(camMock);
}
[Fact]
public void OnActionExecutesCorrectlyWithShortVideo()
{
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");

sut.CameraMode= CameraMode.ShortVideo;
sut.OnAction(It.IsAny<object>(), It.IsAny<EventArgs>());

Mock.Verify(camMock);
}
}
}
46 changes: 46 additions & 0 deletions Source/Tests/ModuleTests/DownlinkTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using Moq;
using skullOS.Modules;
using skullOS.Modules.Exceptions;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ModuleTests
{
public class DownlinkTest
{
Downlink Downlink;

public DownlinkTest()
{
Downlink = new Downlink();
}

[Fact]
public void CreateThrowsException()
{
Assert.Throws<NotImplementedException>(() => Downlink.Create());
}

[Fact]
public void OnActionThrowsException()
{
Assert.Throws<OnActionException>(() =>
Downlink.OnAction(It.IsAny<object>(), It.IsAny<EventArgs>()));
}

[Fact]
public void OnEnableThrowsException()
{
Assert.Throws<OnEnableException>(() => Downlink.OnEnable(It.IsAny<string[]>()));
}

[Fact]
public void OnStringThrowsException()
{
Assert.Throws<NotImplementedException>(() => Downlink.ToString());
}
}
}
46 changes: 46 additions & 0 deletions Source/Tests/ModuleTests/QrCodeReaderTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using Moq;
using skullOS.Modules;
using skullOS.Modules.Exceptions;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ModuleTests
{
public class QrCodeReaderTest
{
QrCodeReader codeReader;

public QrCodeReaderTest()
{
codeReader = new QrCodeReader();
}

[Fact]
public void CreateThrowsException()
{
Assert.Throws<NotImplementedException>(() => codeReader.Create());
}

[Fact]
public void OnActionThrowsException()
{
Assert.Throws<OnActionException>(() =>
codeReader.OnAction(It.IsAny<object>(), It.IsAny<EventArgs>()));
}

[Fact]
public void OnEnableThrowsException()
{
Assert.Throws<OnEnableException>(() => codeReader.OnEnable(It.IsAny<string[]>()));
}

[Fact]
public void OnStringThrowsException()
{
Assert.Throws<NotImplementedException>(() => codeReader.ToString());
}
}
}
46 changes: 46 additions & 0 deletions Source/Tests/ModuleTests/UplinkTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using Moq;
using skullOS.Modules;
using skullOS.Modules.Exceptions;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ModuleTests
{
public class UplinkTest
{
Uplink Uplink;

public UplinkTest()
{
Uplink = new Uplink();
}

[Fact]
public void CreateThrowsException()
{
Assert.Throws<NotImplementedException>(() => Uplink.Create());
}

[Fact]
public void OnActionThrowsException()
{
Assert.Throws<OnActionException>(() =>
Uplink.OnAction(It.IsAny<object>(), It.IsAny<EventArgs>()));
}

[Fact]
public void OnEnableThrowsException()
{
Assert.Throws<OnEnableException>(() => Uplink.OnEnable(It.IsAny<string[]>()));
}

[Fact]
public void OnStringThrowsException()
{
Assert.Throws<NotImplementedException>(() => Uplink.ToString());
}
}
}
6 changes: 5 additions & 1 deletion Source/skullOS.Core/FileManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,11 @@ public static void CreateSkullDirectory(bool usePersonalDir = true, bool isTest
}

}

else
{
var testDir = Directory.CreateDirectory("/tmp");
rootDirectoryPath = testDir.FullName;
}
}

}
Expand Down
1 change: 1 addition & 0 deletions Source/skullOS.Core/Interfaces/ISkullLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
{
public interface ISkullLogger
{
string GetLogLocation();
void LogMessage(string message);
}
}
5 changes: 5 additions & 0 deletions Source/skullOS.Core/SkullLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,10 @@ public void LogMessage(string message)
#endif
File.AppendAllText(filepath, DateTime.Now.ToShortTimeString() + ":" + message + "\n");
}

public string GetLogLocation()
{
return filepath;
}
}
}
17 changes: 8 additions & 9 deletions Source/skullOS.Modules/Buzzer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public override string ToString()
/// 3rd party class for playing media via a buzzer
/// Sourced from teh iot samples
/// </summary>
public class MelodyPlayer : IMelodyPlayer
internal class MelodyPlayer : IMelodyPlayer
{
private readonly DeviceBuzzer _buzzer;
private int _wholeNoteDurationInMilliseconds;
Expand Down Expand Up @@ -391,17 +391,16 @@ public NoteElement(Note note, Octave octave, Duration duration)
Note = note;
Octave = octave;
}
}

/// <summary>
/// A pause
/// </summary>
internal class PauseElement : MelodyElement
{
public PauseElement(Duration duration) : base(duration)
/// <summary>
/// A pause
/// Once there's a tune with a puase in, this can be made internal again
/// </summary>
internal class PauseElement(BuzzerStructures.Duration duration) : MelodyElement(duration)
{

}
}


#endregion
}
8 changes: 5 additions & 3 deletions Source/skullOS.Modules/Downlink.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace skullOS.Modules
using skullOS.Modules.Exceptions;

namespace skullOS.Modules
{
public class Downlink : Module, IDownlinkModule
{
Expand All @@ -9,12 +11,12 @@ public override void Create()

public override void OnAction(object? sender, EventArgs e)
{
throw new NotImplementedException();
throw new OnActionException("Not yet implemented");
}

public override void OnEnable(string[] args)
{
throw new NotImplementedException();
throw new OnEnableException("Not yet implemented");
}
public override string ToString()
{
Expand Down
8 changes: 5 additions & 3 deletions Source/skullOS.Modules/QrCodeReader.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace skullOS.Modules
using skullOS.Modules.Exceptions;

namespace skullOS.Modules
{
public class QrCodeReader : Module, IQrCodeReaderModule
{
Expand All @@ -9,12 +11,12 @@ public override void Create()

public override void OnAction(object? sender, EventArgs e)
{
throw new NotImplementedException();
throw new OnActionException("Not yet implemented");
}

public override void OnEnable(string[] args)
{
throw new NotImplementedException();
throw new OnEnableException("Not yet implemented");
}
public override string ToString()
{
Expand Down
Loading
Loading