<commit_before>﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Data.Entity;
using System.Linq;
using BatMap.Tests.DTO;
using BatMap.Tests.Model;
using FizzWare.NBuilder;
using Moq;
using NUnit.Framework;

namespace BatMap.Tests {

    [TestFixture]
    public class EntityFrameworkTests {
        private readonly IList<Order> _orders;

        public EntityFrameworkTests() {
            var random = new Random();

            var products = Builder<Product>
                .CreateListOfSize(15)
                .All()
                .Do(p => p.Supplier = Builder<Company>.CreateNew().Do(s => s.Addresses = Builder<Address>.CreateListOfSize(2).Build()).Build())
                .Build();

            _orders = Builder<Order>
                .CreateListOfSize(10)
                .All()
                .Do(o => {
                    o.OrderDetails = Builder<OrderDetail>
                        .CreateListOfSize(3)
                        .All()
                        .Do(od => od.Product = products[random.Next(15)])
                        .Build();
                })
                .Build();
        }

        [Test]
        public void Get_Includes() {
            try {
                var context = new TestEntities();
                var q = context.Orders
                    .Include(o => o.OrderDetails.Select(od => od.Product.Supplier.Addresses.Select(a => a.City)))
                    .Include(o => o.OrderDetails.Select(od => od.Product.Supplier.MainAddress));

                var oIncludes = Helper.GetIncludes(q).FirstOrDefault();
                Assert.NotNull(oIncludes);

                var odInclude = oIncludes.Children.FirstOrDefault();
                Assert.NotNull(odInclude);

                var pInclude = odInclude.Children.FirstOrDefault();
                Assert.NotNull(pInclude);

                Assert.AreEqual(pInclude.Children.Count(), 2);
            }
            catch {
                // Most CIs will probably fail, we can still use this test locally
                Assert.Pass();
            }
        }

        [Test]
        public void Project_Orders() {
            var config = new MapConfiguration();
            config.RegisterMap<Order, OrderDTO>();
            config.RegisterMap<OrderDetail, OrderDetailDTO>();
            config.RegisterMap<Product, ProductDTO>();

            var mockContext = new Mock<TestEntities>();
            var observableOrders = new ObservableCollection<Order>(_orders);
            mockContext.Setup(p => p.Orders).Returns(GetMockSet(observableOrders).Object);

            var query = mockContext.Object.Orders;
            var dtoQuery = config.ProjectTo<OrderDTO>(query);
            var dtoList = dtoQuery.ToList();<commit_msg>Increasing coverage Removing try-catch (added for travis)<commit_after>﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Data.Entity;
using System.Linq;
using BatMap.Tests.DTO;
using BatMap.Tests.Model;
using FizzWare.NBuilder;
using Moq;
using NUnit.Framework;

namespace BatMap.Tests {

    [TestFixture]
    public class EntityFrameworkTests {
        private readonly IList<Order> _orders;

        public EntityFrameworkTests() {
            var random = new Random();

            var products = Builder<Product>
                .CreateListOfSize(15)
                .All()
                .Do(p => p.Supplier = Builder<Company>.CreateNew().Do(s => s.Addresses = Builder<Address>.CreateListOfSize(2).Build()).Build())
                .Build();

            _orders = Builder<Order>
                .CreateListOfSize(10)
                .All()
                .Do(o => {
                    o.OrderDetails = Builder<OrderDetail>
                        .CreateListOfSize(3)
                        .All()
                        .Do(od => od.Product = products[random.Next(15)])
                        .Build();
                })
                .Build();
        }

        [Test]
        public void Get_Includes() {
            var context = new TestEntities();
            var q = context.Orders
                .Include(o => o.OrderDetails.Select(od => od.Product.Supplier.Addresses.Select(a => a.City)))
                .Include(o => o.OrderDetails.Select(od => od.Product.Supplier.MainAddress));

            var oIncludes = Helper.GetIncludes(q).FirstOrDefault();
            Assert.NotNull(oIncludes);

            var odInclude = oIncludes.Children.FirstOrDefault();
            Assert.NotNull(odInclude);

            var pInclude = odInclude.Children.FirstOrDefault();
            Assert.NotNull(pInclude);

            Assert.AreEqual(pInclude.Children.Count(), 2);
        }

        [Test]
        public void Project_Orders() {
            var config = new MapConfiguration();
            config.RegisterMap<Order, OrderDTO>();
            config.RegisterMap<OrderDetail, OrderDetailDTO>();
            config.RegisterMap<Product, ProductDTO>();

            var mockContext = new Mock<TestEntities>();
            var observableOrders = new ObservableCollection<Order>(_orders);
            mockContext.Setup(p => p.Orders).Returns(GetMockSet(observableOrders).Object);

            var query = mockContext.Object.Orders;
            var dtoQuery = config.ProjectTo<OrderDTO>(query);
            var dtoList = dtoQuery.ToList();
{'fraction_non_alphanumeric': 0.11069836552748885, 'fraction_numerical': 0.0033432392273402673, 'mean_word_length': 1.820848611838659, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 47, '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': '4921046', 'n_tokens_mistral': 1445, 'n_tokens_neox': 1371, 'n_words': 272}