Unit Testing - DanielAceroJuarez/TMSWebAPI GitHub Wiki
Unit Testing
Unit Testing
Unit tests ensure the reliability and correctness of the system. The TMS Web API uses NUnit for unit testing.
Running Tests
-
Navigate to the Tests directory:
cd TMSWebAPI.Tests
-
Run the tests:
dotnet test
Test Cases
ShipmentRepositoryTests
Tests for the ShipmentRepository
class.
AddShipment_ShouldAddShipment
Tests that a shipment is added correctly.
[Test]
public void AddShipment_ShouldAddShipment()
{
var shipment = new Shipment(1, "New York", "Los Angeles", DateTime.Now, 100);
_repository.Add(shipment);
var retrievedShipment = _repository.Get(1);
Assert.AreEqual(shipment, retrievedShipment);
}
GetShipment_ShouldReturnShipment
Tests that a shipment is retrieved correctly.
[Test]
public void GetShipment_ShouldReturnShipment()
{
var shipment = new Shipment(2, "Chicago", "Houston", DateTime.Now, 200);
_repository.Add(shipment);
var retrievedShipment = _repository.Get(2);
Assert.AreEqual(shipment, retrievedShipment);
}