<commit_before>﻿using System;
using NUnit.Framework;
using MongoDB.Driver;
using MongoQueryBuilder.Exceptions;

namespace MongoQueryBuilder.Tests
{
    [TestFixture]
    public class WrapperTests
    {
        [Test]
        public void ItCallsTheWrapper()
        {
            var called = false;
            Action<Action> wrapper = action =>
            {
                called = true;
                action();
            };
            var repo = CompanyRepo.CreateRepo(new RepositoryConfiguration
            {<commit_msg>Added sanity check test for wrapper function, intended for retries<commit_after>﻿using System;
using System.Linq;
using NUnit.Framework;
using MongoDB.Driver;
using MongoQueryBuilder.Exceptions;

namespace MongoQueryBuilder.Tests
{
    [TestFixture]
    public class WrapperTests
    {
        [Test]
        public void ItDoesNotCallTheWrapperOverInMemoryOperations()
        {
            var wrapperCalls = 0;
            Action<Action> wrapper = action =>
            {
                wrapperCalls++;
                action();
                action();
            };
            var repo = CompanyRepo.CreateRepo(new RepositoryConfiguration
                {
                    CollectionName = "companies",
                    DatabaseName = "testdata",
                    ConnectionString = "mongodb://localhost",
                    SafeModeSetting = SafeMode.True,
                    CustomWrapper = wrapper
                });
            repo.Collection.Drop();
            repo.Save(new Company
                {
                    Id = 1,
                    Name = "bar"
                });
            repo.Save(new Company
                {
                    Id = 2,
                    Name = "foo",
                    ChildCompanies = new [] { 1 }
                });
            repo.Save(new Company
                {
                    Id = 3,
                    Name = "bar",
                    ChildCompanies = new [] { 1 }
                });

            var queryableCalls = 0;
            var enumerableCalls = 0;
            repo
                .Builder()
                .ByName("bar")
                .Queryable(c =>
                {
                    queryableCalls++;
                    return c;
                })
                .Where(i => i.Id == 1)
                .Select(i =>
                {
                    enumerableCalls++;
                    return i;
                })
                .ToList();
            Assert.AreEqual(1, wrapperCalls);
            Assert.AreEqual(2, queryableCalls);
            Assert.AreEqual(1, enumerableCalls);
        }

        [Test]
        public void ItCallsTheWrapper()
        {
            var called = false;
            Action<Action> wrapper = action =>
            {
                called = true;
                action();
            };
            var repo = CompanyRepo.CreateRepo(new RepositoryConfiguration
            {
{'fraction_non_alphanumeric': 0.08257499157398045, 'fraction_numerical': 0.004044489383215369, 'mean_word_length': 1.0901408450704226, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 12, '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': '6945743', 'n_tokens_mistral': 733, 'n_tokens_neox': 677, 'n_words': 152}