<commit_before>﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Threading.Tasks;
using Newtonsoft.Json;
using System.Net.Http;
using System.Text;
using System.Net.Http.Headers;

namespace PortiLog.Service.Tests
{
    [TestClass]
    public class UnitTest1
    {
        [TestMethod]
        public async Task TestMethod1()
        {
            DumpData dumpData = new DumpData();
            dumpData.DeviceId = "abcdeviceid";
            dumpData.ApplicationName = "service2test";
            dumpData.ApplicationVersion = "0.1";
            dumpData.Entries = new System.Collections.Generic.List<Entry>();
            dumpData.Entries.Add(new Entry() { Id = 1, Created = DateTime.Now, Message = "my message123" });
            await PostAsync<object, DumpData>(null, dumpData);        
        }

        public static async Task<T> JsonDeserializeObjectAsync<T>(string sValue)
        {
            var result = await Task.Factory.StartNew<T>(() => { return JsonConvert.DeserializeObject<T>(sValue); });
            return result;
        }

        public static async Task<string> JsonSerializeObjectAsync<T>(T value)
        {
            var result = await Task.Factory.StartNew<string>(() => { return JsonConvert.SerializeObject(value); });
            return result;
        }

        public async Task<T> PostAsync<T, PT>(string token, PT tPostData)
        {
            var postData = await JsonSerializeObjectAsync(tPostData);
            var result = await PostAsync<T>(token, postData);
            return result;
        }

        public async Task<T> PostAsync<T>(string token, string postData)
        {
            try
            {
                using (var client = new HttpClient())
                {
                    client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                    //var url = await CreateUrlAsync(token);
                    var url = "http://localhost/logging2/api/logging";
                    
                    var decodedUrl = Uri.EscapeUriString(url);
                    StringContent postContent = new StringContent(postData, Encoding.UTF8, "application/json");
                    using (var response = await client.PostAsync(decodedUrl, postContent))
                    {
                        response.EnsureSuccessStatusCode();
                        var content = await response.Content.ReadAsStringAsync();
                        var value = await JsonDeserializeObjectAsync<T>(content);
                        return value;
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
                //Logger.Error("ServerService_PostAsync failed", ex);
                //throw new Models.ServerException(strings.ServerError, ex);
            }
        }
    }
}<commit_msg>rest service test<commit_after>﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Threading.Tasks;
using Newtonsoft.Json;
using System.Net.Http;
using System.Text;
using System.Net.Http.Headers;

namespace PortiLog.Service.Tests
{
    [TestClass]
    public class UnitTest1
    {
        [TestMethod]
        public async Task TestMethod1()
        {
            DumpData dumpData = new DumpData();
            dumpData.DeviceId = "abcdeviceid";
            dumpData.ApplicationName = "service2test";
            dumpData.ApplicationVersion = "0.1";
            dumpData.Entries = new System.Collections.Generic.List<Entry>();
            dumpData.Entries.Add(new Entry() { Id = 1, Created = DateTime.Now, Message = "my message123" });
            var client = new ServiceClient("http://localhost/logging2");
            await client.PostDumpData(dumpData);     
        }

       
    }
}
{'fraction_non_alphanumeric': 0.09832197168327216, 'fraction_numerical': 0.00550603041426324, 'mean_word_length': 1.9505027068832173, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4031963', 'n_tokens_mistral': 985, 'n_tokens_neox': 956, 'n_words': 213}