<commit_before>﻿using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using FluentAssertions;
using Nest;
using Tests.Framework;

namespace Tests.CodeStandards
{
	/** # Naming Conventions
	* 
	* NEST uses the following naming conventions (with _some_ exceptions).
	*/
	public class NamingConventions
	{
		/** ## Class Names
		*
		* Abstract class names should end with a `Base` suffix
		*/
		[U] public void AbstractClassNamesEndWithBase()
		{
			var exceptions = new[]
			{
				typeof(DateMath)
			};

			var abstractClasses = typeof(IRequest).Assembly().GetTypes()
				.Where(t => t.IsClass() && t.IsAbstract() && !t.IsSealed() && !exceptions.Contains(t))
				.Where(t => !t.Name.Split('`')[0].EndsWith("Base"))
				.Select(t => t.Name.Split('`')[0])
				.ToList();

			abstractClasses.Should().BeEmpty();
		}

		/**
		* Class names that end with `Base` suffix are abstract
		*/
		[U] public void ClassNameContainsBaseShouldBeAbstract()
		{
			var exceptions = new[] { typeof(DateMath) };

			var baseClassesNotAbstract = typeof(IRequest).Assembly().GetTypes()
				.Where(t => t.IsClass() && !exceptions.Contains(t))
				.Where(t => t.Name.Split('`')[0].EndsWith("Base"))
				.Where(t => !t.IsAbstractClass())
				.Select(t => t.Name.Split('`')[0])
				.ToList();

			baseClassesNotAbstract.Should().BeEmpty();
		}

		/** ## Requests and Responses
		*
		* Request class names should end with `Request`
		*/
		[U]
		public void RequestClassNamesEndWithRequest()
		{
			var types = typeof(IRequest).Assembly().GetTypes();
			var requests = types
				.Where(t => typeof(IRequest).IsAssignableFrom(t) && !t.IsAbstract())
				.Where(t => !typeof(IDescriptor).IsAssignableFrom(t))
				.Where(t => !t.Name.Split('`')[0].EndsWith("Request"))
				.Select(t => t.Name.Split('`')[0])
				.ToList();

			requests.Should().BeEmpty();
		}

		/**
		* Response class names should end with `Response`
		**/
		[U]
		public void ResponseClassNamesEndWithResponse()
		{
			var types = typeof(IRequest).Assembly().GetTypes();
			var responses = types
				.Where(t => typeof(IResponse).IsAssignableFrom(t) && !t.IsAbstract())
				.Where(t => !t.Name.Split('`')[0].EndsWith("Response"))
				.Select(t => t.Name.Split('`')[0])
				.ToList();

			responses.Should().BeEmpty();
		}

		/**
		* Request and Response class names should be one to one in *most* cases.
		* e.g. `ValidateRequest` => `ValidateResponse`, and not `ValidateQueryRequest` => `ValidateResponse`
		* There are a few exceptions to this rule, most notably the `Cat` prefixed requests and
		* `Exists` requests.
		*/
		[U]
		public void ParityBetweenRequestsAndResponses()
		{
			// Add any exceptions to the rule here.
			var exceptions = new[]
			{
				typeof(CatAliasesRequest),
				typeof(CatAllocationRequest),
				typeof(CatCountRequest),
				typeof(CatFielddataRequest),
				typeof(CatHealthRequest),
				typeof(CatHelpRequest),
				typeof(CatIndicesRequest),
				typeof(CatMasterRequest),
				typeof(CatNodesRequest),
				typeof(CatPendingTasksRequest),
				typeof(CatPluginsRequest),
				typeof(CatRecoveryRequest),
				typeof(CatSegmentsRequest),
				typeof(CatShardsRequest),
				typeof(CatThreadPoolRequest),
				typeof(DocumentExistsRequest),
				typeof(DocumentExistsRequest<>),
				typeof(AliasExistsRequest),
				typeof(IndexExistsRequest),
				typeof(TypeExistsRequest),
				typeof(IndexTemplateExistsRequest),
				typeof(SearchExistsRequest),
				typeof(SearchExistsRequest<>),
				typeof(SearchTemplateRequest),
				typeof(SearchTemplateRequest<>),
				typeof(ScrollRequest),
				typeof(SourceRequest),
				typeof(SourceRequest<>),
				typeof(ValidateQueryRequest<>),
				typeof(GetAliasRequest),
				typeof(CatNodeattrsRequest),
				typeof(IndicesShardStoresRequest),
				typeof(RenderSearchTemplateRequest)
			};

			var types = typeof(IRequest).Assembly().GetTypes();

			var requests = new HashSet<string>(types
				.Where(t =>
					t.IsClass() &&
					!t.IsAbstract() &&
					typeof(IRequest).IsAssignableFrom(t) &&
					!typeof(IDescriptor).IsAssignableFrom(t)
					&& !exceptions.Contains(t))
				.Select(t => t.Name.Split('`')[0].Replace("Request", ""))
			);

			var responses = types
				.Where(t => t.IsClass() && !t.IsAbstract() && typeof(IResponse).IsAssignableFrom(t))
				.Select(t => t.Name.Split('`')[0].Replace("Response", ""));

			requests.Except(responses).Should().BeEmpty();
		}
	}
}
<commit_msg>Fix failing convention tests after code gen update<commit_after>﻿using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using FluentAssertions;
using Nest;
using Tests.Framework;

