<commit_before>﻿// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Web.Http;
using System.Xml.Linq;
using Microsoft.Azure.WebJobs.Host;
using Microsoft.Azure.WebJobs.Script.Tests.Properties;
using Microsoft.Azure.WebJobs.Script.WebHost;
using Microsoft.Azure.WebJobs.Script.WebHost.Models;
using Microsoft.ServiceBus;
using Microsoft.ServiceBus.Messaging;
using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Blob;
using Microsoft.WindowsAzure.Storage.Queue;
using Microsoft.WindowsAzure.Storage.Table;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Xunit;

namespace Microsoft.Azure.WebJobs.Script.Tests
{
    [Trait("Category", "E2E")]
    public class SamplesEndToEndTests : IClassFixture<SamplesEndToEndTests.TestFixture>
    {
        private TestFixture _fixture;

        public SamplesEndToEndTests(TestFixture fixture)
        {
            _fixture = fixture;
        }

        [Fact]
        public async Task EventHubTrigger()
        {
            TestHelpers.ClearFunctionLogs("EventHubTrigger");

            // write 3 events
            List<EventData> events = new List<EventData>();
            string[] ids = new string[3];
            for (int i = 0; i < 3; i++)
            {
                ids[i] = Guid.NewGuid().ToString();
                JObject jo = new JObject
                {
                    { "value", ids[i] }
                };
                events.Add(new EventData(Encoding.UTF8.GetBytes(jo.ToString(Formatting.None))));
            }

            string connectionString = Environment.GetEnvironmentVariable("AzureWebJobsEventHubSender");
            ServiceBusConnectionStringBuilder builder = new ServiceBusConnectionStringBuilder(connectionString);
            string eventHubName;
            if (!string.IsNullOrWhiteSpace(builder.EntityPath))
            {
                eventHubName = builder.EntityPath;
            }
            else
            {
                eventHubName = Environment.GetEnvironmentVariable("AzureWebJobsEventHubPath");
            }

            var eventHubClient = EventHubClient.CreateFromConnectionString(connectionString, eventHubName);
            await eventHubClient.SendBatchAsync(events);

            string logs = null;
            await TestHelpers.Await(() =>
            {
                // wait for all 3 of the unique IDs send
                // above have been processed
                logs = string.Join("\r\n", TestHelpers.GetFunctionLogsAsync("EventHubTrigger", throwOnNoLogs: false).Result);
                return ids.All(p => logs.Contains(p));
            });

            Assert.True(logs.Contains("IsArray true"));
        }

        [Fact]<commit_msg>Fixing the EventHubTrigger test<commit_after>﻿// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Web.Http;
using System.Xml.Linq;
using Microsoft.Azure.WebJobs.Host;
using Microsoft.Azure.WebJobs.Script.Tests.Properties;
using Microsoft.Azure.WebJobs.Script.WebHost;
using Microsoft.Azure.WebJobs.Script.WebHost.Models;
using Microsoft.ServiceBus;
using Microsoft.ServiceBus.Messaging;
using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Blob;
using Microsoft.WindowsAzure.Storage.Queue;
using Microsoft.WindowsAzure.Storage.Table;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Xunit;

namespace Microsoft.Azure.WebJobs.Script.Tests
{
    [Trait("Category", "E2E")]
    public class SamplesEndToEndTests : IClassFixture<SamplesEndToEndTests.TestFixture>
    {
        private TestFixture _fixture;

        public SamplesEndToEndTests(TestFixture fixture)
        {
            _fixture = fixture;
        }

        [Fact]
        public async Task EventHubTrigger()
        {
            TestHelpers.ClearFunctionLogs("EventHubTrigger");

            // write 3 events
            List<EventData> events = new List<EventData>();
            string[] ids = new string[3];
            for (int i = 0; i < 3; i++)
            {
                ids[i] = Guid.NewGuid().ToString();
                JObject jo = new JObject
                {
                    { "value", ids[i] }
                };
                events.Add(new EventData(Encoding.UTF8.GetBytes(jo.ToString(Formatting.None))));
            }

            string connectionString = Environment.GetEnvironmentVariable("AzureWebJobsEventHubSender");
            ServiceBusConnectionStringBuilder builder = new ServiceBusConnectionStringBuilder(connectionString);            
            EventHubClient eventHubClient;
            if (!string.IsNullOrWhiteSpace(builder.EntityPath))
            {
                eventHubClient = EventHubClient.CreateFromConnectionString(connectionString);
            }
            else
            {
                string eventHubPath = Environment.GetEnvironmentVariable("AzureWebJobsEventHubPath");
                eventHubClient = EventHubClient.CreateFromConnectionString(connectionString, eventHubPath);
            }

            await eventHubClient.SendBatchAsync(events);

            string logs = null;
            await TestHelpers.Await(() =>
            {
                // wait for all 3 of the unique IDs send
                // above have been processed
                logs = string.Join("\r\n", TestHelpers.GetFunctionLogsAsync("EventHubTrigger", throwOnNoLogs: false).Result);
                return ids.All(p => logs.Contains(p));
            });

            Assert.True(logs.Contains("IsArray true"));
        }

        [Fact]
{'fraction_non_alphanumeric': 0.09406422315926045, 'fraction_numerical': 0.0022705157314304248, 'mean_word_length': 2.4375696767001114, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 13, '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': '7583254', 'n_tokens_mistral': 1621, 'n_tokens_neox': 1579, 'n_words': 348}