<commit_before>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

#if !NUNIT
using Microsoft.VisualStudio.TestTools.UnitTesting;
#else
using NUnit.Framework;
using TestClass = NUnit.Framework.TestFixtureAttribute;
using TestInitialize = NUnit.Framework.SetUpAttribute;
using TestCleanup = NUnit.Framework.TearDownAttribute;
using TestMethod = NUnit.Framework.TestAttribute;
#endif 

namespace Csla.Test.CslaQueryProvider
{
  [Serializable]
  public class RandomThing : BusinessBase<RandomThing>, IConvertible 
  {
    [Indexable(IndexModeEnum.IndexModeAlways)]
    public int SomeVal { get; set; }
    public int SomeOtherVal { get; set; }
    public int YetAnotherVal { get; set; }
    public Guid Id { get; set; }

    public Nullable<int> ANullableVal
    {
      get { return new Nullable<int>(SomeVal); }
    }

    [Indexable(IndexModeEnum.IndexModeAlways)]
    public Nullable<Guid> ANullableGuid
    {
      get { return new Nullable<Guid>(Id); }
    }

    public DateTime SomeDateTime
    {
      get { return new DateTime((long)SomeVal); }
    }

    public DateTime? SomeDateTimeNullable
    {
      get { return (DateTime?) SomeDateTime; }
    }

    public RandomThing(int x)
    {
      MarkAsChild();
      SomeVal = x;
      Id = Guid.NewGuid();
    }

    #region IConvertible Members

    TypeCode IConvertible.GetTypeCode()
    {
      throw new NotImplementedException();
    }

    bool IConvertible.ToBoolean(IFormatProvider provider)
    {
      throw new NotImplementedException();
    }

    byte IConvertible.ToByte(IFormatProvider provider)
    {
      throw new NotImplementedException();
    }

    char IConvertible.ToChar(IFormatProvider provider)
    {
      throw new NotImplementedException();
    }

    DateTime IConvertible.ToDateTime(IFormatProvider provider)
    {
      throw new NotImplementedException();
    }

    decimal IConvertible.ToDecimal(IFormatProvider provider)
    {
      return Convert.ToDecimal(SomeVal);
    }

    double IConvertible.ToDouble(IFormatProvider provider)
    {
      throw new NotImplementedException();
    }

    short IConvertible.ToInt16(IFormatProvider provider)
    {
      throw new NotImplementedException();
    }

    int IConvertible.ToInt32(IFormatProvider provider)
    {
      throw new NotImplementedException();
    }

    long IConvertible.ToInt64(IFormatProvider provider)
    {
      throw new NotImplementedException();
    }

    sbyte IConvertible.ToSByte(IFormatProvider provider)
    {
      throw new NotImplementedException();
    }

    float IConvertible.ToSingle(IFormatProvider provider)
    {
      throw new NotImplementedException();
    }

    string IConvertible.ToString(IFormatProvider provider)
    {
      throw new NotImplementedException();
    }

    object IConvertible.ToType(Type conversionType, IFormatProvider provider)
    {
      if (conversionType == typeof(RandomThing))
        return this;
      else
        throw new NotImplementedException();
    }

    ushort IConvertible.ToUInt16(IFormatProvider provider)
    {
      throw new NotImplementedException();
    }

    uint IConvertible.ToUInt32(IFormatProvider provider)
    {
      throw new NotImplementedException();
    }

    ulong IConvertible.ToUInt64(IFormatProvider provider)
    {
      throw new NotImplementedException();
    }

    #endregion
  }

  [Serializable]
  class CollectionExtendingIQueryable<T> : BusinessListBase<CollectionExtendingIQueryable<T>, T> where T : Csla.Core.IEditableBusinessObject { }

  class CustomRandomThingComparer : IEqualityComparer<RandomThing>
  {

    #region IEqualityComparer<RandomThing> Members

    bool IEqualityComparer<RandomThing>.Equals(RandomThing x, RandomThing y)
    {
      return x.SomeVal == y.SomeVal;
    }

    int IEqualityComparer<RandomThing>.GetHashCode(RandomThing obj)
    {
      return obj.SomeVal.GetHashCode();
    }

    #endregion
  }
  
