using AyCode.Core.Consts; using AyCode.Core.Enums; using AyCode.Core.Helpers; using AyCode.Core.Loggers; using AyCode.Services.Loggers; using AyCode.Services.SignalRs; using Azure; using DevExpress.Data.Filtering; using DevExpress.Data.Linq; using DevExpress.Data.Linq.Helpers; using Newtonsoft.Json; using SkiaSharp; using TIAM.Core.Consts; using TIAM.Core.Enums; using TIAM.Core.Loggers; using TIAM.Database.Test; using TIAM.Entities.Drivers; using TIAM.Entities.ServiceProviders; using TIAM.Entities.Transfers; using TIAM.Entities.Users; using TIAM.Models.Dtos.Users; using TIAM.Services; using TIAMWebApp.Shared.Application.Services; using TIAMWebApp.Shared.Application.Utility; namespace Tiam.Services.Client.Tests { [TestClass] public class SignalRClientTest //: TestModelBase { private const string CompanyIdString = "3587F169-683C-4EEE-BCB5-E8D57F8C6DCE"; private readonly AdminSignalRClient _signalRClient = new(new List { new SignaRClientLogItemWriter(AppType.TestUnit, LogLevel.Detail, nameof(SignalRClientTest)) }); [TestInitialize] public void TestInitialize() { } [TestCleanup] public void TearDown() { } [DataTestMethod] [DataRow(CompanyIdString)] public async Task GetCompanyTest_ReturnCompany_WhenHasCompany(string companyIdString) { var companyId = Guid.Parse(companyIdString); var company = await _signalRClient.GetByIdAsync(SignalRTags.GetCompany, companyId); Assert.IsNotNull(company); } [DataTestMethod] [DataRow(CompanyIdString)] public async Task GetCompanyAsyncTest_ReturnCompany_WhenHasCompany(string companyIdString) { Company? company = null; var companyId = Guid.Parse(companyIdString); await _signalRClient.GetByIdAsync(SignalRTags.GetCompany, response => { Assert.IsNotNull(response.ResponseData); Assert.IsTrue(response.Status == SignalResponseStatus.Success); company = response.ResponseData; return Task.CompletedTask; }, companyId); await TaskHelper.WaitToAsync(() => company != null, 5000, 50); Assert.IsNotNull(company); } [TestMethod] public async Task GetAllCompanyTest_ReturnCompanies_WhenHasCompanies() { var companies = await _signalRClient.GetAllAsync>(SignalRTags.GetCompanies); Assert.IsNotNull(companies); Assert.IsTrue(companies.Count > 0); } [TestMethod] public async Task GetAllCompanyAsyncTest_ReturnCompanies_WhenHasCompanies() { List? companies = null; await _signalRClient.GetAllAsync>(SignalRTags.GetCompanies, response => { Assert.IsNotNull(response.ResponseData); Assert.IsTrue(response.Status == SignalResponseStatus.Success); companies = response.ResponseData; return Task.CompletedTask; }); await TaskHelper.WaitToAsync(() => companies != null, 5000, 50); Assert.IsNotNull(companies); Assert.IsTrue(companies.Count > 0); } [TestMethod] public async Task GetAllUserProductMappingsTest_ReturnProductMappings_WhenHasProductMappings() { var userProductMapping = await _signalRClient.GetAllAsync>(SignalRTags.GetAllUserProductMappings); Assert.IsNotNull(userProductMapping); Assert.IsTrue(userProductMapping.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. } [DataTestMethod] [DataRow(["e7528722-355a-4f8b-8571-7d7abf7ee109", "273EFE3C-D19F-4C2A-BF19-7397DC835C60", "05C147F8-8A87-47DD-BE1D-64EDA7A6A612"])] public async Task TransferDestinationToProductCrudTest(string[] transferDestinationToProductIdTransferDestIdProductIdStrings) { var transferDestinationToProductId = Guid.Parse(transferDestinationToProductIdTransferDestIdProductIdStrings[0]); var transferDestId = Guid.Parse(transferDestinationToProductIdTransferDestIdProductIdStrings[1]); var productId = Guid.Parse(transferDestinationToProductIdTransferDestIdProductIdStrings[2]); var transferDestinationToProduct = TestHelper.CreateTransferDestinationToProduct(transferDestinationToProductId, transferDestId, productId); await _signalRClient.PostDataAsync(SignalRTags.RemoveTransferDestinationToProduct, transferDestinationToProduct); transferDestinationToProduct = await _signalRClient.PostDataAsync(SignalRTags.CreateTransferDestinationToProduct, transferDestinationToProduct); Assert.IsNotNull(transferDestinationToProduct); transferDestinationToProduct = await _signalRClient.GetByIdAsync(SignalRTags.GetTransferDestinationToProductById, transferDestinationToProductId); Assert.IsNotNull(transferDestinationToProduct); Assert.IsNotNull(transferDestinationToProduct.TransferDestination); transferDestinationToProduct.Price = 20000; transferDestinationToProduct = await _signalRClient.PostDataAsync(SignalRTags.UpdateTransferDestinationToProduct, transferDestinationToProduct); Assert.IsNotNull(transferDestinationToProduct); Assert.IsNotNull(transferDestinationToProduct.TransferDestination); Assert.IsTrue((int)transferDestinationToProduct.Price == 20000); Assert.IsTrue(transferDestinationToProduct.Id == transferDestinationToProductId, "transferDestinationToProduct.Id != transferDestinationToProductId"); var transferDestinationToProducts = await _signalRClient.GetByIdAsync>(SignalRTags.GetTransferDestinationToProductsByTransferDestinationId, transferDestId); Assert.IsNotNull(transferDestinationToProducts); Assert.IsTrue(transferDestinationToProducts.Count > 0); Assert.IsTrue(transferDestinationToProducts.All(x => x.TransferDestinationId == transferDestId)); transferDestinationToProducts = await _signalRClient.GetByIdAsync>(SignalRTags.GetTransferDestinationToProductsByProductId, productId); Assert.IsNotNull(transferDestinationToProducts); Assert.IsTrue(transferDestinationToProducts.Count > 0); Assert.IsTrue(transferDestinationToProducts.All(x => x.ProductId == productId)); await _signalRClient.PostDataAsync(SignalRTags.RemoveTransferDestinationToProduct, transferDestinationToProduct); //mielőbb kitöröljük, h ne maradjon szemét a db-ben - J. transferDestinationToProduct = await _signalRClient.GetByIdAsync(SignalRTags.GetTransferDestinationToProductById, transferDestinationToProductId); Assert.IsNull(transferDestinationToProduct); //a korábbi törlés miatt NULL kell legyen - J. } [DataTestMethod] public async Task FilterExpressionTest_WhenTransfersFiletered() { var userId = Guid.Parse("540271F6-C604-4C16-8160-D5A7CAFEDF00"); var statuses = new List() { TransferStatusType.OrderConfirmed, TransferStatusType.AssignedToDriver, TransferStatusType.Finished }; var converter = new CriteriaToExpressionConverter(); var criteriaString = CriteriaOperator.FromLambda(x => x.UserId == userId && statuses.Contains(x.TransferStatusType)).ToString(); //var criteria = CriteriaOperator.Parse(criteriaString); //_signalRDataSource.AsQueryable().Expression. //var filteredData = new List().AsQueryable().AppendWhere(converter, criteria) as IQueryable; var transfers = await _signalRClient.GetTransfersByFilterText(criteriaString); //var transfers = await _signalRClient.GetAllAsync>(SignalRTags.GetTransfersByExpression, [userId, filteredData!.Expression]); Assert.IsNotNull(transfers); Assert.IsTrue(transfers.Count > 0); Assert.IsTrue(transfers.All(x => statuses.Contains(x.TransferStatusType))); //var converter = new CriteriaToExpressionConverter(); ////CriteriaOperator critOps = CriteriaOperator.Parse(tdashboard.EmployeeFilter); //var criteriaString = CriteriaOperator.FromLambda(x => x.LuggageCount == 1).ToString(); ////var json = criteria.AsQueryable().Expression.ToJson(); ////criteria = JsonConvert.DeserializeObject(json); //var criteria = CriteriaOperator.Parse(criteriaString); ////_signalRDataSource.AsQueryable().Expression. //var filteredData = _signalRDataSource.AsQueryable().AppendWhere(converter, criteria) as IQueryable; //Assert.IsNotNull(filteredData); //var filteredTransfers = _signalRDataSource.AsQueryable().Provider.CreateQuery(filteredData.Expression).ToList(); //Assert.IsNotNull(filteredTransfers); //Assert.IsTrue(filteredTransfers.All(x => x.LuggageCount == 1)); } [TestMethod] public async Task GetAllTransfersTest_ReturnTransfers_WhenHasTransfers() { var transfers = await _signalRClient.GetTransfers(); Assert.IsNotNull(transfers); Assert.IsTrue(transfers.Count > 0); } [TestMethod] [DataRow("540271F6-C604-4C16-8160-D5A7CAFEDF00")] public async Task GetTransfersByUserIdTest_ReturnTransfers_WhenAllTransfersByUserId(string userIdString) { var userId = Guid.Parse(userIdString); var transfers = await _signalRClient.GetTransfersByUserId(userId); Assert.IsNotNull(transfers); Assert.IsTrue(transfers.Count > 0); Assert.IsTrue(transfers.All(x => x.UserId == userId)); } [TestMethod] [DataRow("540271F6-C604-4C16-8160-D5A7CAFEDF00")] public async Task ChangePasswordTest_ReturnErrorCode_WhenErrorCodeIsUnset(string userIdString) { var userId = Guid.Parse(userIdString); var errorCode = await _signalRClient.UserChangePassword(userId, "Asdasd123456", "Asdasd123456"); Assert.IsTrue(errorCode == AcErrorCode.Unset, errorCode.ToString()); } [TestMethod] [DataRow("540271F6-C604-4C16-8160-D5A7CAFEDF00")] public async Task ChangePasswordTest_ReturnErrorCode_WhenErrorCodeIsNotUnset(string userIdString) { var userId = Guid.Parse(userIdString); var changePasswordDto = new ChangePasswordDto(userId, "ffdsdergtyf22A", "Asdasd123456"); var errorCode = await _signalRClient.UserChangePassword(changePasswordDto); Assert.IsTrue(errorCode == AcErrorCode.WrongLoginData, errorCode.ToString()); changePasswordDto.UserId = Guid.Parse("110271F6-C604-4C16-8160-D5A7CAFEDF11"); errorCode = await _signalRClient.UserChangePassword(changePasswordDto); Assert.IsTrue(errorCode == AcErrorCode.EntityIsNull, errorCode.ToString()); changePasswordDto.NewPassword = "a"; errorCode = await _signalRClient.UserChangePassword(changePasswordDto); Assert.IsTrue(errorCode == AcErrorCode.PasswordIsTooShort, errorCode.ToString()); } [TestMethod] [DataRow("")] public async Task GetAllCarsAndDriversByProductIdAsyncTest_ReturnCarsAndDrivers_WhenHasCarsAndDrivers(string productIdString) { var cars = new List(); var drivers = new List(); var productId = TiamConstClient.TransferProductId; //Guid.Parse(productIdString); await _signalRClient.GetAllCarsAndDriversByProductIdAsync(productId, cars, drivers); await TaskHelper.WaitToAsync(() => drivers.Count > 0, 5000, 50); Assert.IsTrue(cars.Count > 0); Assert.IsTrue(drivers.Count > 0); Assert.IsTrue(cars.All(car => drivers.Any(driver => driver.Id == car.UserProductMappingId && driver.ProductId == productId))); Assert.IsTrue(drivers.All(driver => driver.ProductId == productId && cars.Any(car => car.UserProductMappingId == driver.Id))); } } }