using AyCode.Core.Enums; using AyCode.Core.Helpers; using AyCode.Core.Loggers; 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.Entities.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. } } }