namespace Tests.CodeStandards
{
	/** # Naming Conventions
	*
	* NEST uses the following naming conventions (with _some_ exceptions).
	*/
	public class NamingConventions
	{
		/** ## Class Names
		*
		* Abstract class names should end with a `Base` suffix
		*/
		[U] public void AbstractClassNamesEndWithBase()
		{
			var exceptions = new[]
			{
				typeof(DateMath)
			};

			var abstractClasses = typeof(IRequest).Assembly().GetTypes()
				.Where(t => t.IsClass() && t.IsAbstract() && !t.IsSealed() && !exceptions.Contains(t))
				.Where(t => !t.Name.Split('`')[0].EndsWith("Base"))
				.Select(t => t.Name.Split('`')[0])
				.ToList();

			abstractClasses.Should().BeEmpty();
		}

		/**
		* Class names that end with `Base` suffix are abstract
		*/
		[U] public void ClassNameContainsBaseShouldBeAbstract()
		{
			var exceptions = new[] { typeof(DateMath) };

			var baseClassesNotAbstract = typeof(IRequest).Assembly().GetTypes()
				.Where(t => t.IsClass() && !exceptions.Contains(t))
				.Where(t => t.Name.Split('`')[0].EndsWith("Base"))
				.Where(t => !t.IsAbstractClass())
				.Select(t => t.Name.Split('`')[0])
				.ToList();

			baseClassesNotAbstract.Should().BeEmpty();
		}

		/** ## Requests and Responses
		*
		* Request class names should end with `Request`
		*/
		[U]
		public void RequestClassNamesEndWithRequest()
		{
			var types = typeof(IRequest).Assembly().GetTypes();
			var requests = types
				.Where(t => typeof(IRequest).IsAssignableFrom(t) && !t.IsAbstract())
				.Where(t => !typeof(IDescriptor).IsAssignableFrom(t))
				.Where(t => !t.Name.Split('`')[0].EndsWith("Request"))
				.Select(t => t.Name.Split('`')[0])
				.ToList();

			requests.Should().BeEmpty();
		}

		/**
		* Response class names should end with `Response`
		**/
		[U]
		public void ResponseClassNamesEndWithResponse()
		{
			var types = typeof(IRequest).Assembly().GetTypes();
			var responses = types
				.Where(t => typeof(IResponse).IsAssignableFrom(t) && !t.IsAbstract())
				.Where(t => !t.Name.Split('`')[0].EndsWith("Response"))
				.Select(t => t.Name.Split('`')[0])
				.ToList();

			responses.Should().BeEmpty();
		}

		/**
		* Request and Response class names should be one to one in *most* cases.
		* e.g. `ValidateRequest` => `ValidateResponse`, and not `ValidateQueryRequest` => `ValidateResponse`
		* There are a few exceptions to this rule, most notably the `Cat` prefixed requests and
		* `Exists` requests.
		*/
		[U]
		public void ParityBetweenRequestsAndResponses()
		{
			// Add any exceptions to the rule here.
			var exceptions = new[]
			{
				typeof(CatAliasesRequest),
				typeof(CatAllocationRequest),
				typeof(CatCountRequest),
				typeof(CatFielddataRequest),
				typeof(CatHealthRequest),
				typeof(CatHelpRequest),
				typeof(CatIndicesRequest),
				typeof(CatMasterRequest),
				typeof(CatNodesRequest),
				typeof(CatPendingTasksRequest),
				typeof(CatPluginsRequest),
				typeof(CatRecoveryRequest),
				typeof(CatSegmentsRequest),
				typeof(CatShardsRequest),
				typeof(CatThreadPoolRequest),
				typeof(CatRepositoriesRequest),
				typeof(CatSnapshotsRequest),
				typeof(IndicesForcemergeRequest),
				typeof(DocumentExistsRequest),
				typeof(DocumentExistsRequest<>),
				typeof(AliasExistsRequest),
				typeof(IndexExistsRequest),
				typeof(TypeExistsRequest),
				typeof(IndexTemplateExistsRequest),
				typeof(SearchExistsRequest),
				typeof(SearchExistsRequest<>),
				typeof(SearchTemplateRequest),
				typeof(SearchTemplateRequest<>),
				typeof(ScrollRequest),
				typeof(SourceRequest),
				typeof(SourceRequest<>),
				typeof(ValidateQueryRequest<>),
				typeof(GetAliasRequest),
				typeof(CatNodeattrsRequest),
				typeof(IndicesShardStoresRequest),
				typeof(RenderSearchTemplateRequest)
			};

			var types = typeof(IRequest).Assembly().GetTypes();

			var requests = new HashSet<string>(types
				.Where(t =>
					t.IsClass() &&
					!t.IsAbstract() &&
					typeof(IRequest).IsAssignableFrom(t) &&
					!typeof(IDescriptor).IsAssignableFrom(t)
					&& !exceptions.Contains(t))
				.Select(t => t.Name.Split('`')[0].Replace("Request", ""))
			);

			var responses = types
				.Where(t => t.IsClass() && !t.IsAbstract() && typeof(IResponse).IsAssignableFrom(t))
				.Select(t => t.Name.Split('`')[0].Replace("Response", ""));

			requests.Except(responses).Should().BeEmpty();
		}
	}
}

{'fraction_non_alphanumeric': 0.1582356225572306, 'fraction_numerical': 0.002233389168062535, 'mean_word_length': 3.997767857142857, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 55, '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': '7313602', 'n_tokens_mistral': 3377, 'n_tokens_neox': 2811, 'n_words': 526}