Implement GetTransfersByDriverUserIdAsync; Add GetTransfersByDriver tests...

This commit is contained in:
Loretta 2024-07-02 19:25:51 +02:00
parent b61f978706
commit 49f64e50fb
2 changed files with 24 additions and 1 deletions

View File

@ -411,10 +411,30 @@ namespace TIAM.Database.Test
Assert.IsNotNull(transfer.TransferToDrivers[0].Car);
Assert.AreEqual(transfer.OrderId, 1);
Assert.IsTrue(transfer.Id == transferId, "transfer.Id != transferId");
}
[DataTestMethod]
[DataRow(["4CBAED43-2465-4D99-84F1-C8BC6B7025F7", "71392CFD-FB9C-45C1-9540-7BE3782CF26A"])]
public async Task GetTransfersByDriver_ReturnsTransfers_WhenHasTransfers(string[] driverUserIdUserProductMappingIdString)
{
var driverUserId = Guid.Parse(driverUserIdUserProductMappingIdString[0]);
var userProductMappingId = Guid.Parse(driverUserIdUserProductMappingIdString[1]);
var transfers = await Dal.GetTransfersByUserProductMappingIdAsync(userProductMappingId);
Assert.IsNotNull(transfers);
Assert.IsTrue(transfers.Count > 0);
Assert.IsNotNull(transfers.All(x => x.TransferToDrivers.Any(ttd => ttd.UserProductMappingId == userProductMappingId)));
var count = transfers.Count;
transfers = await Dal.GetTransfersByDriverUserIdAsync(driverUserId);
Assert.IsNotNull(transfers);
Assert.IsTrue(transfers.Count == count);
Assert.IsNotNull(transfers.All(x => x.TransferToDrivers.Any(ttd => ttd.UserProductMappingId == userProductMappingId)));
}
[DataTestMethod]
[DataRow("273EFE3C-D19F-4C2A-BF19-7397DC835C60")]
public void GetTransferDestionationById_ReturnsTransferDestination_WhenHasAddressRelation(string transferDestinationIdString)

View File

@ -57,6 +57,9 @@ namespace TIAM.Database.DataLayers.Admins
public Task<List<Transfer>> GetTransfersByFilterAsync(CriteriaOperator criteriaOperator) => SessionAsync(ctx => (ctx.GetTransfers().AppendWhere(new CriteriaToExpressionConverter(), criteriaOperator) as IQueryable<Transfer>)!.ToList());
public Task<List<Transfer>> GetTransfersByDriverUserIdAsync(Guid driverUserId)
=> SessionAsync(ctx => ctx.GetTransfers().Where(x => x.TransferToDrivers.Any(ttd => ttd.UserProductMapping.UserId == driverUserId)).ToList());
public Task<List<Transfer>> GetTransfersByUserProductMappingIdAsync(Guid userProductMappingId)
=> SessionAsync(ctx => ctx.GetTransfers().Where(x => x.TransferToDrivers.Any(ttd => ttd.UserProductMappingId == userProductMappingId)).ToList());