  [TestClass]
  public class CslaQueryProviderTests
  {
    [TestMethod]
    public void TestQueryProviderCount()
    {
      CollectionExtendingIQueryable<RandomThing> random = new CollectionExtendingIQueryable<RandomThing>();
      Random rnd = new Random();<commit_msg>Added test to make sure SelectMany works. bugid: 448<commit_after>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

#if !NUNIT
using Microsoft.VisualStudio.TestTools.UnitTesting;
#else
using NUnit.Framework;
using TestClass = NUnit.Framework.TestFixtureAttribute;
using TestInitialize = NUnit.Framework.SetUpAttribute;
using TestCleanup = NUnit.Framework.TearDownAttribute;
using TestMethod = NUnit.Framework.TestAttribute;
#endif 

namespace Csla.Test.CslaQueryProvider
{
  [Serializable]
  public class RandomThing : BusinessBase<RandomThing>, IConvertible 
  {
    [Indexable(IndexModeEnum.IndexModeAlways)]
    public int SomeVal { get; set; }
    public int SomeOtherVal { get; set; }
    public int YetAnotherVal { get; set; }
    public Guid Id { get; set; }

    public Nullable<int> ANullableVal
    {
      get { return new Nullable<int>(SomeVal); }
    }

    [Indexable(IndexModeEnum.IndexModeAlways)]
    public Nullable<Guid> ANullableGuid
    {
      get { return new Nullable<Guid>(Id); }
    }

    public DateTime SomeDateTime
    {
      get { return new DateTime((long)SomeVal); }
    }

    public DateTime? SomeDateTimeNullable
    {
      get { return (DateTime?) SomeDateTime; }
    }

    public RandomThing(int x)
    {
      MarkAsChild();
      SomeVal = x;
      Id = Guid.NewGuid();
    }

    #region IConvertible Members

    TypeCode IConvertible.GetTypeCode()
    {
      throw new NotImplementedException();
    }

    bool IConvertible.ToBoolean(IFormatProvider provider)
    {
      throw new NotImplementedException();
    }

    byte IConvertible.ToByte(IFormatProvider provider)
    {
      throw new NotImplementedException();
    }

    char IConvertible.ToChar(IFormatProvider provider)
    {
      throw new NotImplementedException();
    }

    DateTime IConvertible.ToDateTime(IFormatProvider provider)
    {
      throw new NotImplementedException();
    }

    decimal IConvertible.ToDecimal(IFormatProvider provider)
    {
      return Convert.ToDecimal(SomeVal);
    }

    double IConvertible.ToDouble(IFormatProvider provider)
    {
      throw new NotImplementedException();
    }

    short IConvertible.ToInt16(IFormatProvider provider)
    {
      throw new NotImplementedException();
    }

    int IConvertible.ToInt32(IFormatProvider provider)
    {
      throw new NotImplementedException();
    }

    long IConvertible.ToInt64(IFormatProvider provider)
    {
      throw new NotImplementedException();
    }

    sbyte IConvertible.ToSByte(IFormatProvider provider)
    {
      throw new NotImplementedException();
    }

    float IConvertible.ToSingle(IFormatProvider provider)
    {
      throw new NotImplementedException();
    }

    string IConvertible.ToString(IFormatProvider provider)
    {
      throw new NotImplementedException();
    }

    object IConvertible.ToType(Type conversionType, IFormatProvider provider)
    {
      if (conversionType == typeof(RandomThing))
        return this;
      else
        throw new NotImplementedException();
    }

    ushort IConvertible.ToUInt16(IFormatProvider provider)
    {
      throw new NotImplementedException();
    }

    uint IConvertible.ToUInt32(IFormatProvider provider)
    {
      throw new NotImplementedException();
    }

    ulong IConvertible.ToUInt64(IFormatProvider provider)
    {
      throw new NotImplementedException();
    }

    #endregion
  }

  [Serializable]
  class CollectionExtendingIQueryable<T> : BusinessListBase<CollectionExtendingIQueryable<T>, T> where T : Csla.Core.IEditableBusinessObject { }

  class CustomRandomThingComparer : IEqualityComparer<RandomThing>
  {

    #region IEqualityComparer<RandomThing> Members

    bool IEqualityComparer<RandomThing>.Equals(RandomThing x, RandomThing y)
    {
      return x.SomeVal == y.SomeVal;
    }

    int IEqualityComparer<RandomThing>.GetHashCode(RandomThing obj)
    {
      return obj.SomeVal.GetHashCode();
    }

    #endregion
  }

  class InnerCollectionItem : BusinessBase<InnerCollectionItem>
  {
    public string TestProp { get; set; }
  }

  class InnerCollection : BusinessListBase<InnerCollection, InnerCollectionItem>
  {
  }

  class OuterCollectionItem : BusinessBase<OuterCollectionItem>
  {
    public InnerCollection TestInnerCollection { get; set; }
  }

  class OuterCollection : BusinessListBase<OuterCollection, OuterCollectionItem>
  {
  }
  
  [TestClass]
  public class CslaQueryProviderTests
  {
    [TestMethod]
    public void nested_collections_return_valid_results()
    {
      var item = new InnerCollectionItem() { TestProp = "42" };
      var innerCollection = new InnerCollection();
      innerCollection.Add(item);
      var outerItem = new OuterCollectionItem() { TestInnerCollection = innerCollection };
      var outerCollection = new OuterCollection();
      outerCollection.Add(outerItem);

      var get42back =  from outer in outerCollection
                       from inner in outerItem.TestInnerCollection
                       select inner;
      Assert.IsTrue(get42back.First().TestProp == "42");
      
    }
    
    [TestMethod]
    public void TestQueryProviderCount()
    {
      CollectionExtendingIQueryable<RandomThing> random = new CollectionExtendingIQueryable<RandomThing>();
      Random rnd = new Random();
{'fraction_non_alphanumeric': 0.08136482939632546, 'fraction_numerical': 0.003674540682414698, 'mean_word_length': 3.2948602344454465, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 35, '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': '3401334', 'n_tokens_mistral': 2821, 'n_tokens_neox': 2746, 'n_words': 571}