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

  1. Navigate to the Tests directory:

    cd TMSWebAPI.Tests
    
  2. 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);
}

Additional test cases should be added for updating and deleting shipments.