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.scopetest;
  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.compiler.client;
  using com.espertech.esper.regressionlib.framework;
  using com.espertech.esper.regressionlib.support.bean;
  
  using NEsper.Avro.Extensions;
  
  using Newtonsoft.Json.Linq;
  
  using NUnit.Framework;
  
  using static com.espertech.esper.regressionlib.framework.SupportMessageAssertUtil;
  
  using static NEsper.Avro.Extensions.TypeBuilder;
  
  using SupportBean_A = com.espertech.esper.regressionlib.support.bean.SupportBean_A;
  using SupportBeanComplexProps = com.espertech.esper.regressionlib.support.bean.SupportBeanComplexProps;
  
  namespace com.espertech.esper.regressionlib.suite.epl.insertinto
  {
      public class EPLInsertIntoTransposeStream
      {
          public static IList<RegressionExecution> Executions()
          {
              IList<RegressionExecution> execs = new List<RegressionExecution>();
              WithTransposeCreateSchemaPONO(execs);
              WithTransposeMapAndObjectArrayAndOthers(execs);
              WithTransposeFunctionToStreamWithProps(execs);
              WithTransposeFunctionToStream(execs);
              WithTransposeSingleColumnInsert(execs);
              WithTransposeEventJoinMap(execs);
              WithTransposeEventJoinPONO(execs);
              WithTransposePONOPropertyStream(execs);
              WithInvalidTranspose(execs);
              return execs;
          }
  
          public static IList<RegressionExecution> WithInvalidTranspose(IList<RegressionExecution> execs = null)
          {
              execs = execs ?? new List<RegressionExecution>();
              execs.Add(new EPLInsertIntoInvalidTranspose());
              return execs;
          }
  
          public static IList<RegressionExecution> WithTransposePONOPropertyStream(IList<RegressionExecution> execs = null)
          {
              execs = execs ?? new List<RegressionExecution>();
              execs.Add(new EPLInsertIntoTransposePONOPropertyStream());
              return execs;
          }
  
          public static IList<RegressionExecution> WithTransposeEventJoinPONO(IList<RegressionExecution> execs = null)
          {
              execs = execs ?? new List<RegressionExecution>();
              execs.Add(new EPLInsertIntoTransposeEventJoinPONO());
              return execs;
          }
  
          public static IList<RegressionExecution> WithTransposeEventJoinMap(IList<RegressionExecution> execs = null)
          {
              execs = execs ?? new List<RegressionExecution>();
              execs.Add(new EPLInsertIntoTransposeEventJoinMap());
              return execs;
          }
  
          public static IList<RegressionExecution> WithTransposeSingleColumnInsert(IList<RegressionExecution> execs = null)
          {
              execs = execs ?? new List<RegressionExecution>();
              execs.Add(new EPLInsertIntoTransposeSingleColumnInsert());
              return execs;
          }
  
          public static IList<RegressionExecution> WithTransposeFunctionToStream(IList<RegressionExecution> execs = null)
          {
              execs = execs ?? new List<RegressionExecution>();
              execs.Add(new EPLInsertIntoTransposeFunctionToStream());
              return execs;
          }
  
          public static IList<RegressionExecution> WithTransposeFunctionToStreamWithProps(IList<RegressionExecution> execs = null)
          {
              execs = execs ?? new List<RegressionExecution>();
              execs.Add(new EPLInsertIntoTransposeFunctionToStreamWithProps());
              return execs;
          }
  
          public static IList<RegressionExecution> WithTransposeMapAndObjectArrayAndOthers(IList<RegressionExecution> execs = null)
          {
              execs = execs ?? new List<RegressionExecution>();
              execs.Add(new EPLInsertIntoTransposeMapAndObjectArrayAndOthers());
              return execs;
          }
  
          public static IList<RegressionExecution> WithTransposeCreateSchemaPONO(IList<RegressionExecution> execs = null)
          {
              execs = execs ?? new List<RegressionExecution>();
              execs.Add(new EPLInsertIntoTransposeCreateSchemaPONO());
              return execs;
          }
  
          private static IDictionary<string, object> MakeMap(object[][] entries)
          {
              var result = new Dictionary<string, object>();
              foreach (var entry in entries) {
                  result.Put((string) entry[0], entry[1]);
              }
  
              return result;
          }
  
          public static IDictionary<string, object> LocalGenerateMap(
              string @string,
              int intPrimitive)
          {
              var @out = new Dictionary<string, object>();
              @out.Put("p0", @string);
              @out.Put("p1", intPrimitive);
              return @out;
          }
  
          public static object[] LocalGenerateOA(
              string @string,
              int intPrimitive)
          {
              return new object[] {@string, intPrimitive};
          }
  
          public static GenericRecord LocalGenerateAvro(
              string @string,
              int intPrimitive)
          {
              var schema = SchemaBuilder.Record("name", RequiredString("p0"), RequiredInt("p1"));
              var record = new GenericRecord(schema);
              record.Put("p0", @string);
              record.Put("p1", intPrimitive);
              return record;
          }
  
          public static String LocalGenerateJson(
              string @string,
              int intPrimitive)
          {
              var @object = new JObject();
              @object.Add("p0", @string);
              @object.Add("p1", intPrimitive);
              return @object.ToString();
          }
  
          public static SupportBeanTwo MakeSB2Event(SupportBean sb)
          {
              return new SupportBeanTwo(sb.TheString, sb.IntPrimitive);
          }
  
          internal class EPLInsertIntoTransposeCreateSchemaPONO : RegressionExecution
          {
              public void Run(RegressionEnvironment env)
              {
                  String epl = "create schema SupportBeanTwo as " +
                               typeof(SupportBeanTwo).FullName +
                               ";\n" +
                               "on SupportBean event insert into astream select transpose(" +
                               typeof(EPLInsertIntoTransposeStream).FullName +
                               ".MakeSB2Event(event));\n" +
                               "on SupportBean event insert into bstream select transpose(" +
                               typeof(EPLInsertIntoTransposeStream).FullName +
                               ".MakeSB2Event(event));\n" +
                               "@Name('a') select * from astream\n;" +
                               "@Name('b') select * from bstream\n;";
                  env.CompileDeploy(epl).AddListener("a").AddListener("b");
  
                  env.SendEventBean(new SupportBean("E1", 1));
  
                  String[] fields = new String[] {"StringTwo"};
                  EPAssertionUtil.AssertProps(env.Listener("a").AssertOneGetNewAndReset(), fields, new Object[] {"E1"});
                  EPAssertionUtil.AssertProps(env.Listener("b").AssertOneGetNewAndReset(), fields, new Object[] {"E1"});
  
                  env.UndeployAll();
              }
          }
  
          internal class EPLInsertIntoTransposeMapAndObjectArrayAndOthers : RegressionExecution
          {
              public void Run(RegressionEnvironment env)
              {
                  foreach (var rep in EventRepresentationChoiceExtensions.Values()) {
                      RunTransposeMapAndObjectArray(env, rep);
                  }
              }
  
              private static void RunTransposeMapAndObjectArray(
                  RegressionEnvironment env,
                  EventRepresentationChoice representation)
              {
                  var fields = new[] {"p0", "p1"};
                  var path = new RegressionPath();
                  var schema = representation.GetAnnotationTextWJsonProvided<MyLocalJsonProvidedMySchema>() + "create schema MySchema(p0 string, p1 int)";
                  env.CompileDeployWBusPublicType(schema, path);
  
                  string generateFunction;
                  if (representation.IsObjectArrayEvent()) {
                      generateFunction = "GenerateOA";
                  }
                  else if (representation.IsMapEvent()) {
                      generateFunction = "GenerateMap";
                  }
  
gt:                 else if (representation.IsAvroEvent()) {