From 7779379bd495a13d77b9c6723f26976eb59eaaa6 Mon Sep 17 00:00:00 2001 From: Loretta Date: Wed, 26 Jun 2024 15:40:58 +0200 Subject: [PATCH] Implement TransferDestination SignalR crud test; --- TIAM.Database.Test/AdminDalTest.cs | 31 +- TIAM.Database.Test/TestHelper.cs | 37 +++ TIAM.Database/DataLayers/Admins/AdminDal.cs | 4 +- .../Transfers/TransferDbSetExtensions.cs | 4 +- TIAM.Services/SignalRTags.cs | 13 +- .../User/SysAdmins/ManageTransfers.razor | 6 +- .../Controllers/TransferDataAPIController.cs | 273 +++++++++++------- .../SignalRClientTest.cs | 41 +++ .../SignalRDataSourceTest.cs | 2 + .../Tiam.Services.Client.Tests.csproj | 1 + 10 files changed, 263 insertions(+), 149 deletions(-) create mode 100644 TIAM.Database.Test/TestHelper.cs diff --git a/TIAM.Database.Test/AdminDalTest.cs b/TIAM.Database.Test/AdminDalTest.cs index 31c69fdc..6a9a282d 100644 --- a/TIAM.Database.Test/AdminDalTest.cs +++ b/TIAM.Database.Test/AdminDalTest.cs @@ -4,7 +4,6 @@ using Newtonsoft.Json; using TIAM.Core.Enums; using TIAM.Database.DataLayers.Admins; using TIAM.Database.DbContexts.Admins; -using TIAM.Entities.Addresses; using TIAM.Entities.Drivers; using TIAM.Entities.Emails; using TIAM.Entities.Products; @@ -13,6 +12,7 @@ using TIAM.Models.Dtos.Users; using TIAM.Entities.Transfers; using AyCode.Core.Extensions; using TIAM.Entities.ServiceProviders; +using TIAM.Entities.Addresses; namespace TIAM.Database.Test { @@ -536,32 +536,9 @@ namespace TIAM.Database.Test var transferDestId = Guid.Parse(transferDestIdaddressIdStrings[0]); var addressId = Guid.Parse(transferDestIdaddressIdStrings[1]); - var name = "Liszt Ferenc repülÅ‘tér"; - var address = "Budapest, Liszt Ferenc tér"; - var modifiedAddress = "modified; " + address; - await Dal.RemoveTransferDestinationAsync(transferDestId, true); //kitöröljük a szemetet, ha korábbról bentmaradt - J. - var transferDest = new TransferDestination - { - Id = transferDestId, - AddressId = addressId, - Name = name, - Description = name + "description", - Price = 15000, - //Price2 = 21000, - //Price3 = 23000, - //PriceType = PriceType.Fix, - Address = new Address - { - Id = addressId, - AddressText = address, - IsValid = false, - IsHelper = false, - Latitude = new Random().NextDouble() + 42d, - Longitude = new Random().NextDouble() + 19d - } - }; + var transferDest = TestHelper.CreateTransferDestination(transferDestId, addressId); Assert.IsTrue(await Dal.AddTransferDestinationAsync(transferDest)); Assert.IsNotNull(transferDest); @@ -571,6 +548,8 @@ namespace TIAM.Database.Test Assert.IsNotNull(transferDest); Assert.IsNotNull(transferDest.Address); + var modifiedAddress = "modified; " + transferDest.Address.AddressText; + transferDest.Price = 20000; transferDest.Address.AddressText = modifiedAddress; @@ -590,6 +569,8 @@ namespace TIAM.Database.Test transferDest = Dal.GetTransferDestinationById(transferDestId); Assert.IsNull(transferDest); //a korábbi törlés miatt NULL kell legyen - J. } + + #endregion Transfer #region EmailMessage diff --git a/TIAM.Database.Test/TestHelper.cs b/TIAM.Database.Test/TestHelper.cs new file mode 100644 index 00000000..b5f82bd1 --- /dev/null +++ b/TIAM.Database.Test/TestHelper.cs @@ -0,0 +1,37 @@ +using TIAM.Entities.Addresses; +using TIAM.Entities.Transfers; + +namespace TIAM.Database.Test; + +public static class TestHelper +{ + public static TransferDestination CreateTransferDestination(Guid transferDestId, Guid addressId) + { + var name = "Liszt Ferenc repülÅ‘tér"; + var address = "Budapest, Liszt Ferenc tér"; + + var transferDest = new TransferDestination + { + Id = transferDestId, + AddressId = addressId, + Name = name, + Description = name + "description", + Price = 15000, + //Price2 = 21000, + //Price3 = 23000, + //PriceType = PriceType.Fix, + AddressString = address, + Address = new Address + { + Id = addressId, + AddressText = address, + IsValid = false, + IsHelper = false, + Latitude = null, + Longitude = null + } + }; + + return transferDest; + } +} \ No newline at end of file diff --git a/TIAM.Database/DataLayers/Admins/AdminDal.cs b/TIAM.Database/DataLayers/Admins/AdminDal.cs index 8b0a0f2d..ff8190ba 100644 --- a/TIAM.Database/DataLayers/Admins/AdminDal.cs +++ b/TIAM.Database/DataLayers/Admins/AdminDal.cs @@ -75,8 +75,8 @@ namespace TIAM.Database.DataLayers.Admins public Task AddTransferDestinationAsync(TransferDestination transferDestination) => TransactionAsync(ctx => ctx.AddTransferDestination(transferDestination)); public Task UpdateTransferDestinationAsync(TransferDestination transferDestination) => TransactionAsync(ctx => ctx.UpdateTransferDestination(transferDestination)); - public Task RemoveTransferDestinationAsync(TransferDestination transferDestination, bool removeAddress = false) => TransactionAsync(ctx => ctx.RemoveTransferDestination(transferDestination, removeAddress)); - public Task RemoveTransferDestinationAsync(Guid transferDestinationId, bool removeAddress = false) => TransactionAsync(ctx => ctx.RemoveTransferDestination(transferDestinationId, removeAddress)); + public Task RemoveTransferDestinationAsync(TransferDestination transferDestination, bool removeAddress) => TransactionAsync(ctx => ctx.RemoveTransferDestination(transferDestination.Id, removeAddress)); + public Task RemoveTransferDestinationAsync(Guid transferDestinationId, bool removeAddress) => TransactionAsync(ctx => ctx.RemoveTransferDestination(transferDestinationId, removeAddress)); #endregion TransferDestination #region TransferToDriver diff --git a/TIAM.Database/DbSets/Transfers/TransferDbSetExtensions.cs b/TIAM.Database/DbSets/Transfers/TransferDbSetExtensions.cs index d8622d2d..440a2667 100644 --- a/TIAM.Database/DbSets/Transfers/TransferDbSetExtensions.cs +++ b/TIAM.Database/DbSets/Transfers/TransferDbSetExtensions.cs @@ -30,20 +30,20 @@ public static class TransferDbSetExtensions public static IQueryable GetTransfers(this ITransferDbSet ctx) => ctx.Transfers; + #region TransferDestination public static TransferDestination? GetTransferDestinationById(this ITransferDestinationDbSet ctx, Guid transferDestinationId) => ctx.TransferDestinations.FirstOrDefault(x => x.Id == transferDestinationId); public static IQueryable GetTransferDestinations(this ITransferDestinationDbSet ctx) => ctx.TransferDestinations; - #region TransferDestination public static bool AddTransferDestination(this ITransferDestinationDbSet ctx, TransferDestination transferDestination) => ctx.TransferDestinations.Add(transferDestination).State == EntityState.Added; public static bool UpdateTransferDestination(this ITransferDestinationDbSet ctx, TransferDestination transferDestination) => ctx.TransferDestinations.Update(transferDestination).State == EntityState.Modified; - public static bool RemoveTransferDestination(this ITransferDestinationDbSet ctx, TransferDestination transferDestination, bool removeAddress) + private static bool RemoveTransferDestination(this ITransferDestinationDbSet ctx, TransferDestination transferDestination, bool removeAddress) { if (removeAddress) ctx.Addresses.Remove(transferDestination.Address); diff --git a/TIAM.Services/SignalRTags.cs b/TIAM.Services/SignalRTags.cs index d486d58c..6bea0067 100644 --- a/TIAM.Services/SignalRTags.cs +++ b/TIAM.Services/SignalRTags.cs @@ -77,14 +77,15 @@ public class SignalRTags : AcSignalRTags public const int GetProductsById = 76; public const int GetAllProducts = 77; - public const int CreateTransferDestination = 80; - public const int UpdateTransferDestination = 81; - public const int DeleteTransferDestination = 82; //set permissions to 0 - public const int GetAllTransferDestinations = 83; - + public const int GetTransferDestinationById = 80; + public const int GetAllTransferDestinations = 81; + public const int CreateTransferDestination = 82; + public const int UpdateTransferDestination = 83; + public const int RemoveTransferDestination = 84; //set permissions to 0 + public const int CreateTransferDestinationToProduct = 90; public const int UpdateTransferDestinationToProduct = 91; - public const int DeleteTransferDestinationToProduct = 92; //set permissions to 0 + public const int RemoveTransferDestinationToProduct = 92; //set permissions to 0 public const int GetAllTransferDestinationToProducts = 93; public const int GetTransferDestinationToProductByProductId = 94; public const int GetTransferDestinationToProductByTransferDestinationId = 95; diff --git a/TIAMSharedUI/Pages/User/SysAdmins/ManageTransfers.razor b/TIAMSharedUI/Pages/User/SysAdmins/ManageTransfers.razor index bf3272c5..a6b3ba45 100644 --- a/TIAMSharedUI/Pages/User/SysAdmins/ManageTransfers.razor +++ b/TIAMSharedUI/Pages/User/SysAdmins/ManageTransfers.razor @@ -395,10 +395,8 @@ if (SelectedCategories.Count > 0) TagBox_ValuesChanged(SelectedCategories); - if(!SelectedCategories.Any()) - SelectedCategories = [Statuses.FirstOrDefault(x => x.StatusValue == (byte)TransferStatusType.Finished)!]; - - + // if(!SelectedCategories.Any()) + // SelectedCategories = [Statuses.FirstOrDefault(x => x.StatusValue == (byte)TransferStatusType.Finished)!]; // var filterTransferStatusType = Statuses.FirstOrDefault(x => x.StatusValue == (byte)TransferStatusType.Finished)!; diff --git a/TIAMWebApp/Server/Controllers/TransferDataAPIController.cs b/TIAMWebApp/Server/Controllers/TransferDataAPIController.cs index 44960abd..618b3d98 100644 --- a/TIAMWebApp/Server/Controllers/TransferDataAPIController.cs +++ b/TIAMWebApp/Server/Controllers/TransferDataAPIController.cs @@ -27,19 +27,6 @@ namespace TIAMWebApp.Server.Controllers [Route("api/v1/[controller]")] public class TransferDataAPIController : ControllerBase { - //private static readonly TransferDestination[] Names = new TransferDestination[] - //{ - // /*"Castle of Buda", "Hungarian National Museum", "Parliament of Hungary", "Heroes square", "Gellert Hill", "Margaret Island"*/ - // new() { DestinationId = 1, DestinationName = "Airport", DestinationDescription = "International airport of Budapest", DestinationLatitude = 42.234444f, DestinationLongitude = 39.100010f }, - // new() { DestinationId = 2, DestinationName = "Castle of Buda", DestinationDescription = "International airport of Budapest", DestinationLatitude = 42.234444f, DestinationLongitude = 39.100010f }, - // new() { DestinationId = 3, DestinationName = "Hungarian National Museum", DestinationDescription = "International airport of Budapest", DestinationLatitude = 42.234444f, DestinationLongitude = 39.100010f }, - // new() { DestinationId = 4, DestinationName = "Parliament of Hungary", DestinationDescription = "International airport of Budapest", DestinationLatitude = 42.234444f, DestinationLongitude = 39.100010f }, - // new() { DestinationId = 5, DestinationName = "Heroes square", DestinationDescription = "International airport of Budapest", DestinationLatitude = 42.234444f, DestinationLongitude = 39.100010f }, - // new() { DestinationId = 6, DestinationName = "Gellert Hill", DestinationDescription = "International airport of Budapest", DestinationLatitude = 42.234444f, DestinationLongitude = 39.100010f }, - // new() { DestinationId = 6, DestinationName = "Margaret Island", DestinationDescription = "International airport of Budapest", DestinationLatitude = 42.234444f, DestinationLongitude = 39.100010f } - - //}; - private readonly AdminDal _adminDal; private readonly TIAM.Core.Loggers.ILogger _logger; private readonly TransferBackendService _transferBackendService; @@ -66,6 +53,16 @@ namespace TIAMWebApp.Server.Controllers return await _adminDal.Context.TransferDestinations.ToListAsync(); } + //[Authorize] + //[HttpGet] + //[Route(APIUrls.GetTransferDriversByTransferIdRouteName)] + [SignalR(SignalRTags.GetTransferDestinationById)] + public TransferDestination? GetTransferDestinationById(Guid transferDestinationId) + { + var transferDestination = _adminDal.GetTransferDestinationById(transferDestinationId); + return transferDestination; + } + [AllowAnonymous] [HttpGet] [Route("GetTransferDestinationByCoordinates")] @@ -85,124 +82,180 @@ namespace TIAMWebApp.Server.Controllers [AllowAnonymous] [HttpPost] [Route(APIUrls.CreateTransferDestinationRouteName)] - public async Task CreateTransferDestination([FromBody] JsonElement serializedTransferDestinationModel) + [SignalR(SignalRTags.CreateTransferDestination)] + public async Task CreateTransferDestination([FromBody] TransferDestination transferDestination) { _logger.Info(@"CreateTransferDestination called!"); - if (string.IsNullOrEmpty(serializedTransferDestinationModel.GetRawText())) + + var isSuccess = false; + if (string.IsNullOrEmpty(transferDestination.Name) || string.IsNullOrEmpty(transferDestination.AddressString)) { - return BadRequest("SerializedTramsferDestinationWizardModel is required"); + var logText = $"string.IsNullOrEmpty(transferDestination.Name) || string.IsNullOrEmpty(transferDestination.AddressString); Name: {transferDestination.Name}; AddressString: {transferDestination.AddressString}"; + + _logger.Error(logText); } else { - TransferDestination? transferDestination = JObject.Parse(serializedTransferDestinationModel.GetRawText()).ToObject(); - - if (transferDestination != null) - { - - var id = Guid.NewGuid(); - //TransferDestination transferDestination = new TransferDestination(id, transferDestinationModel.Name, transferDestinationModel.Description, transferDestinationModel.AddressString); - - - if (string.IsNullOrEmpty(transferDestination.Name) || string.IsNullOrEmpty(transferDestination.AddressString)) - { - return BadRequest("Invalid request"); - } - else - { - _logger.Debug(transferDestination.ToString()); - - //await _transferDestinationDal.Context.TransferDestinations.AddAsync(transferDestination); - await _adminDal.AddTransferDestinationAsync(transferDestination); - return Ok(transferDestination); - } - } - else - { - return BadRequest("Invalid request"); - } - - + if (transferDestination.Id.IsNullOrEmpty()) transferDestination.Id = Guid.NewGuid(); + isSuccess = await _adminDal.AddTransferDestinationAsync(transferDestination); } - + return isSuccess ? transferDestination : null; } [AllowAnonymous] [HttpPost] [Route(APIUrls.UpdateTransferDestinationRouteName)] - public async Task UpdateTransferDestination([FromBody] JsonElement serializedTransferDestination) + [SignalR(SignalRTags.UpdateTransferDestination)] + public async Task UpdateTransferDestination([FromBody] TransferDestination transferDestination) { _logger.Info(@"UpdateTransferDestination called!"); - if (string.IsNullOrEmpty(serializedTransferDestination.GetRawText())) + + var isSuccess = false; + if (transferDestination.Id.IsNullOrEmpty() || string.IsNullOrEmpty(transferDestination.Name) || string.IsNullOrEmpty(transferDestination.AddressString)) { - _logger.Error(@"Bad request!"); - return BadRequest("SerializedTramsferDestinationWizardModel is required"); - } - else - { - _logger.Info(@"Serialized model not empty!"); - TransferDestination? transferDestination = JObject.Parse(serializedTransferDestination.GetRawText()).ToObject(); - _logger.Info($@"TransferDestination to be updated: {serializedTransferDestination.GetRawText()}"); - _logger.Info($@"TransferDestination to be updated: {transferDestination.AddressString}"); - - - if (transferDestination != null) - { - - - //TransferDestination transferDestination = new TransferDestination(id, transferDestinationModel.Name, transferDestinationModel.Description, transferDestinationModel.AddressString); - - if (transferDestination.Id == Guid.Empty || string.IsNullOrEmpty(transferDestination.Name) || string.IsNullOrEmpty(transferDestination.AddressString)) - { - _logger.Error(@"Serialized model not empty, but bad request!"); - return BadRequest("Invalid request"); - } - else - { - - _logger.Info($@"TransferDestination to be updated: {transferDestination.Id}"); - _logger.Info($@"TransferDestination to be updated new name: {transferDestination.Name}"); - _logger.Info($@"TransferDestination to be updated new price: {transferDestination.Price}"); - //Console.WriteLine($"TransferDestination to be updated new price: {transferDestination.Price2}"); - //Console.WriteLine($"TransferDestination to be updated new price: {transferDestination.Price3}"); - //Console.WriteLine($"TransferDestination to be updated new priceType: {transferDestination.PriceType}"); - _logger.Info($@"TransferDestination to be updated new address: {transferDestination.AddressString}"); - _logger.Info($@"TransferDestination to be updated new description: {transferDestination.Description}"); - - //var dbTransferDestinationJson = _adminDal.GetTransferDestinationJsonById(transferDestination.Id); - //_logger.Info($"TransferDestination JSON to be updated: {dbTransferDestinationJson}"); - - //var dbTransferDestination = JObject.Parse(dbTransferDestinationJson).ToObject(); - - //var dbTransferDestination = _adminDal.GetTransferDestinationById(transferDestination.Id, true); - //if (dbTransferDestination.Id != Guid.Empty) - //{ - // dbTransferDestination.AddressId = transferDestination.AddressId; - // dbTransferDestination.Price = transferDestination.Price; - // dbTransferDestination.PriceType = transferDestination.PriceType; - // dbTransferDestination.Name = transferDestination.Name; - // dbTransferDestination.Description = transferDestination.Description; - // dbTransferDestination.AddressString = transferDestination.AddressString; - // dbTransferDestination.Address = transferDestination.Address; - - //} - - //await _transferDestinationDal.Context.TransferDestinations.AddAsync(transferDestination); - await _adminDal.UpdateTransferDestinationAsync(transferDestination); - return Ok(transferDestination); - } - } - else - { - return BadRequest("Invalid request"); - } - - + var logText = $"transferDestination.Id.IsNullOrEmpty() || string.IsNullOrEmpty(transferDestination.Name) || string.IsNullOrEmpty(transferDestination.AddressString); Id: {transferDestination.Id}; Name: {transferDestination.Name}; AddressString: {transferDestination.AddressString}"; + + _logger.Error(logText); } + else isSuccess = await _adminDal.UpdateTransferDestinationAsync(transferDestination); + return isSuccess ? transferDestination : null; } + //[Authorize] + //[HttpGet] + //[Route(APIUrls.GetTransferDriversByTransferIdRouteName)] + [SignalR(SignalRTags.RemoveTransferDestination)] + public async Task RemoveTransferDestination([FromBody] TransferDestination transferDestination) + { + var result = await _adminDal.RemoveTransferDestinationAsync(transferDestination, true); + return result ? transferDestination : null; + } + + + //[AllowAnonymous] + //[HttpPost] + //[Route(APIUrls.CreateTransferDestinationRouteName)] + //public async Task CreateTransferDestination([FromBody] JsonElement serializedTransferDestinationModel) + //{ + // _logger.Info(@"CreateTransferDestination called!"); + // if (string.IsNullOrEmpty(serializedTransferDestinationModel.GetRawText())) + // { + // return BadRequest("SerializedTramsferDestinationWizardModel is required"); + // } + // else + // { + // TransferDestination? transferDestination = JObject.Parse(serializedTransferDestinationModel.GetRawText()).ToObject(); + + // if (transferDestination != null) + // { + + // var id = Guid.NewGuid(); + // //TransferDestination transferDestination = new TransferDestination(id, transferDestinationModel.Name, transferDestinationModel.Description, transferDestinationModel.AddressString); + + + // if (string.IsNullOrEmpty(transferDestination.Name) || string.IsNullOrEmpty(transferDestination.AddressString)) + // { + // return BadRequest("Invalid request"); + // } + // else + // { + // _logger.Debug(transferDestination.ToString()); + + // //await _transferDestinationDal.Context.TransferDestinations.AddAsync(transferDestination); + // await _adminDal.AddTransferDestinationAsync(transferDestination); + // return Ok(transferDestination); + // } + // } + // else + // { + // return BadRequest("Invalid request"); + // } + + + // } + + + //} + + //[AllowAnonymous] + //[HttpPost] + //[Route(APIUrls.UpdateTransferDestinationRouteName)] + //public async Task UpdateTransferDestination([FromBody] JsonElement serializedTransferDestination) + //{ + // _logger.Info(@"UpdateTransferDestination called!"); + // if (string.IsNullOrEmpty(serializedTransferDestination.GetRawText())) + // { + // _logger.Error(@"Bad request!"); + // return BadRequest("SerializedTramsferDestinationWizardModel is required"); + // } + // else + // { + // _logger.Info(@"Serialized model not empty!"); + // TransferDestination? transferDestination = JObject.Parse(serializedTransferDestination.GetRawText()).ToObject(); + // _logger.Info($@"TransferDestination to be updated: {serializedTransferDestination.GetRawText()}"); + // _logger.Info($@"TransferDestination to be updated: {transferDestination.AddressString}"); + + + // if (transferDestination != null) + // { + + + // //TransferDestination transferDestination = new TransferDestination(id, transferDestinationModel.Name, transferDestinationModel.Description, transferDestinationModel.AddressString); + + // if (transferDestination.Id == Guid.Empty || string.IsNullOrEmpty(transferDestination.Name) || string.IsNullOrEmpty(transferDestination.AddressString)) + // { + // _logger.Error(@"Serialized model not empty, but bad request!"); + // return BadRequest("Invalid request"); + // } + // else + // { + + // _logger.Info($@"TransferDestination to be updated: {transferDestination.Id}"); + // _logger.Info($@"TransferDestination to be updated new name: {transferDestination.Name}"); + // _logger.Info($@"TransferDestination to be updated new price: {transferDestination.Price}"); + // //Console.WriteLine($"TransferDestination to be updated new price: {transferDestination.Price2}"); + // //Console.WriteLine($"TransferDestination to be updated new price: {transferDestination.Price3}"); + // //Console.WriteLine($"TransferDestination to be updated new priceType: {transferDestination.PriceType}"); + // _logger.Info($@"TransferDestination to be updated new address: {transferDestination.AddressString}"); + // _logger.Info($@"TransferDestination to be updated new description: {transferDestination.Description}"); + + // //var dbTransferDestinationJson = _adminDal.GetTransferDestinationJsonById(transferDestination.Id); + // //_logger.Info($"TransferDestination JSON to be updated: {dbTransferDestinationJson}"); + + // //var dbTransferDestination = JObject.Parse(dbTransferDestinationJson).ToObject(); + + // //var dbTransferDestination = _adminDal.GetTransferDestinationById(transferDestination.Id, true); + // //if (dbTransferDestination.Id != Guid.Empty) + // //{ + // // dbTransferDestination.AddressId = transferDestination.AddressId; + // // dbTransferDestination.Price = transferDestination.Price; + // // dbTransferDestination.PriceType = transferDestination.PriceType; + // // dbTransferDestination.Name = transferDestination.Name; + // // dbTransferDestination.Description = transferDestination.Description; + // // dbTransferDestination.AddressString = transferDestination.AddressString; + // // dbTransferDestination.Address = transferDestination.Address; + + // //} + + // //await _transferDestinationDal.Context.TransferDestinations.AddAsync(transferDestination); + // await _adminDal.UpdateTransferDestinationAsync(transferDestination); + // return Ok(transferDestination); + // } + // } + // else + // { + // return BadRequest("Invalid request"); + // } + + + // } + + + //} + [AllowAnonymous] [HttpPost] [Route(APIUrls.CreateTransferRouteName)] diff --git a/Tiam.Services.Client.Tests/SignalRClientTest.cs b/Tiam.Services.Client.Tests/SignalRClientTest.cs index 4b397c2c..5193707e 100644 --- a/Tiam.Services.Client.Tests/SignalRClientTest.cs +++ b/Tiam.Services.Client.Tests/SignalRClientTest.cs @@ -5,7 +5,9 @@ using AyCode.Services.Loggers; using AyCode.Services.SignalRs; using Azure; using TIAM.Core.Loggers; +using TIAM.Database.Test; using TIAM.Entities.ServiceProviders; +using TIAM.Entities.Transfers; using TIAM.Services; using TIAMWebApp.Shared.Application.Services; using TIAMWebApp.Shared.Application.Utility; @@ -88,5 +90,44 @@ namespace Tiam.Services.Client.Tests Assert.IsNotNull(companies); Assert.IsTrue(companies.Count > 0); } + + [DataTestMethod] + [DataRow(["cfb27fc2-54c2-4f07-8471-587d6b79b019", "7385c4e3-3c1e-4c5e-9926-8c0ea60dcb38"])] + public async Task TransferDestinationCrudTest(string[] transferDestIdaddressIdStrings) + { + var transferDestId = Guid.Parse(transferDestIdaddressIdStrings[0]); + var addressId = Guid.Parse(transferDestIdaddressIdStrings[1]); + + var transferDest = TestHelper.CreateTransferDestination(transferDestId, addressId); + + await _signalRClient.PostDataAsync(SignalRTags.RemoveTransferDestination, transferDest); + + transferDest = await _signalRClient.PostDataAsync(SignalRTags.CreateTransferDestination, transferDest); + Assert.IsNotNull(transferDest); + + transferDest = await _signalRClient.GetByIdAsync(SignalRTags.GetTransferDestinationById, transferDestId); + + Assert.IsNotNull(transferDest); + Assert.IsNotNull(transferDest.Address); + + var modifiedAddress = "modified; " + transferDest.Address.AddressText; + + transferDest.Price = 20000; + transferDest.Address.AddressText = modifiedAddress; + + transferDest = await _signalRClient.PostDataAsync(SignalRTags.UpdateTransferDestination, transferDest); + + Assert.IsNotNull(transferDest); + Assert.IsNotNull(transferDest.Address); + + Assert.IsTrue((int)transferDest.Price == 20000); + Assert.IsTrue(transferDest.Address.AddressText == modifiedAddress); + Assert.IsTrue(transferDest.Id == transferDestId, "transferDest.Id != transferDestId"); + + await _signalRClient.PostDataAsync(SignalRTags.RemoveTransferDestination, transferDest); //mielõbb kitöröljük, h ne maradjon szemét a db-ben - J. + + transferDest = await _signalRClient.GetByIdAsync(SignalRTags.GetTransferDestinationById, transferDestId); + Assert.IsNull(transferDest); //a korábbi törlés miatt NULL kell legyen - J. + } } } \ No newline at end of file diff --git a/Tiam.Services.Client.Tests/SignalRDataSourceTest.cs b/Tiam.Services.Client.Tests/SignalRDataSourceTest.cs index ee39a418..3821c7a4 100644 --- a/Tiam.Services.Client.Tests/SignalRDataSourceTest.cs +++ b/Tiam.Services.Client.Tests/SignalRDataSourceTest.cs @@ -14,6 +14,7 @@ using Newtonsoft.Json; using Newtonsoft.Json.Linq; using TIAM.Core.Loggers; using TIAM.Database.DataLayers.Admins; +using TIAM.Database.Test; using TIAM.Entities.ServiceProviders; using TIAM.Entities.Transfers; using TIAM.Services; @@ -80,6 +81,7 @@ namespace Tiam.Services.Client.Tests Assert.IsTrue(dbTransfer.LuggageCount == luggageCount); } + [DataTestMethod] public void FilterExpressionTest_WhenTransfersFiletered() { diff --git a/Tiam.Services.Client.Tests/Tiam.Services.Client.Tests.csproj b/Tiam.Services.Client.Tests/Tiam.Services.Client.Tests.csproj index 89d265b7..6bad5966 100644 --- a/Tiam.Services.Client.Tests/Tiam.Services.Client.Tests.csproj +++ b/Tiam.Services.Client.Tests/Tiam.Services.Client.Tests.csproj @@ -24,6 +24,7 @@ +