<commit_before>﻿using System.Linq;
using Mios.WebMatrix.Helpers;
using WebMatrix.Data;
using Xunit;

namespace Tests {
	public class DynamicQueryTests {
		private readonly Database db;

		public DynamicQueryTests() {
			db = Database.OpenConnectionString("Data Source=QueryTesting.sdf");
		}

		[Fact]
		public void CanExecuteQuery() {
			var query = new DynamicQuery("SELECT * FROM Users");
			Assert.True(query.ExecuteIn(db).Any(t => t.firstName=="Alice"));
		}
		[Fact]
		public void CanExecuteFilteredQuery() {
			var query = new DynamicQuery("SELECT * FROM Users")
				.Where("[firstName]=@0", "Alice");
			Assert.Equal(1, query.ExecuteIn(db).Count());
		}
		[Fact]
		public void CanExecuteMultipleFilteredQueries() {
			db.DynamicQuery("SELECT * FROM Users")
				.Where("[firstName]", "bob")
				.OrderByDesc("[id]")
				.InPagesOf(30).Page(2);

			var query = new DynamicQuery("SELECT * FROM Users")
				.Where("[lastName]=@0", "Johnsson")
				.Where("[firstName]=@0", "Alice");
			Assert.Equal(0, query.ExecuteIn(db).Count());
		}
		[Fact]
		public void CanOrderQuery() {
			Assert.Equal("Bobson",
				new DynamicQuery("SELECT * FROM Users")
					.OrderBy("[lastName]")
					.ExecuteIn(db).First().LastName);
		}
		[Fact]
		public void CanOrderFilteredQuery() {
			Assert.Equal("Bobson",
				new DynamicQuery("SELECT * FROM Users")
					.Where("[firstName]=@0","Bob")
					.OrderBy("[lastName]")
					.ExecuteIn(db).First().LastName);
		}
		[Fact]
		public void CanPageQuery() {
			Assert.Equal(1003,
				new DynamicQuery("SELECT * FROM Users")
					.OrderBy("[id]")
					.InPagesOf(3).Page(1)<commit_msg>Cosmetics<commit_after>﻿using System.Linq;
using Mios.WebMatrix.Helpers;
using WebMatrix.Data;
using Xunit;

namespace Tests {
	public class DynamicQueryTests {
		private readonly Database db;

		public DynamicQueryTests() {
			db = Database.OpenConnectionString("Data Source=QueryTesting.sdf");
		}

		[Fact]
		public void CanExecuteQuery() {
			var query = new DynamicQuery("SELECT * FROM Users");
			Assert.True(query.ExecuteIn(db).Any(t => t.firstName=="Alice"));
		}
		[Fact]
		public void CanExecuteFilteredQuery() {
			var query = new DynamicQuery("SELECT * FROM Users")
				.Where("[firstName]=@0", "Alice");
			Assert.Equal(1, query.ExecuteIn(db).Count());
		}
		[Fact]
		public void CanExecuteMultipleFilteredQueries() {
			db.DynamicQuery("SELECT * FROM Users")
				.Where("[firstName]", "bob")
				.OrderByDesc("[id]")
				.InPagesOf(30).Page(2);

			var query = new DynamicQuery("SELECT * FROM Users")
				.Where("[lastName]=@0", "Johnsson")
				.Where("[firstName]=@0", "Alice");
			Assert.Equal(0, query.ExecuteIn(db).Count());
		}
		[Fact]
		public void CanOrderQuery() {
			Assert.Equal("Bobson",
				new DynamicQuery("SELECT * FROM Users")
					.OrderBy("[lastName]")
					.ExecuteIn(db).First().LastName);
		}
		[Fact]
		public void CanOrderFilteredQuery() {
			Assert.Equal("Bobson",
				new DynamicQuery("SELECT * FROM Users")
					.Where("[firstName]=@0","Bob")
					.OrderBy("[lastName]")
					.ExecuteIn(db).First().LastName);
		}
		[Fact]
		public void CanPageOrderedQuery() {
			Assert.Equal(1003,
				new DynamicQuery("SELECT * FROM Users")
					.OrderBy("[id]")
					.InPagesOf(3).Page(1)
{'fraction_non_alphanumeric': 0.16971198513471664, 'fraction_numerical': 0.009290802105915144, 'mean_word_length': 4.054773082942097, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '2613019', 'n_tokens_mistral': 1290, 'n_tokens_neox': 1078, 'n_words': 209}