Skip to content
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
26 changes: 26 additions & 0 deletions .github/workflows/dotnet-core-master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,32 @@ jobs:
uses: actions/setup-dotnet@v3
with:
dotnet-version: 9.0.x
- name: Wait for MariaDB to be ready
run: |
echo "Waiting for MariaDB to be ready..."
for i in {1..30}; do
if docker exec mariadbtest mariadb -u root --password=secretpassword -e "SELECT 1" > /dev/null 2>&1; then
echo "MariaDB is ready!"
break
fi
echo "Waiting for MariaDB... ($i/30)"
sleep 2
done
- name: Load main DB dump
run: |
docker exec -i mariadbtest mariadb -h 127.0.0.1 -u root --password=secretpassword -e 'CREATE DATABASE IF NOT EXISTS `420_SDK`'
docker exec -i mariadbtest mariadb -h 127.0.0.1 -u root --password=secretpassword 420_SDK < main/420_SDK.sql
- name: Setup test database for handler integration tests
run: |
echo "Setting up test data for all handler test scenarios..."
docker exec -i mariadbtest mariadb -h 127.0.0.1 -u root --password=secretpassword 420_SDK < main/ServiceTrashInspectionPlugin.Integration.Test/Handlers/setup-test-database.sql
echo "Test database setup complete!"
- name: Verify test data setup
run: |
echo "Verifying test data was inserted..."
docker exec -i mariadbtest mariadb -u root --password=secretpassword -e "SELECT COUNT(*) as TrashInspectionCases_Count FROM 420_SDK.TrashInspectionCases;"
docker exec -i mariadbtest mariadb -u root --password=secretpassword -e "SELECT COUNT(*) as TrashInspections_Count FROM 420_SDK.TrashInspections;"
docker exec -i mariadbtest mariadb -u root --password=secretpassword -e "SELECT COUNT(*) as PluginConfigValues_Count FROM 420_SDK.PluginConfigurationValues WHERE Name LIKE 'TrashInspectionBaseSettings:%';"
- name: Install dependencies
run: dotnet restore eform-service-trash-inspection-plugin
- name: Build
Expand Down
26 changes: 26 additions & 0 deletions .github/workflows/dotnet-core-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,32 @@ jobs:
uses: actions/setup-dotnet@v3
with:
dotnet-version: 9.0.x
- name: Wait for MariaDB to be ready
run: |
echo "Waiting for MariaDB to be ready..."
for i in {1..30}; do
if docker exec mariadbtest mariadb -u root --password=secretpassword -e "SELECT 1" > /dev/null 2>&1; then
echo "MariaDB is ready!"
break
fi
echo "Waiting for MariaDB... ($i/30)"
sleep 2
done
- name: Load main DB dump
run: |
docker exec -i mariadbtest mariadb -h 127.0.0.1 -u root --password=secretpassword -e 'CREATE DATABASE IF NOT EXISTS `420_SDK`'
docker exec -i mariadbtest mariadb -h 127.0.0.1 -u root --password=secretpassword 420_SDK < main/420_SDK.sql
- name: Setup test database for handler integration tests
run: |
echo "Setting up test data for all handler test scenarios..."
docker exec -i mariadbtest mariadb -h 127.0.0.1 -u root --password=secretpassword 420_SDK < main/ServiceTrashInspectionPlugin.Integration.Test/Handlers/setup-test-database.sql
echo "Test database setup complete!"
- name: Verify test data setup
run: |
echo "Verifying test data was inserted..."
docker exec -i mariadbtest mariadb -u root --password=secretpassword -e "SELECT COUNT(*) as TrashInspectionCases_Count FROM 420_SDK.TrashInspectionCases;"
docker exec -i mariadbtest mariadb -u root --password=secretpassword -e "SELECT COUNT(*) as TrashInspections_Count FROM 420_SDK.TrashInspections;"
docker exec -i mariadbtest mariadb -u root --password=secretpassword -e "SELECT COUNT(*) as PluginConfigValues_Count FROM 420_SDK.PluginConfigurationValues WHERE Name LIKE 'TrashInspectionBaseSettings:%';"
- name: Install dependencies
run: dotnet restore eform-service-trash-inspection-plugin
- name: Build
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*
The MIT License (MIT)
Copyright (c) 2007 - 2025 Microting A/S
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/

