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.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); } [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(["cfb27fc2-54c2-4f07-8471-587d6b79b019", "7385c4e3-3c1e-4c5e-9926-8c0ea60dcb38"])] public async Task TransferDestinationToProductCrudTest(string[] transferDestIdAddressIdStrings) { var transferDestId = Guid.Parse(transferDestIdAddressIdStrings[0]); var addressId = Guid.Parse(transferDestIdAddressIdStrings[1]); var transferDest = TestHelper.CreateTransferDestination(transferDestId, addressId); await _signalRClient.PostDataAsync(SignalRTags.RemoveTransferDestinationToProduct, 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. } } }