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;
  using System.Collections.Generic;
  
  using Avro.Generic;
  
  using com.espertech.esper.common.client;
  using com.espertech.esper.common.client.json.util;
  using com.espertech.esper.common.client.meta;
  using com.espertech.esper.common.client.scopetest;
  using com.espertech.esper.common.client.soda;
  using com.espertech.esper.common.client.util;
  using com.espertech.esper.common.@internal.@event.bean.core;
  using com.espertech.esper.common.@internal.support;
  using com.espertech.esper.common.@internal.util;
  using com.espertech.esper.compat;
  using com.espertech.esper.compat.collections;
  using com.espertech.esper.compat.function;
  using com.espertech.esper.compat.magic;
  using com.espertech.esper.compiler.client;
  using com.espertech.esper.regressionlib.framework;
  using com.espertech.esper.regressionlib.support.bean;
  using com.espertech.esper.runtime.client.scopetest;
  
  using NEsper.Avro.Extensions;
  using NEsper.Avro.Util.Support;
  
  using Newtonsoft.Json.Linq;
  
  using NUnit.Framework;
  
  using static com.espertech.esper.regressionlib.framework.SupportMessageAssertUtil;
  using static com.espertech.esper.regressionlib.support.util.SupportAdminUtil;
  
  using SupportBean_A = com.espertech.esper.regressionlib.support.bean.SupportBean_A;
  using SupportBeanSimple = com.espertech.esper.regressionlib.support.bean.SupportBeanSimple;
  
  namespace com.espertech.esper.regressionlib.suite.epl.insertinto
  {
      public class EPLInsertInto
      {
          public static IList<RegressionExecution> Executions()
          {
              IList<RegressionExecution> execs = new List<RegressionExecution>();
              WithAssertionWildcardRecast(execs);
              WithJoinWildcard(execs);
              WithWithOutputLimitAndSort(execs);
              WithStaggeredWithWildcard(execs);
              WithInsertFromPattern(execs);
              WithInsertIntoPlusPattern(execs);
              WithNullType(execs);
              WithChain(execs);
              WithMultiBeanToMulti(execs);
              WithSingleBeanToMulti(execs);
              WithProvidePartitialCols(execs);
              WithRStreamOMToStmt(execs);
              WithNamedColsOMToStmt(execs);
              WithNamedColsEPLToOMStmt(execs);
              WithNamedColsSimple(execs);
              WithNamedColsStateless(execs);
              WithNamedColsWildcard(execs);
              WithNamedColsJoin(execs);
              WithNamedColsJoinWildcard(execs);
              WithUnnamedSimple(execs);
              WithUnnamedWildcard(execs);
              WithUnnamedJoin(execs);
              WithTypeMismatchInvalid(execs);
              WithEventRepresentationsSimple(execs);
              return execs;
          }
  
          public static IList<RegressionExecution> WithEventRepresentationsSimple(IList<RegressionExecution> execs = null)
          {
              execs = execs ?? new List<RegressionExecution>();
              execs.Add(new EPLInsertIntoEventRepresentationsSimple());
              return execs;
          }
  
          public static IList<RegressionExecution> WithTypeMismatchInvalid(IList<RegressionExecution> execs = null)
          {
              execs = execs ?? new List<RegressionExecution>();
              execs.Add(new EPLInsertIntoTypeMismatchInvalid());
              return execs;
          }
  
          public static IList<RegressionExecution> WithUnnamedJoin(IList<RegressionExecution> execs = null)
          {
              execs = execs ?? new List<RegressionExecution>();
              execs.Add(new EPLInsertIntoUnnamedJoin());
              return execs;
          }
  
          public static IList<RegressionExecution> WithUnnamedWildcard(IList<RegressionExecution> execs = null)
          {
              execs = execs ?? new List<RegressionExecution>();
              execs.Add(new EPLInsertIntoUnnamedWildcard());
              return execs;
          }
  
          public static IList<RegressionExecution> WithUnnamedSimple(IList<RegressionExecution> execs = null)
          {
              execs = execs ?? new List<RegressionExecution>();
              execs.Add(new EPLInsertIntoUnnamedSimple());
              return execs;
          }
  
          public static IList<RegressionExecution> WithNamedColsJoinWildcard(IList<RegressionExecution> execs = null)
          {
              execs = execs ?? new List<RegressionExecution>();
              execs.Add(new EPLInsertIntoNamedColsJoinWildcard());
              return execs;
          }
  
          public static IList<RegressionExecution> WithNamedColsJoin(IList<RegressionExecution> execs = null)
          {
              execs = execs ?? new List<RegressionExecution>();
              execs.Add(new EPLInsertIntoNamedColsJoin());
              return execs;
          }
  
          public static IList<RegressionExecution> WithNamedColsWildcard(IList<RegressionExecution> execs = null)
          {
              execs = execs ?? new List<RegressionExecution>();
              execs.Add(new EPLInsertIntoNamedColsWildcard());
              return execs;
          }
  
          public static IList<RegressionExecution> WithNamedColsStateless(IList<RegressionExecution> execs = null)
          {
              execs = execs ?? new List<RegressionExecution>();
              execs.Add(new EPLInsertIntoNamedColsStateless());
              return execs;
          }
  
          public static IList<RegressionExecution> WithNamedColsSimple(IList<RegressionExecution> execs = null)
          {
              execs = execs ?? new List<RegressionExecution>();
              execs.Add(new EPLInsertIntoNamedColsSimple());
              return execs;
          }
  
          public static IList<RegressionExecution> WithNamedColsEPLToOMStmt(IList<RegressionExecution> execs = null)
          {
              execs = execs ?? new List<RegressionExecution>();
              execs.Add(new EPLInsertIntoNamedColsEPLToOMStmt());
              return execs;
          }
  
          public static IList<RegressionExecution> WithNamedColsOMToStmt(IList<RegressionExecution> execs = null)
          {
              execs = execs ?? new List<RegressionExecution>();
              execs.Add(new EPLInsertIntoNamedColsOMToStmt());
              return execs;
          }
  
          public static IList<RegressionExecution> WithRStreamOMToStmt(IList<RegressionExecution> execs = null)
          {
              execs = execs ?? new List<RegressionExecution>();
              execs.Add(new EPLInsertIntoRStreamOMToStmt());
              return execs;
          }
  
          public static IList<RegressionExecution> WithProvidePartitialCols(IList<RegressionExecution> execs = null)
          {
              execs = execs ?? new List<RegressionExecution>();
              execs.Add(new EPLInsertIntoProvidePartitialCols());
              return execs;
          }
  
          public static IList<RegressionExecution> WithSingleBeanToMulti(IList<RegressionExecution> execs = null)
          {
              execs = execs ?? new List<RegressionExecution>();
              execs.Add(new EPLInsertIntoSingleBeanToMulti());
              return execs;
          }
  
          public static IList<RegressionExecution> WithMultiBeanToMulti(IList<RegressionExecution> execs = null)
          {
              execs = execs ?? new List<RegressionExecution>();
              execs.Add(new EPLInsertIntoMultiBeanToMulti());
              return execs;
          }
  
          public static IList<RegressionExecution> WithChain(IList<RegressionExecution> execs = null)
          {
              execs = execs ?? new List<RegressionExecution>();
              execs.Add(new EPLInsertIntoChain());
              return execs;
          }
  
          public static IList<RegressionExecution> WithNullType(IList<RegressionExecution> execs = null)
          {
              execs = execs ?? new List<RegressionExecution>();
              execs.Add(new EPLInsertIntoNullType());
              return execs;
          }
  
          public static IList<RegressionExecution> WithInsertIntoPlusPattern(IList<RegressionExecution> execs = null)
          {
              execs = execs ?? new List<RegressionExecution>();
              execs.Add(new EPLInsertIntoInsertIntoPlusPattern());
              return execs;
          }
  
          public static IList<RegressionExecution> WithInsertFromPattern(IList<RegressionExecution> execs = null)
          {
              execs = execs ?? new List<RegressionExecution>();
              execs.Add(new EPLInsertIntoInsertFromPattern());
              return execs;
          }
  
          public static IList<RegressionExecution> WithStaggeredWithWildcard(IList<RegressionExecution> execs = null)
          {
              execs = execs ?? new List<RegressionExecution>();
              execs.Add(new EPLInsertIntoStaggeredWithWildcard());
              return execs;
          }
  
          public static IList<RegressionExecution> WithWithOutputLimitAndSort(IList<RegressionExecution> execs = null)
          {
              execs = execs ?? new List<RegressionExecution>();
              execs.Add(new EPLInsertIntoWithOutputLimitAndSort());
              return execs;
          }
  
          public static IList<RegressionExecution> WithJoinWildcard(IList<RegressionExecution> execs = null)
          {
              execs = execs ?? new List<RegressionExecution>();
              execs.Add(new EPLInsertIntoJoinWildcard());
              return execs;
          }
  
          public static IList<RegressionExecution> WithAssertionWildcardRecast(IList<RegressionExecution> execs = null)
          {
              execs = execs ?? new List<RegressionExecution>();
              execs.Add(new EPLInsertIntoAssertionWildcardRecast());
              return execs;
          }
  
          private static void TryAssertsVariant(
              RegressionEnvironment env,
              string stmtText,
              EPStatementObjectModel model,
              string typeName)
          {
              typeName = TypeHelper.MaskTypeName(typeName);
  
              var path = new RegressionPath();
              // Attach listener to feed
              if (model != null) {
                  model.Annotations = Collections.SingletonList(AnnotationPart.NameAnnotation("fl"));
                  env.CompileDeploy(model, path);
              }
              else {
                  env.CompileDeploy("@Name('fl') " + stmtText, path);
              }
  
              env.AddListener("fl");
  
              // send event for joins to match on
              env.SendEventBean(new SupportBean_A("myId"));
  
              // Attach delta statement to statement and add listener
              stmtText = "@Name('rld') select MIN(delta) as minD, max(delta) as maxD " +
                         "from " +
                         typeName +
                         "#time(60)";
              env.CompileDeploy(stmtText, path).AddListener("rld");
  
              // Attach prodict statement to statement and add listener
              stmtText = "@Name('rlp') select min(product) as minP, max(product) as maxP " +
                         "from " +
                         typeName +
                         "#time(60)";
              env.CompileDeploy(stmtText, path).AddListener("rlp");
  
              env.AdvanceTime(0); // Set the time to 0 seconds
  
              // send events
              SendEvent(env, 20, 10);
              AssertReceivedFeed(env.Listener("fl"), 10, 200);
              AssertReceivedMinMax(env.Listener("rld"), env.Listener("rlp"), 10, 10, 200, 200);
  
              SendEvent(env, 50, 25);
              AssertReceivedFeed(env.Listener("fl"), 25, 25 * 50);
              AssertReceivedMinMax(env.Listener("rld"), env.Listener("rlp"), 10, 25, 200, 1250);
  
              SendEvent(env, 5, 2);
              AssertReceivedFeed(env.Listener("fl"), 3, 2 * 5);
              AssertReceivedMinMax(env.Listener("rld"), env.Listener("rlp"), 3, 25, 10, 1250);
  
              env.AdvanceTime(10 * 1000); // Set the time to 10 seconds
  
              SendEvent(env, 13, 1);
              AssertReceivedFeed(env.Listener("fl"), 12, 13);
              AssertReceivedMinMax(env.Listener("rld"), env.Listener("rlp"), 3, 25, 10, 1250);
  
              env.AdvanceTime(61 * 1000); // Set the time to 61 seconds
              AssertReceivedMinMax(env.Listener("rld"), env.Listener("rlp"), 12, 12, 13, 13);
          }
  
          private static void AssertReceivedMinMax(
              SupportListener resultListenerDelta,
              SupportListener resultListenerProduct,
              int minDelta,
              int maxDelta,
              int minProduct,
              int maxProduct)
          {
              Assert.AreEqual(1, resultListenerDelta.NewDataList.Count);
              Assert.AreEqual(1, resultListenerDelta.LastNewData.Length);
              Assert.AreEqual(1, resultListenerProduct.NewDataList.Count);
              Assert.AreEqual(1, resultListenerProduct.LastNewData.Length);
              Assert.AreEqual(minDelta, resultListenerDelta.LastNewData[0].Get("minD"));
              Assert.AreEqual(maxDelta, resultListenerDelta.LastNewData[0].Get("maxD"));
              Assert.AreEqual(minProduct, resultListenerProduct.LastNewData[0].Get("minP"));
              Assert.AreEqual(maxProduct, resultListenerProduct.LastNewData[0].Get("maxP"));
              resultListenerDelta.Reset();
              resultListenerProduct.Reset();
          }
  
          private static void AssertReceivedFeed(
              SupportListener feedListener,
              int delta,
              int product)
          {
              Assert.AreEqual(1, feedListener.NewDataList.Count);
              Assert.AreEqual(1, feedListener.LastNewData.Length);
              Assert.AreEqual(delta, feedListener.LastNewData[0].Get("delta"));
              Assert.AreEqual(product, feedListener.LastNewData[0].Get("product"));
              feedListener.Reset();
          }
  
          private static SupportBean SendEvent(
              RegressionEnvironment env,
              int intPrimitive,
              int intBoxed)
          {
              var bean = new SupportBean();
              bean.TheString = "myId";
              bean.IntPrimitive = intPrimitive;
              bean.IntBoxed = intBoxed;
              env.SendEventBean(bean);
              return bean;
          }
  
          private static void AssertSimple(
              SupportListener listener,
              string myString,
              int myInt,
              string additionalString,
              int additionalInt)
          {
              Assert.IsTrue(listener.GetAndClearIsInvoked());
              var eventBean = listener.LastNewData[0];
              Assert.AreEqual(myString, eventBean.Get("MyString"));
              Assert.AreEqual(myInt, eventBean.Get("MyInt"));
              if (additionalString != null) {
                  Assert.AreEqual(additionalString, eventBean.Get("concat"));
                  Assert.AreEqual(additionalInt, eventBean.Get("summed"));
              }
          }
  
          private static void SendEvent(
              RegressionEnvironment env,
              string symbol,
              double price)
          {
              var bean = new SupportMarketDataBean(symbol, price, null, null);
              env.SendEventBean(bean);
          }
  
          private static void SendSimpleEvent(
              RegressionEnvironment env,
              string theString,
              int val)
          {
              env.SendEventBean(new SupportBeanSimple(theString, val));
          }
  
          private static void AssertJoinWildcard(
              EventRepresentationChoice? rep,
              SupportListener listener,
              object eventS0,
              object eventS1)
          {
              Assert.IsTrue(listener.GetAndClearIsInvoked());
              Assert.AreEqual(1, listener.LastNewData.Length);
              Assert.AreEqual(2, listener.LastNewData[0].EventType.PropertyNames.Length);
              Assert.IsTrue(listener.LastNewData[0].EventType.IsProperty("S0"));
              Assert.IsTrue(listener.LastNewData[0].EventType.IsProperty("S1"));
              if (rep != null && (rep.Value.IsJsonEvent() || rep.Value.IsJsonProvidedClassEvent())) {
                  Assert.AreEqual(
                      listener.LastNewData[0].Get("S0").ToString().RemoveWhitespace(),
                      eventS0.ToString().RemoveWhitespace());
                  Assert.AreEqual(
                      listener.LastNewData[0].Get("S1").ToString().RemoveWhitespace(),
                      eventS1.ToString().RemoveWhitespace());
              }
              else {
                  Assert.AreSame(eventS0, listener.LastNewData[0].Get("S0"));
                  Assert.AreSame(eventS1, listener.LastNewData[0].Get("S1"));
              }
  
              Assert.IsTrue(rep == null || rep.Value.MatchesClass(listener.LastNewData[0].Underlying.GetType()));
          }
  
          private static void TryAssertionJoinWildcard(
              RegressionEnvironment env,
              bool bean,
              EventRepresentationChoice? rep)
          {
              string schema;
  
              if (bean) {
                  schema = "@Name('schema1') create schema S0 as " +
                           typeof(SupportBean).FullName +
                           ";\n" +
                           "@Name('schema2') create schema S1 as " +
                           typeof(SupportBean_A).FullName +
                           ";\n";
              }
              else if (rep == null) {
                  throw new ArgumentException(nameof(rep));
              }
              else if (rep.Value.IsMapEvent()) {
                  Console.WriteLine($"Rep = {rep.Value}");
                  schema = "@Name('schema1') create map schema S0 as (TheString string);\n" +
                           "@Name('schema2') create map schema S1 as (Id string);\n";
              }
              else if (rep.Value.IsObjectArrayEvent()) {
                  Console.WriteLine($"Rep = {rep.Value}");
                  schema = "@Name('schema1') create objectarray schema S0 as (TheString string);\n" +
                           "@Name('schema2') create objectarray schema S1 as (Id string);\n";
              }
              else if (rep.Value.IsAvroEvent()) {
                  Console.WriteLine($"Rep = {rep.Value}");
                  schema = "@Name('schema1') create avro schema S0 as (TheString string);\n" +
                           "@Name('schema2') create avro schema S1 as (Id string);\n";
              }
              else if (rep.Value.IsJsonEvent()) {
                  Console.WriteLine($"Rep = {rep.Value}");
                  schema = "@Name('schema1') create json schema S0 as (TheString string);\n" +
                           "@Name('schema2') create json schema S1 as (Id string);\n";
              }
              else if (rep.Value.IsJsonProvidedClassEvent()) {
                  Console.WriteLine($"Rep = {rep.Value}");
                  schema = "@Name('schema1') @JsonSchema(ClassName='" +
                           typeof(MyLocalJsonProvidedS0).FullName +
                           "') create json schema S0 as ();\n" +
                           "@Name('schema2') @JsonSchema(ClassName='" +
                           typeof(MyLocalJsonProvidedS1).FullName +
                           "') create json schema S1 as ();\n";
              }
              else {
                  schema = null;
                  Assert.Fail();
              }
  
              var path = new RegressionPath();
              env.CompileDeployWBusPublicType(schema, path);
  
  
gt:             var textOne = "@Name('s1') " +