-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
62eec83
commit 5066a76
Showing
1 changed file
with
125 additions
and
125 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,125 +1,125 @@ | ||
// using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
// using Microsoft.EntityFrameworkCore; | ||
// using System.Collections.Generic; | ||
// using System.Threading.Tasks; | ||
// using CargoHub.Models; | ||
// using CargoHub.Services; | ||
|
||
// namespace CargoHub.Tests | ||
// { | ||
// [TestClass] | ||
// public class LocationStorageServiceTests | ||
// { | ||
// private LocationStorageService _locationService; | ||
// private AppDbContext _dbContext; | ||
|
||
// [TestInitialize] // Setup method that runs before each test | ||
// public void Setup() | ||
// { | ||
// var options = new DbContextOptionsBuilder<AppDbContext>() | ||
// .UseInMemoryDatabase(databaseName: "TestDatabase") // Create an in-memory database | ||
// .Options; | ||
|
||
// _dbContext = new AppDbContext(options); | ||
// _locationService = new LocationStorageService(_dbContext); | ||
// } | ||
|
||
// [TestCleanup] | ||
// public void Cleanup() | ||
// { | ||
// _dbContext.Database.EnsureDeleted(); | ||
// _dbContext.Dispose(); | ||
// } | ||
|
||
// [TestMethod] | ||
// public async Task GetLocationsInWarehouse_ShouldReturnCorrectLocations() | ||
// { | ||
// // Arrange | ||
// _dbContext.Locations.AddRange(new List<Location> | ||
// { | ||
// new Location { Name = "Location 1", Code = "LOC001", WarehouseId = 1 }, | ||
// new Location { Name = "Location 2", Code = "LOC002", WarehouseId = 2 }, | ||
// new Location { Name = "Location 3", Code = "LOC003", WarehouseId = 1 } | ||
// }); | ||
// await _dbContext.SaveChangesAsync(); | ||
|
||
// // Act | ||
// var result = await _locationService.GetLocationsInWarehouse(1); | ||
|
||
// // Assert | ||
// Assert.AreEqual(2, result.Count); // There should be 2 locations in warehouse 1 | ||
// Assert.IsTrue(result.Exists(l => l.Code == "LOC001")); | ||
// Assert.IsTrue(result.Exists(l => l.Code == "LOC003")); | ||
// } | ||
|
||
// [TestMethod] | ||
// public async Task AddRow_ShouldAddLocationToDatabase() | ||
// { | ||
// // Arrange | ||
// var newLocation = new Location | ||
// { | ||
// Name = "New Location", | ||
// Code = "LOC004", | ||
// WarehouseId = 3 | ||
// }; | ||
|
||
// // Act | ||
// var result = await _locationService.AddRow(newLocation); | ||
|
||
// // Assert | ||
// Assert.IsNotNull(result); | ||
// var location = await _dbContext.Locations.FindAsync(result); | ||
// Assert.IsNotNull(location); | ||
// Assert.AreEqual("New Location", location.Name); | ||
// } | ||
|
||
// [TestMethod] | ||
// public async Task GetRow_ShouldReturnCorrectLocation() | ||
// { | ||
// // Arrange | ||
// var location = new Location { Name = "Test Location", Code = "LOC005", WarehouseId = 4 }; | ||
// await _locationService.AddRow(location); | ||
|
||
// // Act | ||
// var result = await _locationService.GetRow<Location>(location.Id); | ||
|
||
// // Assert | ||
// Assert.IsNotNull(result); | ||
// Assert.AreEqual("Test Location", result.Name); | ||
// } | ||
|
||
// [TestMethod] | ||
// public async Task UpdateRow_ShouldUpdateExistingLocation() | ||
// { | ||
// // Arrange | ||
// var location = new Location { Name = "Old Name", Code = "LOC006", WarehouseId = 5 }; | ||
// await _locationService.AddRow(location); | ||
|
||
// var updatedLocation = new Location { Id = location.Id, Name = "New Name", Code = "LOC006", WarehouseId = 5 }; | ||
|
||
// // Act | ||
// var result = await _locationService.UpdateRow(location.Id, updatedLocation); | ||
|
||
// // Assert | ||
// Assert.IsTrue(result); | ||
// var updated = await _dbContext.Locations.FindAsync(location.Id); | ||
// Assert.AreEqual("New Name", updated.Name); | ||
// } | ||
|
||
// [TestMethod] | ||
// public async Task DeleteRow_ShouldRemoveLocationFromDatabase() | ||
// { | ||
// // Arrange | ||
// var location = new Location { Name = "Location to Delete", Code = "LOC007", WarehouseId = 6 }; | ||
// await _locationService.AddRow(location); | ||
|
||
// // Act | ||
// var result = await _locationService.DeleteRow<Location>(location.Id); | ||
|
||
// // Assert | ||
// Assert.IsTrue(result); | ||
// var deletedLocation = await _dbContext.Locations.FindAsync(location.Id); | ||
// Assert.IsNull(deletedLocation); | ||
// } | ||
// } | ||
// } | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using Microsoft.EntityFrameworkCore; | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
using CargoHub.Models; | ||
using CargoHub.Services; | ||
|
||
namespace CargoHub.Tests | ||
{ | ||
[TestClass] | ||
public class LocationStorageServiceTests | ||
{ | ||
private LocationStorageService _locationService; | ||
private AppDbContext _dbContext; | ||
|
||
[TestInitialize] // Setup method that runs before each test | ||
public void Setup() | ||
{ | ||
var options = new DbContextOptionsBuilder<AppDbContext>() | ||
.UseInMemoryDatabase(databaseName: "TestDatabase") // Create an in-memory database | ||
.Options; | ||
|
||
_dbContext = new AppDbContext(options); | ||
_locationService = new LocationStorageService(_dbContext); | ||
} | ||
|
||
[TestCleanup] | ||
public void Cleanup() | ||
{ | ||
_dbContext.Database.EnsureDeleted(); | ||
_dbContext.Dispose(); | ||
} | ||
|
||
[TestMethod] | ||
public async Task GetLocationsInWarehouse_ShouldReturnCorrectLocations() | ||
{ | ||
// Arrange | ||
_dbContext.Locations.AddRange(new List<Location> | ||
{ | ||
new Location { Name = "Location 1", Code = "LOC001", WarehouseId = 1 }, | ||
new Location { Name = "Location 2", Code = "LOC002", WarehouseId = 2 }, | ||
new Location { Name = "Location 3", Code = "LOC003", WarehouseId = 1 } | ||
}); | ||
await _dbContext.SaveChangesAsync(); | ||
|
||
// Act | ||
var result = await _locationService.GetLocationsInWarehouse(1); | ||
|
||
// Assert | ||
Assert.AreEqual(2, result.Count); // There should be 2 locations in warehouse 1 | ||
Assert.IsTrue(result.Exists(l => l.Code == "LOC001")); | ||
Assert.IsTrue(result.Exists(l => l.Code == "LOC003")); | ||
} | ||
|
||
[TestMethod] | ||
public async Task AddRow_ShouldAddLocationToDatabase() | ||
{ | ||
// Arrange | ||
var newLocation = new Location | ||
{ | ||
Name = "New Location", | ||
Code = "LOC004", | ||
WarehouseId = 3 | ||
}; | ||
|
||
// Act | ||
var result = await _locationService.AddRow(newLocation); | ||
|
||
// Assert | ||
Assert.IsNotNull(result); | ||
var location = await _dbContext.Locations.FindAsync(result); | ||
Assert.IsNotNull(location); | ||
Assert.AreEqual("New Location", location.Name); | ||
} | ||
|
||
[TestMethod] | ||
public async Task GetRow_ShouldReturnCorrectLocation() | ||
{ | ||
// Arrange | ||
var location = new Location { Name = "Test Location", Code = "LOC005", WarehouseId = 4 }; | ||
await _locationService.AddRow(location); | ||
|
||
// Act | ||
var result = await _locationService.GetRow<Location>(location.Id); | ||
|
||
// Assert | ||
Assert.IsNotNull(result); | ||
Assert.AreEqual("Test Location", result.Name); | ||
} | ||
|
||
[TestMethod] | ||
public async Task UpdateRow_ShouldUpdateExistingLocation() | ||
{ | ||
// Arrange | ||
var location = new Location { Name = "Old Name", Code = "LOC006", WarehouseId = 5 }; | ||
await _locationService.AddRow(location); | ||
|
||
var updatedLocation = new Location { Id = location.Id, Name = "New Name", Code = "LOC006", WarehouseId = 5 }; | ||
|
||
// Act | ||
var result = await _locationService.UpdateRow(location.Id, updatedLocation); | ||
|
||
// Assert | ||
Assert.IsTrue(result); | ||
var updated = await _dbContext.Locations.FindAsync(location.Id); | ||
Assert.AreEqual("New Name", updated.Name); | ||
} | ||
|
||
[TestMethod] | ||
public async Task DeleteRow_ShouldRemoveLocationFromDatabase() | ||
{ | ||
// Arrange | ||
var location = new Location { Name = "Location to Delete", Code = "LOC007", WarehouseId = 6 }; | ||
await _locationService.AddRow(location); | ||
|
||
// Act | ||
var result = await _locationService.DeleteRow<Location>(location.Id); | ||
|
||
// Assert | ||
Assert.IsTrue(result); | ||
var deletedLocation = await _dbContext.Locations.FindAsync(location.Id); | ||
Assert.IsNull(deletedLocation); | ||
} | ||
} | ||
} |