using NUnit.Framework;
using ServiceTrashInspectionPlugin.Messages;

namespace ServiceTrashInspectionPlugin.Integration.Test.Handlers;

/// <summary>
/// Unit tests for EformParsedByServerHandler
///
/// The EformParsedByServerHandler is responsible for handling messages when an eForm is parsed by the server.
/// It updates the status of TrashInspectionCase to 70 when the case exists and status is below 70.
///
/// Expected behavior:
/// - When a case exists in SDK and TrashInspectionCase exists: status should be updated to 70
/// - When case status is already >= 70: status should remain unchanged
/// - When TrashInspectionCase doesn't exist: no update should occur
/// - When case doesn't exist in SDK: no update should occur
/// </summary>
[TestFixture]
public class EformParsedByServerHandlerTests
{
[SetUp]
public void Setup()
{
// Note: These tests require actual database and SDK setup due to the complexity of mocking
// eFormCore.Core and its dependencies. These tests serve as documentation of expected behavior
// and should be run as integration tests with proper test database setup.
}

/// <summary>
/// Test to verify that the message structure is valid
/// </summary>
[Test]
public void Message_CanBeCreatedWithCaseId()
{
// Arrange
var caseId = 12345;

// Act
var message = new EformParsedByServer(caseId);

// Assert
Assert.That(message.CaseId, Is.EqualTo(caseId));
}

/// <summary>
/// Test to verify message with different case ID values
/// </summary>
[Test]
[TestCase(1)]
[TestCase(999)]
[TestCase(123456)]
public void Message_HandlesVariousCaseIds(int caseId)
{
// Act
var message = new EformParsedByServer(caseId);

// Assert
Assert.That(message.CaseId, Is.EqualTo(caseId));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/*
The MIT License (MIT)
Copyright (c) 2007 - 2025 Microting A/S
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/

using System.Linq;
using System.Threading.Tasks;
using Microting.eFormTrashInspectionBase.Infrastructure.Data;
using Microting.eFormTrashInspectionBase.Infrastructure.Data.Entities;
using Moq;
using NUnit.Framework;
using ServiceTrashInspectionPlugin.Handlers;
using ServiceTrashInspectionPlugin.Infrastructure.Helpers;
using ServiceTrashInspectionPlugin.Messages;

namespace ServiceTrashInspectionPlugin.Integration.Test.Handlers;

/// <summary>
/// Unit tests for EformParsingErrorHandler
///
/// The EformParsingErrorHandler is responsible for handling messages when an eForm parsing error occurs.
/// It updates the status of TrashInspectionCase to 110 when the case exists and status is below 110.
///
/// Expected behavior:
/// - When TrashInspectionCase exists: status should be updated to 110 if below 110
/// - When case status is already >= 110: status should remain unchanged
/// - When TrashInspectionCase doesn't exist: no update should occur
/// </summary>
[TestFixture]
public class EformParsingErrorHandlerTests
{
[SetUp]
public void Setup()
{
// Note: Due to non-virtual methods in DbContextHelper, these tests require actual database setup.
// These tests serve as documentation of expected behavior and should be run as integration tests.
}

/// <summary>
/// Test to verify that the message structure is valid
/// </summary>
[Test]
public void Message_CanBeCreatedWithCaseId()
{
// Arrange
var caseId = 12345;

// Act
var message = new EformParsingError(caseId);

// Assert
Assert.That(message.CaseId, Is.EqualTo(caseId));
}

/// <summary>
/// Test to verify message with different case ID values
/// </summary>
[Test]
[TestCase(1)]
[TestCase(999)]
[TestCase(123456)]
public void Message_HandlesVariousCaseIds(int caseId)
{
// Act
var message = new EformParsingError(caseId);

// Assert
Assert.That(message.CaseId, Is.EqualTo(caseId));
}
}
Loading
Loading