Skip to content
Open
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
6 changes: 6 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
version: 2
updates:
- package-ecosystem: "nuget"
directory: "/"
schedule:
interval: "weekly"
73 changes: 25 additions & 48 deletions .github/workflows/sonarcloud.yml
Original file line number Diff line number Diff line change
@@ -1,31 +1,3 @@
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.

# This workflow helps you trigger a SonarCloud analysis of your code and populates
# GitHub Code Scanning alerts with the vulnerabilities found.
# Free for open source project.

# 1. Login to SonarCloud.io using your GitHub account

# 2. Import your project on SonarCloud
# * Add your GitHub organization first, then add your repository as a new project.
# * Please note that many languages are eligible for automatic analysis,
# which means that the analysis will start automatically without the need to set up GitHub Actions.
# * This behavior can be changed in Administration > Analysis Method.
#
# 3. Follow the SonarCloud in-product tutorial
# * a. Copy/paste the Project Key and the Organization Key into the args parameter below
# (You'll find this information in SonarCloud. Click on "Information" at the bottom left)
#
# * b. Generate a new token and add it to your Github repository's secrets using the name SONAR_TOKEN
# (On SonarCloud, click on your avatar on top-right > My account > Security
# or go directly to https://sonarcloud.io/account/security/)

# Feel free to take a look at our documentation (https://docs.sonarcloud.io/getting-started/github/)
# or reach out to our community forum if you need some help (https://community.sonarsource.com/c/help/sc/9)

name: SonarCloud analysis

on:
Expand All @@ -36,15 +8,16 @@ on:
workflow_dispatch:

permissions:
pull-requests: read # allows SonarCloud to decorate PRs with analysis results
pull-requests: read

jobs:
sonar-check:
name: Sonar Check
runs-on: windows-latest # безпечно для будь-яких .NET проектів
runs-on: windows-latest
steps:
- uses: actions/checkout@v4
with: { fetch-depth: 0 }
with:
fetch-depth: 0

- uses: actions/setup-dotnet@v4
with:
Expand All @@ -54,29 +27,33 @@ jobs:
- name: SonarScanner Begin
run: |
dotnet tool install --global dotnet-sonarscanner
echo "$env:USERPROFILE\.dotnet\tools" >> $env:GITHUB_PATH
dotnet sonarscanner begin `
/k:"ppanchen_NetSdrClient" `
/o:"ppanchen" `
/d:sonar.token="${{ secrets.SONAR_TOKEN }}" `
/d:sonar.cs.opencover.reportsPaths="**/coverage.xml" `
/d:sonar.cpd.cs.minimumTokens=40 `
/d:sonar.cpd.cs.minimumLines=5 `
/d:sonar.exclusions=**/bin/**,**/obj/**,**/sonarcloud.yml `
/d:sonar.qualitygate.wait=true
/k:"NatashaTymchenko_NetSdrClient" `
/o:"natashatymchenko" `
/d:sonar.token="${{ secrets.SONAR_TOKEN }}" `
/d:sonar.cs.opencover.reportsPaths="**/coverage.xml" `
/d:sonar.cpd.cs.minimumTokens=40 `
/d:sonar.cpd.cs.minimumLines=5 `
/d:sonar.exclusions=**/bin/**,**/obj/**,**/sonarcloud.yml `
/d:sonar.qualitygate.wait=true
shell: pwsh
# 2) BUILD & TEST

# 2) BUILD
- name: Restore
run: dotnet restore NetSdrClient.sln

- name: Build
run: dotnet build NetSdrClient.sln -c Release --no-restore
#- name: Tests with coverage (OpenCover)
# run: |
# dotnet test NetSdrClientAppTests/NetSdrClientAppTests.csproj -c Release --no-build `
# /p:CollectCoverage=true `
# /p:CoverletOutput=TestResults/coverage.xml `
# /p:CoverletOutputFormat=opencover
# shell: pwsh

