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.client.soda;
  using com.espertech.esper.common.@internal.support;
  using com.espertech.esper.compat;
  using com.espertech.esper.compat.collections;
  using com.espertech.esper.regressionlib.framework;
  using com.espertech.esper.regressionlib.support.bean;
  using com.espertech.esper.regressionlib.support.epl;
  
  using NUnit.Framework;
  
  namespace com.espertech.esper.regressionlib.suite.epl.subselect
  {
      public class EPLSubselectUnfiltered
      {
          public static IList<RegressionExecution> Executions()
          {
              IList<RegressionExecution> execs = new List<RegressionExecution>();
              WithUnfilteredExpression(execs);
              WithUnfilteredUnlimitedStream(execs);
              WithUnfilteredLengthWindow(execs);
              WithUnfilteredAsAfterSubselect(execs);
              WithUnfilteredWithAsWithinSubselect(execs);
              WithUnfilteredNoAs(execs);
              WithUnfilteredLastEvent(execs);
              WithStartStopStatement(execs);
              WithSelfSubselect(execs);
              WithComputedResult(execs);
              WithFilterInside(execs);
              WithWhereClauseWithExpression(execs);
              WithCustomFunction(execs);
              WithUnfilteredStreamPriorOM(execs);
              WithUnfilteredStreamPriorCompile(execs);
              WithTwoSubqSelect(execs);
              WithWhereClauseReturningTrue(execs);
              WithJoinUnfiltered(execs);
              WithInvalidSubselect(execs);
              return execs;
          }
  
          public static IList<RegressionExecution> WithInvalidSubselect(IList<RegressionExecution> execs = null)
          {
              execs = execs ?? new List<RegressionExecution>();
              execs.Add(new EPLSubselectInvalidSubselect());
              return execs;
          }
  
          public static IList<RegressionExecution> WithJoinUnfiltered(IList<RegressionExecution> execs = null)
          {
              execs = execs ?? new List<RegressionExecution>();
              execs.Add(new EPLSubselectJoinUnfiltered());
              return execs;
          }
  
          public static IList<RegressionExecution> WithWhereClauseReturningTrue(IList<RegressionExecution> execs = null)
          {
              execs = execs ?? new List<RegressionExecution>();
              execs.Add(new EPLSubselectWhereClauseReturningTrue());
              return execs;
          }
  
          public static IList<RegressionExecution> WithTwoSubqSelect(IList<RegressionExecution> execs = null)
          {
              execs = execs ?? new List<RegressionExecution>();
              execs.Add(new EPLSubselectTwoSubqSelect());
              return execs;
          }
  
          public static IList<RegressionExecution> WithUnfilteredStreamPriorCompile(IList<RegressionExecution> execs = null)
          {
              execs = execs ?? new List<RegressionExecution>();
              execs.Add(new EPLSubselectUnfilteredStreamPriorCompile());
              return execs;
          }
  
          public static IList<RegressionExecution> WithUnfilteredStreamPriorOM(IList<RegressionExecution> execs = null)
          {
              execs = execs ?? new List<RegressionExecution>();
              execs.Add(new EPLSubselectUnfilteredStreamPriorOM());
              return execs;
          }
  
          public static IList<RegressionExecution> WithCustomFunction(IList<RegressionExecution> execs = null)
          {
              execs = execs ?? new List<RegressionExecution>();
              execs.Add(new EPLSubselectCustomFunction());
              return execs;
          }
  
          public static IList<RegressionExecution> WithWhereClauseWithExpression(IList<RegressionExecution> execs = null)
          {
              execs = execs ?? new List<RegressionExecution>();
              execs.Add(new EPLSubselectWhereClauseWithExpression());
              return execs;
          }
  
          public static IList<RegressionExecution> WithFilterInside(IList<RegressionExecution> execs = null)
          {
              execs = execs ?? new List<RegressionExecution>();
              execs.Add(new EPLSubselectFilterInside());
              return execs;
          }
  
          public static IList<RegressionExecution> WithComputedResult(IList<RegressionExecution> execs = null)
          {
              execs = execs ?? new List<RegressionExecution>();
              execs.Add(new EPLSubselectComputedResult());
              return execs;
          }
  
          public static IList<RegressionExecution> WithSelfSubselect(IList<RegressionExecution> execs = null)
          {
              execs = execs ?? new List<RegressionExecution>();
              execs.Add(new EPLSubselectSelfSubselect());
              return execs;
          }
  
          public static IList<RegressionExecution> WithStartStopStatement(IList<RegressionExecution> execs = null)
          {
              execs = execs ?? new List<RegressionExecution>();
              execs.Add(new EPLSubselectStartStopStatement());
              return execs;
          }
  
          public static IList<RegressionExecution> WithUnfilteredLastEvent(IList<RegressionExecution> execs = null)
          {
              execs = execs ?? new List<RegressionExecution>();
              execs.Add(new EPLSubselectUnfilteredLastEvent());
              return execs;
          }
  
          public static IList<RegressionExecution> WithUnfilteredNoAs(IList<RegressionExecution> execs = null)
          {
              execs = execs ?? new List<RegressionExecution>();
              execs.Add(new EPLSubselectUnfilteredNoAs());
              return execs;
          }
  
          public static IList<RegressionExecution> WithUnfilteredWithAsWithinSubselect(IList<RegressionExecution> execs = null)
          {
              execs = execs ?? new List<RegressionExecution>();
              execs.Add(new EPLSubselectUnfilteredWithAsWithinSubselect());
              return execs;
          }
  
          public static IList<RegressionExecution> WithUnfilteredAsAfterSubselect(IList<RegressionExecution> execs = null)
          {
              execs = execs ?? new List<RegressionExecution>();
              execs.Add(new EPLSubselectUnfilteredAsAfterSubselect());
              return execs;
          }
  
          public static IList<RegressionExecution> WithUnfilteredLengthWindow(IList<RegressionExecution> execs = null)
          {
              execs = execs ?? new List<RegressionExecution>();
              execs.Add(new EPLSubselectUnfilteredLengthWindow());
              return execs;
          }
  
          public static IList<RegressionExecution> WithUnfilteredUnlimitedStream(IList<RegressionExecution> execs = null)
          {
              execs = execs ?? new List<RegressionExecution>();
              execs.Add(new EPLSubselectUnfilteredUnlimitedStream());
              return execs;
          }
  
          public static IList<RegressionExecution> WithUnfilteredExpression(IList<RegressionExecution> execs = null)
          {
              execs = execs ?? new List<RegressionExecution>();
              execs.Add(new EPLSubselectUnfilteredExpression());
              return execs;
          }
  
          private static void TryAssertSingleRowUnfiltered(
              RegressionEnvironment env,
              string stmtText,
              string columnName)
          {
              env.CompileDeployAddListenerMileZero(stmtText, "s0");
  
              // check type
              Assert.AreEqual(typeof(int?), env.Statement("s0").EventType.GetPropertyType(columnName));
  
              // test no event, should return null
              env.SendEventBean(new SupportBean_S0(0));
              Assert.AreEqual(null, env.Listener("s0").AssertOneGetNewAndReset().Get(columnName));
  
              // test one event
              env.SendEventBean(new SupportBean_S1(10));
              env.SendEventBean(new SupportBean_S0(1));
              Assert.AreEqual(10, env.Listener("s0").AssertOneGetNewAndReset().Get(columnName));
  
              // resend event
              env.SendEventBean(new SupportBean_S0(2));
              Assert.AreEqual(10, env.Listener("s0").AssertOneGetNewAndReset().Get(columnName));
  
              // test second event
              env.SendEventBean(new SupportBean_S1(999));
              env.SendEventBean(new SupportBean_S0(3));
              Assert.AreEqual(999, env.Listener("s0").AssertOneGetNewAndReset().Get(columnName));
  
              env.UndeployAll();
          }
  
          private static void RunUnfilteredStreamPrior(RegressionEnvironment env)
          {
              // check type
              Assert.AreEqual(typeof(int?), env.Statement("s0").EventType.GetPropertyType("IdS1"));
  
              // test no event, should return null
              env.SendEventBean(new SupportBean_S0(0));
              Assert.AreEqual(null, env.Listener("s0").AssertOneGetNewAndReset().Get("IdS1"));
  
              // test one event
              env.SendEventBean(new SupportBean_S1(10));
              env.SendEventBean(new SupportBean_S0(1));
              Assert.AreEqual(10, env.Listener("s0").AssertOneGetNewAndReset().Get("IdS1"));
  
              // resend event
              env.SendEventBean(new SupportBean_S0(2));
              Assert.AreEqual(10, env.Listener("s0").AssertOneGetNewAndReset().Get("IdS1"));
  
              // test second event
              env.SendEventBean(new SupportBean_S0(3));
              Assert.AreEqual(10, env.Listener("s0").AssertOneGetNewAndReset().Get("IdS1"));
          }
  
          private static void TryAssertMultiRowUnfiltered(
              RegressionEnvironment env,
              string stmtText,
              string columnName)
          {
              env.CompileDeployAddListenerMileZero(stmtText, "s0");
  
              // check type
              Assert.AreEqual(typeof(int?), env.Statement("s0").EventType.GetPropertyType(columnName));
  
              // test no event, should return null
              env.SendEventBean(new SupportBean_S0(0));
              Assert.AreEqual(null, env.Listener("s0").AssertOneGetNewAndReset().Get(columnName));
  
              // test one event
              env.SendEventBean(new SupportBean_S1(10));
              env.SendEventBean(new SupportBean_S0(1));
              Assert.AreEqual(10, env.Listener("s0").AssertOneGetNewAndReset().Get(columnName));
  
              // resend event
              env.SendEventBean(new SupportBean_S0(2));
              Assert.AreEqual(10, env.Listener("s0").AssertOneGetNewAndReset().Get(columnName));
  
              // test second event
              env.SendEventBean(new SupportBean_S1(999));
              env.SendEventBean(new SupportBean_S0(3));
              Assert.AreEqual(null, env.Listener("s0").AssertOneGetNewAndReset().Get(columnName));
  
              env.UndeployAll();
          }
  
          internal class EPLSubselectSelfSubselect : RegressionExecution
          {
              public void Run(RegressionEnvironment env)
              {
                  var epl = "insert into MyCount select count(*) as cnt from SupportBean_S0;\n" +
                            "@Name('s0') select (select cnt from MyCount#lastevent) as value from SupportBean_S0";
                  env.CompileDeployAddListenerMileZero(epl, "s0");
  
                  env.SendEventBean(new SupportBean_S0(1));
                  Assert.AreEqual(null, env.Listener("s0").AssertOneGetNewAndReset().Get("value"));
  
                  env.SendEventBean(new SupportBean_S0(2));
                  Assert.AreEqual(1L, env.Listener("s0").AssertOneGetNewAndReset().Get("value"));
  
                  env.UndeployAll();
              }
          }
  
          internal class EPLSubselectStartStopStatement : RegressionExecution
          {
              public void Run(RegressionEnvironment env)
              {
                  var stmtText =
                      "@Name('s0') select Id from SupportBean_S0 where (select true from SupportBean_S1#length(1000))";
                  env.CompileDeployAddListenerMileZero(stmtText, "s0");
  
                  env.SendEventBean(new SupportBean_S0(2));
                  Assert.IsFalse(env.Listener("s0").IsInvoked);
  
                  env.SendEventBean(new SupportBean_S1(10));
                  env.SendEventBean(new SupportBean_S0(2));
                  Assert.AreEqual(2, env.Listener("s0").AssertOneGetNewAndReset().Get("Id"));
  
                  var listener = env.Listener("s0");
                  env.UndeployAll();
                  env.SendEventBean(new SupportBean_S0(2));
                  Assert.IsFalse(listener.IsInvoked);
  
                  env.CompileDeployAddListenerMileZero(stmtText, "s0");
                  env.SendEventBean(new SupportBean_S0(2));
                  Assert.IsFalse(env.Listener("s0").IsInvoked);
  
                  env.SendEventBean(new SupportBean_S1(10));
                  env.SendEventBean(new SupportBean_S0(3));
                  Assert.AreEqual(3, env.Listener("s0").AssertOneGetNewAndReset().Get("Id"));
  
                  env.UndeployAll();
              }
          }
  
          internal class EPLSubselectWhereClauseReturningTrue : RegressionExecution
          {
              public void Run(RegressionEnvironment env)
              {
                  var stmtText =
                      "@Name('s0') select Id from SupportBean_S0 where (select true from SupportBean_S1#length(1000))";
  
                  env.CompileDeployAddListenerMileZero(stmtText, "s0");
  
                  env.SendEventBean(new SupportBean_S1(10));
                  env.SendEventBean(new SupportBean_S0(2));
                  Assert.AreEqual(2, env.Listener("s0").AssertOneGetNewAndReset().Get("Id"));
  
                  env.UndeployAll();
              }
          }
  
          internal class EPLSubselectWhereClauseWithExpression : RegressionExecution
          {
              public void Run(RegressionEnvironment env)
              {
                  var stmtText =
                      "@Name('s0') select Id from SupportBean_S0 where (select P10='X' from SupportBean_S1#length(1000))";
  
                  env.CompileDeployAddListenerMileZero(stmtText, "s0");
  
                  env.SendEventBean(new SupportBean_S0(0));
                  Assert.IsFalse(env.Listener("s0").IsInvoked);
  
                  env.SendEventBean(new SupportBean_S1(10, "X"));
                  env.SendEventBean(new SupportBean_S0(0));
                  Assert.AreEqual(0, env.Listener("s0").AssertOneGetNewAndReset().Get("Id"));
  
                  env.UndeployAll();
              }
          }
  
          internal class EPLSubselectJoinUnfiltered : RegressionExecution
          {
              public void Run(RegressionEnvironment env)
              {
                  var stmtText =
                      "@Name('s0') select" +
                      " (select Id from SupportBean_S3#length(1000)) as idS3," +
                      " (select Id from SupportBean_S4#length(1000)) as idS4 from " +
                      " SupportBean_S0#keepall as S0," +
                      " SupportBean_S1#keepall as S1 " +
                      " where S0.Id = S1.Id";
  
                  env.CompileDeployAddListenerMileZero(stmtText, "s0");
  
                  // check type
                  Assert.AreEqual(typeof(int?), env.Statement("s0").EventType.GetPropertyType("idS3"));
                  Assert.AreEqual(typeof(int?), env.Statement("s0").EventType.GetPropertyType("idS4"));
  
                  // test no event, should return null
                  env.SendEventBean(new SupportBean_S0(0));
                  env.SendEventBean(new SupportBean_S1(0));
                  var theEvent = env.Listener("s0").AssertOneGetNewAndReset();
                  Assert.AreEqual(null, theEvent.Get("idS3"));
                  Assert.AreEqual(null, theEvent.Get("idS4"));
  
                  // send one event
                  env.SendEventBean(new SupportBean_S3(-1));
                  env.SendEventBean(new SupportBean_S0(1));
                  env.SendEventBean(new SupportBean_S1(1));
                  theEvent = env.Listener("s0").AssertOneGetNewAndReset();
                  Assert.AreEqual(-1, theEvent.Get("idS3"));
                  Assert.AreEqual(null, theEvent.Get("idS4"));
  
                  // send one event
                  env.SendEventBean(new SupportBean_S4(-2));
                  env.SendEventBean(new SupportBean_S0(2));
                  env.SendEventBean(new SupportBean_S1(2));
                  theEvent = env.Listener("s0").AssertOneGetNewAndReset();
                  Assert.AreEqual(-1, theEvent.Get("idS3"));
                  Assert.AreEqual(-2, theEvent.Get("idS4"));
  
                  // send second event
                  env.SendEventBean(new SupportBean_S4(-2));
                  env.SendEventBean(new SupportBean_S0(3));
                  env.SendEventBean(new SupportBean_S1(3));
                  theEvent = env.Listener("s0").AssertOneGetNewAndReset();
                  Assert.AreEqual(-1, theEvent.Get("idS3"));
                  Assert.AreEqual(null, theEvent.Get("idS4"));
  
                  env.SendEventBean(new SupportBean_S3(-2));
                  env.SendEventBean(new SupportBean_S0(3));
                  env.SendEventBean(new SupportBean_S1(3));
  
gt:                 var events = env.Listener("s0").NewDataListFlattened;