<commit_before>using System.Linq;
using Xunit;

namespace Norm.Tests
{
    public class MapReduceTests
    {
        private const string _map = "function(){emit(0, this.Price);}";
        private const string _reduce = "function(key, values){var sumPrice = 0;for(var i = 0; i < values.length; ++i){sumPrice += values[i];} return sumPrice;}";

        public MapReduceTests()
        {
            using (var mongo = Mongo.ParseConnection(TestHelper.ConnectionString("pooling=false&strict=false")))
            {
                mongo.Database.DropCollection("ReduceProduct");
            }
        }
        
        [Fact]
        public void TypedMapReduceOptionSetsCollectionName()
        {
            var options = new MapReduceOptions<ReduceProduct>();
            Assert.Equal("Product", options.CollectionName);
        }

        [Fact]
        public void MapReduceCreatesACollection()
        {
            using (var mongo = Mongo.ParseConnection(TestHelper.ConnectionString("pooling=false")))
            {
                mongo.GetCollection<ReduceProduct>().Insert(new ReduceProduct { Price = 1.5f }, new ReduceProduct { Price = 2.5f }); 
                var mr = mongo.CreateMapReduce();
                var result = mr.Execute(new MapReduceOptions<ReduceProduct> {Map = _map, Reduce = _reduce});
                var found = false;
                foreach(var c in mongo.Database.GetAllCollections())
                {
                    if (c.Name.EndsWith(result.Result))
                    {
                        found = true;
                        break;
                    }
                }
                Assert.Equal(true, found);
            }
        }

        [Fact]
        public void TemporaryCollectionIsCleanedUpWhenConnectionIsClosed()
        {
            string name;
            using (var mongo = Mongo.ParseConnection(TestHelper.ConnectionString("pooling=false")))<commit_msg>Fixed a MapReduce Test.<commit_after>using System.Linq;
using Xunit;

namespace Norm.Tests
{
    public class MapReduceTests
    {
        private const string _map = "function(){emit(0, this.Price);}";
        private const string _reduce = "function(key, values){var sumPrice = 0;for(var i = 0; i < values.length; ++i){sumPrice += values[i];} return sumPrice;}";

        public MapReduceTests()
        {
            using (var mongo = Mongo.ParseConnection(TestHelper.ConnectionString("pooling=false&strict=false")))
            {
                mongo.Database.DropCollection("ReduceProduct");
            }
        }
        
        [Fact]
        public void TypedMapReduceOptionSetsCollectionName()
        {
            var options = new MapReduceOptions<ReduceProduct>();
            Assert.Equal(typeof(ReduceProduct).Name, options.CollectionName);
        }

        [Fact]
        public void MapReduceCreatesACollection()
        {
            using (var mongo = Mongo.ParseConnection(TestHelper.ConnectionString("pooling=false")))
            {
                mongo.GetCollection<ReduceProduct>().Insert(new ReduceProduct { Price = 1.5f }, new ReduceProduct { Price = 2.5f }); 
                var mr = mongo.CreateMapReduce();
                var result = mr.Execute(new MapReduceOptions<ReduceProduct> {Map = _map, Reduce = _reduce});
                var found = false;
                foreach(var c in mongo.Database.GetAllCollections())
                {
                    if (c.Name.EndsWith(result.Result))
                    {
                        found = true;
                        break;
                    }
                }
                Assert.Equal(true, found);
            }
        }

        [Fact]
        public void TemporaryCollectionIsCleanedUpWhenConnectionIsClosed()
        {
            string name;
            using (var mongo = Mongo.ParseConnection(TestHelper.ConnectionString("pooling=false")))
{'fraction_non_alphanumeric': 0.10198300283286119, 'fraction_numerical': 0.0036054596961112542, 'mean_word_length': 1.822674418604651, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 9, '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': '6246361', 'n_tokens_mistral': 1042, 'n_tokens_neox': 995, 'n_words': 200}