# ДОДАНО БЛОК ТЕСТІВ
- name: Tests with coverage (OpenCover)
run: |
dotnet test NetSdrClientAppTests/NetSdrClientAppTests.csproj -c Release --no-build `
/p:CollectCoverage=true `
/p:CoverletOutput=TestResults/coverage.xml `
/p:CoverletOutputFormat=opencover
shell: pwsh

# 3) END: SonarScanner
- name: SonarScanner End
run: dotnet sonarscanner end /d:sonar.token="${{ secrets.SONAR_TOKEN }}"
Expand Down
2 changes: 1 addition & 1 deletion NetSdrClientApp/NetSdrClientApp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="SharpZipLib" Version="1.3.2" />
</ItemGroup>

Expand Down
144 changes: 41 additions & 103 deletions NetSdrClientAppTests/NetSdrClientTests.cs
Original file line number Diff line number Diff line change
@@ -1,119 +1,57 @@
using Moq;
using NUnit.Framework;
using Moq;
using NetSdrClientApp;
using NetSdrClientApp.Networking;
using System.Threading.Tasks;

namespace NetSdrClientAppTests;

public class NetSdrClientTests
namespace NetSdrClientAppTests
{
NetSdrClient _client;
Mock<ITcpClient> _tcpMock;
Mock<IUdpClient> _updMock;

public NetSdrClientTests() { }

[SetUp]
public void Setup()
[TestFixture]
public class NetSdrClientTests
{
_tcpMock = new Mock<ITcpClient>();
_tcpMock.Setup(tcp => tcp.Connect()).Callback(() =>
{
_tcpMock.Setup(tcp => tcp.Connected).Returns(true);
});
private Mock<ITcpClient> _mockTcp;
private Mock<IUdpClient> _mockUdp;
private NetSdrClient _client;

_tcpMock.Setup(tcp => tcp.Disconnect()).Callback(() =>
[SetUp]
public void Setup()
{
_tcpMock.Setup(tcp => tcp.Connected).Returns(false);
});
_mockTcp = new Mock<ITcpClient>();
_mockUdp = new Mock<IUdpClient>();
_client = new NetSdrClient(_mockTcp.Object, _mockUdp.Object);
}

_tcpMock.Setup(tcp => tcp.SendMessageAsync(It.IsAny<byte[]>())).Callback<byte[]>((bytes) =>
[Test]
public async Task ConnectAsync_ShouldCallTcpConnect()
{
_tcpMock.Raise(tcp => tcp.MessageReceived += null, _tcpMock.Object, bytes);
});

_updMock = new Mock<IUdpClient>();

_client = new NetSdrClient(_tcpMock.Object, _updMock.Object);
}

[Test]
public async Task ConnectAsyncTest()
{
//act
await _client.ConnectAsync();

//assert
_tcpMock.Verify(tcp => tcp.Connect(), Times.Once);
_tcpMock.Verify(tcp => tcp.SendMessageAsync(It.IsAny<byte[]>()), Times.Exactly(3));
}

[Test]
public async Task DisconnectWithNoConnectionTest()
{
//act
_client.Disconect();

//assert
//No exception thrown
_tcpMock.Verify(tcp => tcp.Disconnect(), Times.Once);
}

[Test]
public async Task DisconnectTest()
{
//Arrange
await ConnectAsyncTest();

//act
_client.Disconect();

//assert
//No exception thrown
_tcpMock.Verify(tcp => tcp.Disconnect(), Times.Once);
}

[Test]
public async Task StartIQNoConnectionTest()
{

//act
await _client.StartIQAsync();

//assert
//No exception thrown
_tcpMock.Verify(tcp => tcp.SendMessageAsync(It.IsAny<byte[]>()), Times.Never);
_tcpMock.VerifyGet(tcp => tcp.Connected, Times.AtLeastOnce);
}

[Test]
public async Task StartIQTest()
{
//Arrange
await ConnectAsyncTest();

await _client.ConnectAsync();

_mockTcp.Verify(x => x.ConnectAsync(), Times.AtLeastOnce);
}

[Test]
public void Disconnect_ShouldCallTcpDisconnect()
{
_client.Disconnect(); // Тут вже правильна назва!

//act
await _client.StartIQAsync();
_mockTcp.Verify(x => x.Disconnect(), Times.Once);
}

//assert
//No exception thrown
_updMock.Verify(udp => udp.StartListeningAsync(), Times.Once);
Assert.That(_client.IQStarted, Is.True);
}
[Test]
public async Task StartIQAsync_ShouldSendCorrectCommand()
{
await _client.StartIQAsync();

[Test]
public async Task StopIQTest()
{
//Arrange
await ConnectAsyncTest();
_mockTcp.Verify(x => x.WriteAsync(It.IsAny<byte[]>()), Times.AtLeastOnce);
}

//act
await _client.StopIQAsync();
[Test]
public async Task ChangeFrequencyAsync_ShouldSendBytes()
{
await _client.ChangeFrequencyAsync(1000000, 1);

//assert
//No exception thrown
_updMock.Verify(tcp => tcp.StopListening(), Times.Once);
Assert.That(_client.IQStarted, Is.False);
_mockTcp.Verify(x => x.WriteAsync(It.IsAny<byte[]>()), Times.AtLeastOnce);
}
}

//TODO: cover the rest of the NetSdrClient code here
}
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=NatashaTymchenko_NetSdrClient&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=NatashaTymchenko_NetSdrClient)
# Лабораторні з реінжинірингу (8×)
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=ppanchen_NetSdrClient&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=ppanchen_NetSdrClient)
[![Coverage](https://sonarcloud.io/api/project_badges/measure?project=ppanchen_NetSdrClient&metric=coverage)](https://sonarcloud.io/summary/new_code?id=ppanchen_NetSdrClient)
Expand Down