<commit_before>﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reactive.Concurrency;
using System.Reactive.Linq;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Qactive.Tests.Queries
{
  [TestClass]
  public class ComplexTests : TestBase
  {
    private const int leafCountPerNode = 10;

    [TestMethod]
    public async Task ComplexTest1()
    {
      var rootIds = new[] { "C", "A" };
      var rootIdsLocal = rootIds.Do(v => Debug.WriteLine("RootObject: " + v));
      var nodeIds = new[] { new[] { "2", "4" } }.ToObservable().Do(p => p.ForEach(id => Debug.WriteLine("Node: " + id)));

      var service = TestService.Create(
        TestService.DuplexOptions,
        new[] { typeof(RootObject), typeof(Node), typeof(Leaf), typeof(EnumerableEx) },
        Observable.Return(new ServiceContext(new[] { new RootObject("A", 1), new RootObject("B", 10), new RootObject("C", 100), new RootObject("D", 1000) })));

      var results = await service.InMemoryQueryAsync(source =>
        from leafPackResult in
          from leaf in
            (from context in source
             from ids in nodeIds
             select from root in context.RootObjects.ToObservable()
                    where rootIdsLocal.Contains(root.Id)
                    from node in root[ids]
                    from leaf in node.Leaves
                    select leaf)
             .Switch()
          group leaf by leaf.Node into leavesByNode
          from leaves in leavesByNode.Buffer(leafCountPerNode * rootIds.Length)
          select new
          {
            Node = leavesByNode.Key,
            LeafPack = (from leaf in leaves
                        orderby leaf.Tick descending
                        select leaf)
                        .Distinct(leaf => leaf.Id)
                        .Memoize(memoized => new[]<commit_msg>Changed the complex test to use the test service query source rather than an in-memory query source.<commit_after>﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reactive.Concurrency;
using System.Reactive.Linq;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Qactive.Tests.Queries
{
  [TestClass]
  public class ComplexTests : TestBase
  {
    private const int leafCountPerNode = 10;

    [TestMethod]
    public async Task ComplexTest1()
    {
      var rootIds = new[] { "C", "A" };
      var rootIdsLocal = rootIds.Do(v => Debug.WriteLine("RootObject: " + v));
      var nodeIds = new[] { new[] { "2", "4" } }.ToObservable().Do(p => p.ForEach(id => Debug.WriteLine("Node: " + id)));

      var service = TestService.Create(
        TestService.DuplexOptions,
        new[] { typeof(RootObject), typeof(Node), typeof(Leaf), typeof(EnumerableEx) },
        Observable.Return(new ServiceContext(new[] { new RootObject("A", 1), new RootObject("B", 10), new RootObject("C", 100), new RootObject("D", 1000) })));

      var results = await service.QueryAsync(source =>
        from leafPackResult in
          from leaf in
            (from context in source
             from ids in nodeIds
             select from root in context.RootObjects.ToObservable()
                    where rootIdsLocal.Contains(root.Id)
                    from node in root[ids]
                    from leaf in node.Leaves
                    select leaf)
             .Switch()
          group leaf by leaf.Node into leavesByNode
          from leaves in leavesByNode.Buffer(leafCountPerNode * rootIds.Length)
          select new
          {
            Node = leavesByNode.Key,
            LeafPack = (from leaf in leaves
                        orderby leaf.Tick descending
                        select leaf)
                        .Distinct(leaf => leaf.Id)
                        .Memoize(memoized => new[]
{'fraction_non_alphanumeric': 0.10298241141983176, 'fraction_numerical': 0.007647208768799388, 'mean_word_length': 2.213759213759214, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, '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': '4730421', 'n_tokens_mistral': 1081, 'n_tokens_neox': 1040, 'n_words': 297}