Skip to content
Open

Lab5 #57

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
f5daa32
lab1
friezze Jun 1, 2026
2534516
lab1
friezze Jun 1, 2026
ba99cf9
lab1_readme_after_lr
friezze Jun 1, 2026
aa6e54d
minor fix 1
friezze Jun 1, 2026
5d5d3ac
minor fix 2
friezze Jun 1, 2026
710dc1e
minor fix 3
friezze Jun 1, 2026
a7ad091
minor fix 4
friezze Jun 1, 2026
31b9a38
minor fix 5
friezze Jun 1, 2026
16b27e3
Merge branch 'lab1' into lab2
friezze Jun 1, 2026
7c640bb
README update
friezze Jun 1, 2026
9c4804f
minor fix
friezze Jun 1, 2026
d4c95ba
Merge branch 'master' into lab1
friezze Jun 1, 2026
a4c6d7f
Merge branch 'lab1' into lab2
friezze Jun 1, 2026
25ac81f
minor fix
friezze Jun 1, 2026
96b82b8
Merge branch 'master' into lab1
friezze Jun 1, 2026
f7b3e84
minor fix
friezze Jun 1, 2026
db8bd43
Merge branch 'master' into lab1
friezze Jun 1, 2026
21b04e7
Merge branch 'lab1' into lab2
friezze Jun 1, 2026
890a88a
README update
friezze Jun 1, 2026
f25b5ed
enable test cover
friezze Jun 1, 2026
0fc6182
add test
friezze Jun 1, 2026
cec1494
add test - fix
friezze Jun 1, 2026
5730fd9
add test - fix v2
friezze Jun 1, 2026
fd1b757
README update
friezze Jun 1, 2026
b3812f7
README update
friezze Jun 1, 2026
4f1a682
README update
friezze Jun 1, 2026
b8bf4b2
duble remove
friezze Jun 1, 2026
5950a8c
Merge branch 'lab3' into lab4
friezze Jun 1, 2026
7b4d3a3
README UPDATE
friezze Jun 1, 2026
557ae51
README UPDATE v2
friezze Jun 1, 2026
38561a1
add broken test
friezze Jun 1, 2026
da8ee6a
add test forgot bad code fix it broke test
friezze Jun 1, 2026
8287c29
del bad code
friezze Jun 1, 2026
d8ce943
README update
friezze Jun 1, 2026
031b064
README update
friezze Jun 1, 2026
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
37 changes: 13 additions & 24 deletions .github/workflows/sonarcloud.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,54 +30,43 @@ name: SonarCloud analysis

on:
push:
branches: [ "master" ]
branches: ["master"]
pull_request:
branches: [ "master" ]
branches: ["master"]
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 }

- uses: actions/setup-dotnet@v4
with:
dotnet-version: '8.0.x'
dotnet-version: "8.0.x"

# 1) BEGIN: SonarScanner for .NET
- 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
dotnet sonarscanner begin /k:"friezze_ReengineeringCourse" /o:"friezze" /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
- 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
# 3) END: SonarScanner

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

- name: SonarScanner End
run: dotnet sonarscanner end /d:sonar.token="${{ secrets.SONAR_TOKEN }}"
shell: pwsh
2 changes: 2 additions & 0 deletions NetSdrClientApp/Messages/NetSdrMessageHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ public static class NetSdrMessageHelper
private const short _msgControlItemLength = 2; //2 byte, 16 bit
private const short _msgSequenceNumberLength = 2; //2 byte, 16 bit



public enum MsgTypes
{
SetControlItem,
Expand Down
12 changes: 6 additions & 6 deletions NetSdrClientApp/NetSdrClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ namespace NetSdrClientApp
{
public class NetSdrClient
{
private ITcpClient _tcpClient;
private IUdpClient _udpClient;
private readonly ITcpClient _tcpClient;
private readonly IUdpClient _udpClient;

public bool IQStarted { get; set; }

Expand Down Expand Up @@ -66,7 +66,7 @@ public async Task StartIQAsync()
return;
}

; var iqDataMode = (byte)0x80;
var iqDataMode = (byte)0x80;
var start = (byte)0x02;
var fifo16bitCaptureMode = (byte)0x01;
var n = (byte)1;
Expand Down Expand Up @@ -114,9 +114,9 @@ public async Task ChangeFrequencyAsync(long hz, int channel)
await SendTcpRequest(msg);
}

private void _udpClient_MessageReceived(object? sender, byte[] e)
private static void _udpClient_MessageReceived(object? sender, byte[] e)
{
NetSdrMessageHelper.TranslateMessage(e, out MsgTypes type, out ControlItemCodes code, out ushort sequenceNum, out byte[] body);
NetSdrMessageHelper.TranslateMessage(e, out _, out _, out _, out byte[] body);
var samples = NetSdrMessageHelper.GetSamples(16, body);

Console.WriteLine($"Samples recieved: " + body.Select(b => Convert.ToString(b, toBase: 16)).Aggregate((l, r) => $"{l} {r}"));
Expand Down Expand Up @@ -153,7 +153,7 @@ private async Task<byte[]> SendTcpRequest(byte[] msg)

private void _tcpClient_MessageReceived(object? sender, byte[] e)
{
//TODO: add Unsolicited messages handling here
//NOTE: add Unsolicited messages handling here
if (responseTaskSource != null)
{
responseTaskSource.SetResult(e);
Expand Down
15 changes: 3 additions & 12 deletions NetSdrClientApp/Networking/TcpClientWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,18 +84,10 @@ public async Task SendMessageAsync(byte[] data)
}
}

public async Task SendMessageAsync(string str)
public Task SendMessageAsync(string str)
{
var data = Encoding.UTF8.GetBytes(str);
if (Connected && _stream != null && _stream.CanWrite)
{
Console.WriteLine($"Message sent: " + data.Select(b => Convert.ToString(b, toBase: 16)).Aggregate((l, r) => $"{l} {r}"));
await _stream.WriteAsync(data, 0, data.Length);
}
else
{
throw new InvalidOperationException("Not connected to a server.");
}
return SendMessageAsync(data);
}

private async Task StartListeningAsync()
Expand Down Expand Up @@ -136,5 +128,4 @@ private async Task StartListeningAsync()
}
}
}

}
}
11 changes: 1 addition & 10 deletions NetSdrClientApp/Networking/UdpClientWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,7 @@ public void StopListening()

