context: ///////////////////////////////////////////////////////////////////////////////////////
  // Copyright (C) 2006-2015 Esper Team. All rights reserved.                           /
  // http://esper.codehaus.org                                                          /
  // ---------------------------------------------------------------------------------- /
  // The software in this package is published under the terms of the GPL license       /
  // a copy of which has been included with this distribution in the license.txt file.  /
  ///////////////////////////////////////////////////////////////////////////////////////
  
  using System.Collections.Generic;
  
  using com.espertech.esper.common.client.scopetest;
  using com.espertech.esper.common.@internal.support;
  using com.espertech.esper.compat;
  using com.espertech.esper.regressionlib.framework;
  using com.espertech.esper.regressionlib.support.bean;
  using com.espertech.esper.regressionlib.support.epl;
  
  using NUnit.Framework;
  
  using static com.espertech.esper.regressionlib.framework.SupportMessageAssertUtil;
  
  using SupportBean_A = com.espertech.esper.regressionlib.support.bean.SupportBean_A;
  
  namespace com.espertech.esper.regressionlib.suite.resultset.aggregate
  {
      public class ResultSetAggregateFirstLastWindow
      {
          public static IList<RegressionExecution> Executions()
          {
              var execs = new List<RegressionExecution>();
              WithStar(execs);
              WithUnboundedSimple(execs);
              WithUnboundedStream(execs);
              WithWindowedUnGrouped(execs);
              WithWindowedGrouped(execs);
              WithFirstLastIndexed(execs);
              WithPrevNthIndexedFirstLast(execs);
              WithInvalid(execs);
              WithSubquery(execs);
              WithMethodAndAccessTogether(execs);
              WithTypeAndColNameAndEquivalency(execs);
              WithJoin2Access(execs);
              WithOuterJoin1Access(execs);
              WithBatchWindow(execs);
              WithBatchWindowGrouped(execs);
              WithFirstLastWindowNoGroup(execs);
              WithFirstLastWindowGroup(execs);
              WithWindowAndSumWGroup(execs);
              WithOutputRateLimiting(execs);
              WithOnDelete(execs);
              WithLastMaxMixedOnSelect(execs);
              WithLateInitialize(execs);
              WithMixedNamedWindow(execs);
              WithNoParamChainedAndProperty(execs);
              WithOnDemandQuery(execs);
              return execs;
          }
  
          public static IList<RegressionExecution> WithOnDemandQuery(IList<RegressionExecution> execs = null)
          {
              execs = execs ?? new List<RegressionExecution>();
              execs.Add(new ResultSetAggregateOnDemandQuery());
              return execs;
          }
  
          public static IList<RegressionExecution> WithNoParamChainedAndProperty(IList<RegressionExecution> execs = null)
          {
              execs = execs ?? new List<RegressionExecution>();
              execs.Add(new ResultSetAggregateNoParamChainedAndProperty());
              return execs;
          }
  
          public static IList<RegressionExecution> WithMixedNamedWindow(IList<RegressionExecution> execs = null)
          {
              execs = execs ?? new List<RegressionExecution>();
              execs.Add(new ResultSetAggregateMixedNamedWindow());
              return execs;
          }
  
          public static IList<RegressionExecution> WithLateInitialize(IList<RegressionExecution> execs = null)
          {
              execs = execs ?? new List<RegressionExecution>();
              execs.Add(new ResultSetAggregateLateInitialize());
              return execs;
          }
  
          public static IList<RegressionExecution> WithLastMaxMixedOnSelect(IList<RegressionExecution> execs = null)
          {
              execs = execs ?? new List<RegressionExecution>();
              execs.Add(new ResultSetAggregateLastMaxMixedOnSelect());
              return execs;
          }
  
          public static IList<RegressionExecution> WithOnDelete(IList<RegressionExecution> execs = null)
          {
              execs = execs ?? new List<RegressionExecution>();
              execs.Add(new ResultSetAggregateOnDelete());
              return execs;
          }
  
          public static IList<RegressionExecution> WithOutputRateLimiting(IList<RegressionExecution> execs = null)
          {
              execs = execs ?? new List<RegressionExecution>();
              execs.Add(new ResultSetAggregateOutputRateLimiting());
              return execs;
          }
  
          public static IList<RegressionExecution> WithWindowAndSumWGroup(IList<RegressionExecution> execs = null)
          {
              execs = execs ?? new List<RegressionExecution>();
              execs.Add(new ResultSetAggregateWindowAndSumWGroup());
              return execs;
          }
  
          public static IList<RegressionExecution> WithFirstLastWindowGroup(IList<RegressionExecution> execs = null)
          {
              execs = execs ?? new List<RegressionExecution>();
              execs.Add(new ResultSetAggregateFirstLastWindowGroup());
              return execs;
          }
  
          public static IList<RegressionExecution> WithFirstLastWindowNoGroup(IList<RegressionExecution> execs = null)
          {
              execs = execs ?? new List<RegressionExecution>();
              execs.Add(new ResultSetAggregateFirstLastWindowNoGroup());
              return execs;
          }
  
          public static IList<RegressionExecution> WithBatchWindowGrouped(IList<RegressionExecution> execs = null)
          {
              execs = execs ?? new List<RegressionExecution>();
              execs.Add(new ResultSetAggregateBatchWindowGrouped());
              return execs;
          }
  
          public static IList<RegressionExecution> WithBatchWindow(IList<RegressionExecution> execs = null)
          {
              execs = execs ?? new List<RegressionExecution>();
              execs.Add(new ResultSetAggregateBatchWindow());
              return execs;
          }
  
          public static IList<RegressionExecution> WithOuterJoin1Access(IList<RegressionExecution> execs = null)
          {
              execs = execs ?? new List<RegressionExecution>();
              execs.Add(new ResultSetAggregateOuterJoin1Access());
              return execs;
          }
  
          public static IList<RegressionExecution> WithJoin2Access(IList<RegressionExecution> execs = null)
          {
              execs = execs ?? new List<RegressionExecution>();
              execs.Add(new ResultSetAggregateJoin2Access());
              return execs;
          }
  
          public static IList<RegressionExecution> WithTypeAndColNameAndEquivalency(IList<RegressionExecution> execs = null)
          {
              execs = execs ?? new List<RegressionExecution>();
              execs.Add(new ResultSetAggregateTypeAndColNameAndEquivalency());
              return execs;
          }
  
          public static IList<RegressionExecution> WithMethodAndAccessTogether(IList<RegressionExecution> execs = null)
          {
              execs = execs ?? new List<RegressionExecution>();
              execs.Add(new ResultSetAggregateMethodAndAccessTogether());
              return execs;
          }
  
          public static IList<RegressionExecution> WithSubquery(IList<RegressionExecution> execs = null)
          {
              execs = execs ?? new List<RegressionExecution>();
              execs.Add(new ResultSetAggregateSubquery());
              return execs;
          }
  
          public static IList<RegressionExecution> WithInvalid(IList<RegressionExecution> execs = null)
          {
              execs = execs ?? new List<RegressionExecution>();
              execs.Add(new ResultSetAggregateInvalid());
              return execs;
          }
  
          public static IList<RegressionExecution> WithPrevNthIndexedFirstLast(IList<RegressionExecution> execs = null)
          {
              execs = execs ?? new List<RegressionExecution>();
              execs.Add(new ResultSetAggregatePrevNthIndexedFirstLast());
              return execs;
          }
  
          public static IList<RegressionExecution> WithFirstLastIndexed(IList<RegressionExecution> execs = null)
          {
              execs = execs ?? new List<RegressionExecution>();
              execs.Add(new ResultSetAggregateFirstLastIndexed());
              return execs;
          }
  
          public static IList<RegressionExecution> WithWindowedGrouped(IList<RegressionExecution> execs = null)
          {
              execs = execs ?? new List<RegressionExecution>();
              execs.Add(new ResultSetAggregateWindowedGrouped());
              return execs;
          }
  
          public static IList<RegressionExecution> WithWindowedUnGrouped(IList<RegressionExecution> execs = null)
          {
              execs = execs ?? new List<RegressionExecution>();
              execs.Add(new ResultSetAggregateWindowedUnGrouped());
              return execs;
          }
  
          public static IList<RegressionExecution> WithUnboundedStream(IList<RegressionExecution> execs = null)
          {
              execs = execs ?? new List<RegressionExecution>();
              execs.Add(new ResultSetAggregateUnboundedStream());
              return execs;
          }
  
          public static IList<RegressionExecution> WithUnboundedSimple(IList<RegressionExecution> execs = null)
          {
              execs = execs ?? new List<RegressionExecution>();
              execs.Add(new ResultSetAggregateUnboundedSimple());
              return execs;
          }
  
          public static IList<RegressionExecution> WithStar(IList<RegressionExecution> execs = null)
          {
              execs = execs ?? new List<RegressionExecution>();
              execs.Add(new ResultSetAggregateStar());
              return execs;
          }
  
          private static void TryAssertionGrouped(
              RegressionEnvironment env,
              AtomicLong milestone)
          {
              var fields = new[] {"TheString", "firststring", "firstint", "laststring", "lastint", "allint"};
  
              env.SendEventBean(new SupportBean("E1", 10));
              EPAssertionUtil.AssertProps(
                  env.Listener("s0").AssertOneGetNewAndReset(),
                  fields,
                  new object[] {"E1", "E1", 10, "E1", 10, new[] {10}});
  
              env.MilestoneInc(milestone);
  
              env.SendEventBean(new SupportBean("E2", 11));
              EPAssertionUtil.AssertProps(
                  env.Listener("s0").AssertOneGetNewAndReset(),
                  fields,
                  new object[] {"E2", "E2", 11, "E2", 11, new[] {11}});
  
              env.SendEventBean(new SupportBean("E1", 12));
              EPAssertionUtil.AssertProps(
                  env.Listener("s0").AssertOneGetNewAndReset(),
                  fields,
                  new object[] {"E1", "E1", 10, "E1", 12, new[] {10, 12}});
  
              env.MilestoneInc(milestone);
  
              env.SendEventBean(new SupportBean("E2", 13));
              EPAssertionUtil.AssertProps(
                  env.Listener("s0").AssertOneGetNewAndReset(),
                  fields,
                  new object[] {"E2", "E2", 11, "E2", 13, new[] {11, 13}});
  
              env.SendEventBean(new SupportBean("E2", 14));
              EPAssertionUtil.AssertProps(
                  env.Listener("s0").AssertOneGetNewAndReset(),
                  fields,
                  new object[] {"E2", "E2", 11, "E2", 14, new[] {11, 13, 14}});
  
              env.SendEventBean(new SupportBean("E1", 15)); // push out E1/10
              EPAssertionUtil.AssertProps(
                  env.Listener("s0").AssertOneGetNewAndReset(),
                  fields,
                  new object[] {"E1", "E1", 12, "E1", 15, new[] {12, 15}});
  
              env.MilestoneInc(milestone);
  
              env.SendEventBean(new SupportBean("E1", 16)); // push out E2/11 -=> 2 events
              var received = env.Listener("s0").GetAndResetLastNewData();
              EPAssertionUtil.AssertPropsPerRow(
                  received,
                  fields,
                  new[] {
                      new object[] {"E1", "E1", 12, "E1", 16, new[] {12, 15, 16}},
                      new object[] {"E2", "E2", 13, "E2", 14, new[] {13, 14}}
                  });
          }
  
          private static void TryAssertionFirstLastIndexed(
              RegressionEnvironment env,
              AtomicLong milestone)
          {
              var fields = new[] {"f0", "f1", "f2", "f3", "l0", "l1", "l2", "l3"};
  
gt:             env.SendEventBean(new SupportBean("E1", 10));