<commit_before>﻿using NUnit.Framework;
using Msg.Infrastructure;
using System.Threading.Tasks;
using Msg.Domain;
using Version = Msg.Domain.Version;

namespace Msg.Acceptance.Tests
{
	[TestFixture]
	public class VersionNegotiation
	{
		[Test]
		public async Task Given_a_client_prefers_a_lower_version_than_the_version_the_server_prefers_When_negotiating_which_version_to_use_Then_the_server_returns_the_clients_preferred_version()
		{
			// Arrange
			new AmqpServer (SupportedVersion.From(0, 9, 0).To(1, 0, 0)).Start();
			var client = new AmqpClient (SupportedVersion.Exactly(0, 9, 0));

			// Act
			var result = await client.ConnectAsync ();

			// Assert
			Assert.That (result.AmqpVersion, Is.EqualTo (new Version(0, 9, 0)));
		}

		[Test]
		public async Task Given_a_client_prefers_a_version_which_the_server_does_not_support_When_negotiating_which_version_to_use_Then_the_server_returns_its_preferred_version_And_closes_the_connection()
		{
			// Arrange
			new AmqpServer (SupportedVersion.From(0, 9, 0).To(1, 0, 0)).Start();
			var client = new AmqpClient (SupportedVersion.Exactly(0, 8, 0));

			// Act
			var result = await client.ConnectAsync ();

			// Assert
			Assert.That (result.AmqpVersion, Is.EqualTo (new Version(1, 0, 0)));
			Assert.That (result.IsConnected, Is.False);
		}

		[Test]
		public async Task Given_a_client_prefers_the_same_version_as_the_server_When_negotiating_which_version_to_use_Then_the_server_returns_the_clients_preferred_version()<commit_msg>Add property to spec. Fixes #2.<commit_after>﻿using NUnit.Framework;
using Msg.Infrastructure;
using System.Threading.Tasks;
using Msg.Domain;
using Version = Msg.Domain.Version;

namespace Msg.Acceptance.Tests
{
	[TestFixture]
	public class VersionNegotiation
	{
		[Test]
		[Property("Issue","2")]
		public async Task Given_a_client_prefers_a_lower_version_than_the_version_the_server_prefers_When_negotiating_which_version_to_use_Then_the_server_returns_the_clients_preferred_version()
		{
			// Arrange
			new AmqpServer (SupportedVersion.From(0, 9, 0).To(1, 0, 0)).Start();
			var client = new AmqpClient (SupportedVersion.Exactly(0, 9, 0));

			// Act
			var result = await client.ConnectAsync ();

			// Assert
			Assert.That (result.AmqpVersion, Is.EqualTo (new Version(0, 9, 0)));
		}

		[Test]
		public async Task Given_a_client_prefers_a_version_which_the_server_does_not_support_When_negotiating_which_version_to_use_Then_the_server_returns_its_preferred_version_And_closes_the_connection()
		{
			// Arrange
			new AmqpServer (SupportedVersion.From(0, 9, 0).To(1, 0, 0)).Start();
			var client = new AmqpClient (SupportedVersion.Exactly(0, 8, 0));

			// Act
			var result = await client.ConnectAsync ();

			// Assert
			Assert.That (result.AmqpVersion, Is.EqualTo (new Version(1, 0, 0)));
			Assert.That (result.IsConnected, Is.False);
		}

		[Test]
		public async Task Given_a_client_prefers_the_same_version_as_the_server_When_negotiating_which_version_to_use_Then_the_server_returns_the_clients_preferred_version()
{'fraction_non_alphanumeric': 0.09940357852882704, 'fraction_numerical': 0.01656726308813784, 'mean_word_length': 5.5773420479302835, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '3098825', 'n_tokens_mistral': 1172, 'n_tokens_neox': 1035, 'n_words': 187}