<commit_before>using Api.ApplicationServices;
using Api.Data;
using Api.Controllers;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Linq;
using System.Threading.Tasks;
using System;
using Api.ViewModels;
using RabbitMQ.Client;
using RabbitMQ.Client.Events;
using System.Text;

namespace tests.Integration
{
    [TestClass]
    public class NewProductQueueTests
    {
        //private string productQueueConnection = "tcp://localhost:25672";

        [TestMethod]
        public void Smoke_Connection_To_Queue()
        {
            // var factory = new ConnectionFactory() { HostName = "localhost" };
            // using (var connection = factory.CreateConnection())
            // using (var channel = connection.CreateModel())
            // {
            //     channel.QueueDeclare(queue: "hello",
            //                     durable: true,
            //                     exclusive: false,
            //                     autoDelete: false,
            //                     arguments: null);

            //     string message = "Hello World!";
            //     var body = Encoding.UTF8.GetBytes(message);

            //     channel.BasicPublish(exchange: "",
            //                         routingKey: "hello",
            //                         basicProperties: null,
            //                         body: body);
            //     Console.WriteLine(" [x] Sent {0}", message);
            // }

            
            var factory = new ConnectionFactory() { HostName = "localhost" };
            using(var connection = factory.CreateConnection())
            using(var channel = connection.CreateModel())
            {

                channel.ExchangeDeclare(exchange: "newproduct", type: "fanout");

                var message = "Tomate";
                var body = Encoding.UTF8.GetBytes(message);

                channel.BasicPublish(exchange: "newproduct",
                                    routingKey: "",
                                    basicProperties: null,
                                    body: body);
            }
        }
        

        [TestMethod]
        public void Smoke_Read_From_Queue()
        {
            var factory = new ConnectionFactory() { HostName = "localhost" };
            using (var connection = factory.CreateConnection())
            using (var channel = connection.CreateModel())
            {
                channel.QueueDeclare(queue: "hello",
                                     durable: true,
                                     exclusive: false,
                                     autoDelete: false,
                                     arguments: null);

                var consumer = new EventingBasicConsumer(channel);
                consumer.Received += (model, ea) =>
                {
                    var body = ea.Body;
                    var message = Encoding.UTF8.GetString(body);
                    Console.WriteLine(" [x] Received {0}", message);

                    channel.BasicAck(deliveryTag: ea.DeliveryTag, multiple: false);
                };
                channel.BasicConsume(queue: "hello",
                                     autoAck: false,
                                     consumer: consumer);

                Console.WriteLine(" Press [enter] to exit.");
                Console.ReadLine();
            }


            //Ler de exchange
            //var factory = new ConnectionFactory() { HostName = "localhost" };
            // using(var connection = factory.CreateConnection())
            // using(var channel = connection.CreateModel())
            // {
            //     channel.ExchangeDeclare(exchange: "logs", type: "fanout");

            //     var queueName = channel.QueueDeclare().QueueName;
            //     channel.QueueBind(queue: queueName,
            //                     exchange: "logs",
            //                     routingKey: "");

            //     Console.WriteLine(" [*] Waiting for logs.");

            //     var consumer = new EventingBasicConsumer(channel);
            //     consumer.Received += (model, ea) =>
            //     {
            //         var body = ea.Body;
            //         var message = Encoding.UTF8.GetString(body);
            //         Console.WriteLine(" [x] {0}", message);
            //     };
            //     channel.BasicConsume(queue: queueName,
            //                         autoAck: true,
            //                         consumer: consumer);

            //     Console.WriteLine(" Press [enter] to exit.");
            //     Console.ReadLine();
            // }
        }
    }

}<commit_msg>Lendo de exchange em rabbit<commit_after>using Api.ApplicationServices;
using Api.Data;
using Api.Controllers;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Linq;
using System.Threading.Tasks;
using System;
using Api.ViewModels;
using RabbitMQ.Client;
using RabbitMQ.Client.Events;
using System.Text;

namespace tests.Integration
{
    [TestClass]
    public class NewProductQueueTests
    {
        //private string productQueueConnection = "tcp://localhost:25672";

        [TestMethod]
        public void Smoke_Connection_To_Queue()
        {
            // var factory = new ConnectionFactory() { HostName = "localhost" };
            // using (var connection = factory.CreateConnection())
            // using (var channel = connection.CreateModel())
            // {
            //     channel.QueueDeclare(queue: "hello",
            //                     durable: true,
            //                     exclusive: false,
            //                     autoDelete: false,
            //                     arguments: null);

            //     string message = "Hello World!";
            //     var body = Encoding.UTF8.GetBytes(message);

            //     channel.BasicPublish(exchange: "",
            //                         routingKey: "hello",
            //                         basicProperties: null,
            //                         body: body);
            //     Console.WriteLine(" [x] Sent {0}", message);
            // }

            
            var factory = new ConnectionFactory() { HostName = "localhost" };
            using(var connection = factory.CreateConnection())
            using(var channel = connection.CreateModel())
            {

                channel.ExchangeDeclare(exchange: "newproduct", type: "fanout");

                var message = "Tomate";
                var body = Encoding.UTF8.GetBytes(message);

                channel.BasicPublish(exchange: "newproduct",
                                    routingKey: "",
                                    basicProperties: null,
                                    body: body);
            }
        }
        

        [TestMethod]
        public void Smoke_Read_From_Queue()
        {
            // var factory = new ConnectionFactory() { HostName = "localhost" };
            // using (var connection = factory.CreateConnection())
            // using (var channel = connection.CreateModel())
            // {
            //     channel.QueueDeclare(queue: "hello",
            //                          durable: true,
            //                          exclusive: false,
            //                          autoDelete: false,
            //                          arguments: null);

            //     var consumer = new EventingBasicConsumer(channel);
            //     consumer.Received += (model, ea) =>
            //     {
            //         var body = ea.Body;
            //         var message = Encoding.UTF8.GetString(body);
            //         Console.WriteLine(" [x] Received {0}", message);

            //         channel.BasicAck(deliveryTag: ea.DeliveryTag, multiple: false);
            //     };
            //     channel.BasicConsume(queue: "hello",
            //                          autoAck: false,
            //                          consumer: consumer);

            //     Console.WriteLine(" Press [enter] to exit.");
            //     Console.ReadLine();
            // }


            //Ler de exchange
            var factory = new ConnectionFactory() { HostName = "localhost" };
            using(var connection = factory.CreateConnection())
            using(var channel = connection.CreateModel())
            {
                channel.ExchangeDeclare(exchange: "logs", type: "fanout");

                var queueName = channel.QueueDeclare().QueueName;
                channel.QueueBind(queue: queueName,
                                exchange: "logs",
                                routingKey: "");

                Console.WriteLine(" [*] Waiting for logs.");

                var consumer = new EventingBasicConsumer(channel);
                consumer.Received += (model, ea) =>
                {
                    var body = ea.Body;
                    var message = Encoding.UTF8.GetString(body);
                    Console.WriteLine(" [x] {0}", message);
                };
                channel.BasicConsume(queue: queueName,
                                    autoAck: true,
                                    consumer: consumer);

                Console.WriteLine(" Press [enter] to exit.");
                Console.ReadLine();
            }
        }
    }

}
{'fraction_non_alphanumeric': 0.10635344367325147, 'fraction_numerical': 0.0025627335824879873, 'mean_word_length': 1.1771269177126917, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 38, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7308623', 'n_tokens_mistral': 2199, 'n_tokens_neox': 2088, 'n_words': 464}