<commit_before>﻿// Copyright 2007-2008 The Apache Software Foundation.
// 
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use 
// this file except in compliance with the License. You may obtain a copy of the 
// License at 
// 
//     http://www.apache.org/licenses/LICENSE-2.0 
// 
// Unless required by applicable law or agreed to in writing, software distributed 
// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 
// CONDITIONS OF ANY KIND, either express or implied. See the License for the 
// specific language governing permissions and limitations under the License.
namespace MassTransit.Transports.RabbitMq.Tests
{
    using System;
    using System.IO;
    using System.Text;
    using NUnit.Framework;
    using Serialization;

    [TestFixture]
    public class RabbitMqAddressSpecs
    {
        Uri _address = new Uri("rabbitmq://localhost/dru");
        [Test]
        public void AddressSpec()
        {
            var addr = new RabbitMqEndpointAddress(_address);
            Assert.AreEqual(new Uri("amqp-0-8://localhost:5672/dru"), addr.RabbitMqAddress);
        }

        [Test]
        public void Send()
        {
            var t = new RabbitMqTransport(new RabbitMqEndpointAddress(_address));
            t.Send((s)=>
            {
                var b = Encoding.UTF8.GetBytes("dru");
                s.Write(b, 0,b.Length);
            });
        }

        [Test]
        public void Receive()
        {
            var t = new RabbitMqTransport(new RabbitMqEndpointAddress(new Uri("rabbitmq://localhost/dru")));
            t.Receive(s=>
            {
                return ss =>
                {
                    var buff = new byte[3];
                    ss.Read(buff, 0, buff.Length);
                    var name = Encoding.UTF8.GetString(buff);
                    Assert.AreEqual("dru", name);
                    Console.WriteLine(name);
                };
            });
        }

        [Test]
        public void EndpointSend()
        {
            var addr = new RabbitMqEndpointAddress(_address);

            IMessageSerializer ser = new XmlMessageSerializer();

            var msg = new BugsBunny() {Food = "Carrot"};

            using (var stream = new MemoryStream())
            {
                ser.Serialize(stream, msg);
            }
            var e = new RabbitMqEndpoint(addr, ser, new RabbitMqTransport(addr), null);
            e.Send(new BugsBunny() {Food = "Carrot"});
        }

        [Test]
        public void EndpointReceive()
        {
            var addr = new RabbitMqEndpointAddress(_address);

            IMessageSerializer ser = new XmlMessageSerializer();

           
            var e = new RabbitMqEndpoint(addr, ser, new RabbitMqTransport(addr), null);
            e.Receive(o=>
            {
                return b =>
                {
                    var bb = (BugsBunny) b;
                    Console.WriteLine(bb.Food);
                };<commit_msg>Tests requiring RabbitMQ are now Integration<commit_after>﻿// Copyright 2007-2008 The Apache Software Foundation.
// 
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use 
// this file except in compliance with the License. You may obtain a copy of the 
// License at 
// 
//     http://www.apache.org/licenses/LICENSE-2.0 
// 
// Unless required by applicable law or agreed to in writing, software distributed 
// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 
// CONDITIONS OF ANY KIND, either express or implied. See the License for the 
// specific language governing permissions and limitations under the License.
namespace MassTransit.Transports.RabbitMq.Tests
{
    using System;
    using System.IO;
    using System.Text;
    using NUnit.Framework;
    using Serialization;

    [TestFixture]
    public class RabbitMqAddressSpecs
    {
        Uri _address = new Uri("rabbitmq://localhost/dru");
        [Test]
        public void AddressSpec()
        {
            var addr = new RabbitMqEndpointAddress(_address);
            Assert.AreEqual(new Uri("amqp-0-8://localhost:5672/dru"), addr.RabbitMqAddress);
        }

		[Test, Category("Integration")]
        public void Send()
        {
            var t = new RabbitMqTransport(new RabbitMqEndpointAddress(_address));
            t.Send((s)=>
            {
                var b = Encoding.UTF8.GetBytes("dru");
                s.Write(b, 0,b.Length);
            });
        }

		[Test, Category("Integration")]
		public void Receive()
        {
            var t = new RabbitMqTransport(new RabbitMqEndpointAddress(new Uri("rabbitmq://localhost/dru")));
            t.Receive(s=>
            {
                return ss =>
                {
                    var buff = new byte[3];
                    ss.Read(buff, 0, buff.Length);
                    var name = Encoding.UTF8.GetString(buff);
                    Assert.AreEqual("dru", name);
                    Console.WriteLine(name);
                };
            });
        }

		[Test, Category("Integration")]
        public void EndpointSend()
        {
            var addr = new RabbitMqEndpointAddress(_address);

            IMessageSerializer ser = new XmlMessageSerializer();

            var msg = new BugsBunny() {Food = "Carrot"};

            using (var stream = new MemoryStream())
            {
                ser.Serialize(stream, msg);
            }
            var e = new RabbitMqEndpoint(addr, ser, new RabbitMqTransport(addr), null);
            e.Send(new BugsBunny() {Food = "Carrot"});
        }

		[Test, Category("Integration")]
        public void EndpointReceive()
        {
            var addr = new RabbitMqEndpointAddress(_address);

            IMessageSerializer ser = new XmlMessageSerializer();

           
            var e = new RabbitMqEndpoint(addr, ser, new RabbitMqTransport(addr), null);
            e.Receive(o=>
            {
                return b =>
                {
                    var bb = (BugsBunny) b;
                    Console.WriteLine(bb.Food);
                };
{'fraction_non_alphanumeric': 0.10105949470252648, 'fraction_numerical': 0.007497962510187449, 'mean_word_length': 1.7246891651865008, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '536079', 'n_tokens_mistral': 1713, 'n_tokens_neox': 1576, 'n_words': 453}