<commit_before>﻿using System;
using System.Linq;
using System.Collections.Generic;
using NHibernate.DomainModel;
using NHibernate.DomainModel.Northwind.Entities;
using NHibernate.Linq;
using NUnit.Framework;

namespace NHibernate.Test.Linq
{
	[TestFixture]
	public class FunctionTests : LinqTestCase
	{
		[Test]
		public void SubstringFunction()
		{
			var query = from e in db.Employees
						where e.FirstName.Substring(1, 2) == "An"
						select e;

			ObjectDumper.Write(query);
		}

		[Test]
		public void LeftFunction()
		{
			var query = from e in db.Employees
                        where e.FirstName.Substring(1, 2) == "An"
                        select e.FirstName.Substring(3);

			ObjectDumper.Write(query);
		}

		[Test]
		public void ReplaceFunction()
		{
			var query = from e in db.Employees
						where e.FirstName.StartsWith("An")
						select new
								{
									Before = e.FirstName,
									AfterMethod = e.FirstName.Replace("An", "Zan"),
                                    AfterExtension = ExtensionMethods.Replace(e.FirstName, "An", "Zan"),
                                    AfterExtension2 = e.FirstName.ReplaceExtension("An", "Zan")
								};

			var s = ObjectDumper.Write(query);
		}

		[Test]
		public void CharIndexFunction()
		{
			if (!TestDialect.SupportsLocate)
				Assert.Ignore("Locate function not supported.");

			var query = from e in db.Employees
                        where e.FirstName.IndexOf('A') == 1<commit_msg>Fixed string.Substring Linq tests (NH-3067)<commit_after>﻿using System;
using System.Linq;
using System.Collections.Generic;
using NHibernate.DomainModel;
using NHibernate.DomainModel.Northwind.Entities;
using NHibernate.Linq;
using NUnit.Framework;

namespace NHibernate.Test.Linq
{
	[TestFixture]
	public class FunctionTests : LinqTestCase
	{
		[Test]
		public void SubstringFunction2()
		{
			var query = (from e in db.Employees
						 where e.FirstName.Substring(0, 2) == "An"
						 select e).ToList();

			Assert.That(query.Count, Is.EqualTo(2));
		}

		[Test]
		public void SubstringFunction1()
		{
			var query = (from e in db.Employees
						 where e.FirstName.Substring(3) == "rew"
						 select e).ToList();

			Assert.That(query.Count, Is.EqualTo(1));
			Assert.That(query[0].FirstName, Is.EqualTo("Andrew"));
		}

		[Test]
		public void LeftFunction()
		{
			var query = (from e in db.Employees
						 where e.FirstName.Substring(0, 2) == "An"
						 select e.FirstName.Substring(3)).ToList();

			Assert.That(query.Count, Is.EqualTo(2));
			Assert.That(query[0], Is.EqualTo("rew")); //Andrew
			Assert.That(query[1], Is.EqualTo("e")); //Anne
		}

		[Test]
		public void ReplaceFunction()
		{
			var query = from e in db.Employees
						where e.FirstName.StartsWith("An")
						select new
								{
									Before = e.FirstName,
									AfterMethod = e.FirstName.Replace("An", "Zan"),
                                    AfterExtension = ExtensionMethods.Replace(e.FirstName, "An", "Zan"),
                                    AfterExtension2 = e.FirstName.ReplaceExtension("An", "Zan")
								};

			var s = ObjectDumper.Write(query);
		}

		[Test]
		public void CharIndexFunction()
		{
			if (!TestDialect.SupportsLocate)
				Assert.Ignore("Locate function not supported.");

			var query = from e in db.Employees
                        where e.FirstName.IndexOf('A') == 1
{'fraction_non_alphanumeric': 0.1232876712328767, 'fraction_numerical': 0.008040500297796307, 'mean_word_length': 2.577209797657082, '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': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3388071', 'n_tokens_mistral': 1301, 'n_tokens_neox': 1042, 'n_words': 236}