You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

90 lines
4.5 KiB

using Microsoft.ApplicationBlocks.Data;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Data;
using System.Diagnostics;
using System.Text;
namespace DealerSelection.WebApi.IntegrationTests.DetailsRequestController.BookingConfirmation;
[TestClass]
public class BookingConfirmationTest
{
[TestMethod]
public void TestMethod1()
{
var val = GetUTMDetails("", "utm_source");
val = GetUTMDetails("", "utm_medium");
val = GetUTMDetails("", "utm_campaign");
val = GetUTMDetails("", "utm_content");
return;
string apiUrl = "https://booking-dev.bajajauto.com/Details/BookingConfirmation";
var handler = new SocketsHttpHandler
{
PooledConnectionLifetime = TimeSpan.FromMinutes(15) // Recreate every 15 minutes
};
HttpClient client = new HttpClient(handler);
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Add("Authorization", "Bearer " + "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJodHRwOi8vc2NoZW1hcy54bWxzb2FwLm9yZy93cy8yMDA1LzA1L2lkZW50aXR5L2NsYWltcy9uYW1laWRlbnRpZmllciI6ImVlMTJlM2Q5Y2I5YTRkYzZhZjM1OTk5MzRjYzQxNTJiIiwiaHR0cDovL3NjaGVtYXMubWljcm9zb2Z0LmNvbS93cy8yMDA4LzA2L2lkZW50aXR5L2NsYWltcy9yb2xlIjoiQWRtaW4iLCJleHAiOjE2OTQzNDM5NzYsImlzcyI6Imh0dHBzOi8vYm9va2luZy1kZXYuYmFqYWphdXRvLmNvbS8iLCJhdWQiOiJodHRwczovL3d3dy5rdG0tdWF0Mi5iYWphamF1dG8uY29tLyJ9.Rg5miSU6IVPNpGDNwW3tQwoEVHw_Dr0iMgZQI5ArM7c");
client.DefaultRequestHeaders.Add("cache-control", "no-cache");
client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
Uri requestUri = new Uri(apiUrl);
string bookConnectionString = "user id=sqlAdmin;password=bFLW43%p40^;Data Source=mc-5f2bf602-449a-48b2-ae5a-5901-sql.database.windows.net,1433;Database=Booking;";
int buId = 1;
string transactionalsql = $"select BookingId, RecordId from tbl_transaction_details where Buid={buId} AND BookingId <>'0' AND Status <> 'Successful' order by RecordId asc";
DataTable bookingobjDataTable = SqlHelper.ExecuteDataset(bookConnectionString, CommandType.Text, transactionalsql).Tables[0];
var stopwatch = new Stopwatch();
stopwatch.Start();
Console.WriteLine($"Bulk Testing started at : {DateTime.Now}.");
List <Task> tasks = new List<Task>();
if (bookingobjDataTable != null & bookingobjDataTable.Rows != null)
{
foreach (DataRow row in bookingobjDataTable.Rows)
{
string recordId = Convert.ToString(row["RecordId"]);
string bookingId = Convert.ToString(row["BookingId"]);
string data = "{\r\n \"buId\": "+buId+",\r\n \"recordId\": "+ recordId + ",\r\n \"bookingId\": \""+ bookingId + "\",\r\n \"paymentTransactionStatus\": \"success\",\r\n \"amountPaid\": \"1\",\r\n \"paymentTransactionId\": \"Test-"+ recordId + "\",\r\n \"paymentType\": \"Card\",\r\n \"cardName\": \"VISA\"\r\n}";
Console.WriteLine($"BuId: {buId} , BookingId: {bookingId} , RecordId: {recordId} Processed");
BookingController(client, requestUri, data);
//tasks.Add(BookingController(client, requestUri, data));
}
}
//It will execute all the tasks concurrently
Task.WhenAll(tasks);
stopwatch.Stop();
Console.WriteLine($"Processing of {bookingobjDataTable.Rows.Count} BookingId Done in {stopwatch.ElapsedMilliseconds / 1000.0} Seconds");
}
public static async Task BookingController(HttpClient client, Uri requestUri, string data)
{
var response = await client.PostAsync(requestUri, new StringContent(data, Encoding.UTF8, "application/json"));
}
private string GetUTMDetails(string referrerUrl, string utmName)
{
referrerUrl = "https://www.triumphmotorcyclesindia.com/?utm_medium=cpc&utm_campaign=Sok_TriumphSpeed400_PMAX_Leads_02082023&utm_id=20423312638&adgroup=&utm_customdetails=AssetGroup1&utm_term=&utm_source_platform=x&utm_customdetails1=Speed_Booking_D2C&utm_customdetails2=Display_Google&gad=1&gclid=CjwKCAjwsKqoBhBPEiwALrrqiP8FJ2m-dbUdgg7GRZE2t71BmNcCQ3q6mHce20EP24Yg3iikzk1ceRoCW18QAvD_BwE";
Uri bUri = new Uri(referrerUrl);
var query = bUri.Query.Replace("?", "");
var queryValues = query.Split('&').Select(q => q.Split('='))
.ToDictionary(k => k[0], v => v[1]);
if (queryValues.ContainsKey(utmName))
return queryValues[utmName];
return "";
}
}