public void Exit()
{
try
{
_cts?.Cancel();
_udpClient?.Close();
Console.WriteLine("Stopped listening for UDP messages.");
}
catch (Exception ex)
{
Console.WriteLine($"Error while stopping: {ex.Message}");
}
StopListening();
}

public override int GetHashCode()
Expand Down
24 changes: 24 additions & 0 deletions NetSdrClientAppTests/ArchitectureTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using NetArchTest.Rules;
using NUnit.Framework;
using NetSdrClientApp.Networking;

namespace NetSdrClientAppTests
{
public class ArchitectureTests
{
[Test]
public void Messages_ShouldNotDependOn_Networking()
{
// Arrange
var result = Types.InAssembly(typeof(TcpClientWrapper).Assembly)
.That()
.ResideInNamespace("NetSdrClientApp.Messages")
.ShouldNot()
.HaveDependencyOn("NetSdrClientApp.Networking")
.GetResult();

// Assert
Assert.That(result.IsSuccessful, Is.True, "Messages namespace has a prohibited dependency on Networking.");
}
}
}
5 changes: 5 additions & 0 deletions NetSdrClientAppTests/NetSdrClientAppTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,13 @@

<ItemGroup>
<PackageReference Include="coverlet.collector" Version="6.0.0" />
<PackageReference Include="coverlet.msbuild" Version="10.0.1">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="Moq" Version="4.20.72" />
<PackageReference Include="NetArchTest.Rules" Version="1.3.2" />
<PackageReference Include="NUnit" Version="3.14.0" />
<PackageReference Include="NUnit.Analyzers" Version="3.9.0" />
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0" />
Expand Down
58 changes: 58 additions & 0 deletions NetSdrClientAppTests/NetSdrClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,4 +116,62 @@ public async Task StopIQTest()
}

//TODO: cover the rest of the NetSdrClient code here
[Test]
public async Task StartIQAsync_CalledTwice_ExecutesTwice()
{
// Arrange
await ConnectAsyncTest();

// Act
await _client.StartIQAsync();
await _client.StartIQAsync();

// Assert
_updMock.Verify(udp => udp.StartListeningAsync(), Times.Exactly(2));
}

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

// Act
await _client.StopIQAsync();
await _client.StopIQAsync();

// Assert
_updMock.Verify(udp => udp.StopListening(), Times.Exactly(2));
}

[Test]
public void Disconect_CalledTwice_ExecutesTwice()
{
// Act
_client.Disconect();
_client.Disconect();

// Assert
_tcpMock.Verify(tcp => tcp.Disconnect(), Times.Exactly(2));
}

[Test]
public async Task StartIQAsync_NeverCalls_TcpDisconnect()
{
// Act
await _client.StartIQAsync();

// Assert
_tcpMock.Verify(tcp => tcp.Disconnect(), Times.Never);
}

[Test]
public async Task StopIQAsync_NeverCalls_TcpDisconnect()
{
// Act
await _client.StopIQAsync();

// Assert
_tcpMock.Verify(tcp => tcp.Disconnect(), Times.Never);
}
}
51 changes: 51 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,57 @@
[![Maintainability Rating](https://sonarcloud.io/api/project_badges/measure?project=ppanchen_NetSdrClient&metric=sqale_rating)](https://sonarcloud.io/summary/new_code?id=ppanchen_NetSdrClient)



## Тут все пов'язане з виконанням самих лаб
# 1
![Чек сонарклауда з форка репозиторія](image.png)
![Бейджі](image-1.png)
Лінк на коміт
'''
https://github.com/friezze/ReengineeringCourse/commit/2534516c319a38d4aecd5d70a4e93c086961300
'''

# 2

До змін
![alt text](image-2.png)
Після
![alt text](image-3.png)
Може здатися дивним що їх стало більше але скоріше за все це тому що пофіксився білдер через зміни в які я лив в мейн і мерджив в гілку але сонар аналізував пуши в мейн а тік злиття. Але у будьякому випадку 8 фіксед.

# 3
До а якщо бути точним одразу після включення ковередж
![alt text](image-5.png)
Після(пушу тестів нових)
![alt text](image-6.png)

# 4
До

![alt text](image-4.png)

Після

![alt text](image-7.png)

Важливо зауважити що завдяки зменьшенню дублікатів піднявся і тест коверед бо коду стало банально меньше

![alt text](image-8.png)

# 5

Це так виглядає після додання порушення прав архітектури і самого порушення.
![alt text](image-9.png)


![alt text](image-10.png)

Після виправлення

![alt text](image-11.png)



Цей репозиторій використовується для курсу **реінжиніринг ПЗ**.
Мета — провести комплексний реінжиніринг спадкового коду NetSdrClient, включаючи рефакторинг архітектури, покращення якості коду, впровадження сучасних практик розробки та автоматизацію процесів контролю якості через CI/CD пайплайни.

Expand Down
Binary file added image-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added image-10.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added image-11.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added image-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added image-3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added image-4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added image-5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added image-6.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added image-7.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added image-8.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added image-9.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added image.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.