private void RunAssertionStreamInsertWWidenMap(TypeTested typeTested)
        {
            EPServiceProvider epService = EPServiceProviderManager.GetDefaultProvider();

            epService.EPAdministrator.CreateEPL("create " + GetText(typeTested) + " schema Src as (myint int, mystr string)");

            epService.EPAdministrator.CreateEPL("create " + GetText(typeTested) + " schema D1 as (myint int, mystr string, addprop long)");
            String eplOne = "insert into D1 select 1 as addprop, mysrc.* from Src as mysrc";

            RunStreamInsertAssertion(typeTested, eplOne, "myint,mystr,addprop", new Object[] { 123, "abc", 1L });

            epService.EPAdministrator.CreateEPL("create " + GetText(typeTested) + " schema D2 as (mystr string, myint int, addprop double)");
            String eplTwo = "insert into D2 select 1 as addprop, mysrc.* from Src as mysrc";

            RunStreamInsertAssertion(typeTested, eplTwo, "myint,mystr,addprop", new Object[] { 123, "abc", 1d });

            epService.EPAdministrator.CreateEPL("create " + GetText(typeTested) + " schema D3 as (mystr string, addprop int)");
            String eplThree = "insert into D3 select 1 as addprop, mysrc.* from Src as mysrc";

            RunStreamInsertAssertion(typeTested, eplThree, "mystr,addprop", new Object[] { "abc", 1 });

            epService.EPAdministrator.CreateEPL("create " + GetText(typeTested) + " schema D4 as (myint int, mystr string)");
            String eplFour = "insert into D4 select mysrc.* from Src as mysrc";

            RunStreamInsertAssertion(typeTested, eplFour, "myint,mystr", new Object[] { 123, "abc" });

            String eplFive = "insert into D4 select mysrc.*, 999 as myint, 'xxx' as mystr from Src as mysrc";

            RunStreamInsertAssertion(typeTested, eplFive, "myint,mystr", new Object[] { 999, "xxx" });
            String eplSix = "insert into D4 select 999 as myint, 'xxx' as mystr, mysrc.* from Src as mysrc";

            RunStreamInsertAssertion(typeTested, eplSix, "myint,mystr", new Object[] { 999, "xxx" });
        }
        internal static string GetText(TypeTested type)
        {
            switch (type)
            {
            case TypeTested.MAP:
                return("map");

            case TypeTested.OA:
                return("objectarray");
            }

            throw new ArgumentException();
        }
        public void RunAssertionInvalid(TypeTested typeTested)
        {
            _epService.EPAdministrator.CreateEPL("create " + GetText(typeTested) + " schema Src as (myint int, mystr string)");

            // mismatch in type
            _epService.EPAdministrator.CreateEPL("create " + GetText(typeTested) + " schema E1 as (myint long)");
            TryInvalid("insert into E1 select mysrc.* from Src as mysrc",
                       "Error starting statement: Type by name 'E1' in property 'myint' expected " + typeof(int?) + " but receives " + typeof(long?) + " [insert into E1 select mysrc.* from Src as mysrc]");

            // mismatch in column name
            _epService.EPAdministrator.CreateEPL("create " + GetText(typeTested) + " schema E2 as (someprop long)");
            TryInvalid("insert into E2 select mysrc.*, 1 as otherprop from Src as mysrc",
                       "Error starting statement: Failed to find column 'otherprop' in target type 'E2' [insert into E2 select mysrc.*, 1 as otherprop from Src as mysrc]");
        }
        private void RunAssertionNamedWindow(TypeTested typeTested)
        {
            if (typeTested == TypeTested.MAP)
            {
                IDictionary <String, Object> typeinfo = new Dictionary <String, Object>();
                typeinfo.Put("myint", typeof(int));
                typeinfo.Put("mystr", typeof(String));
                _epService.EPAdministrator.Configuration.AddEventType("A", typeinfo);
                _epService.EPAdministrator.CreateEPL("create map schema C as (addprop int) inherits A");
            }
            else if (typeTested == TypeTested.OA)
            {
                _epService.EPAdministrator.Configuration.AddEventType("A", new String[] { "myint", "mystr" }, new Object[] { typeof(int), typeof(String) });
                _epService.EPAdministrator.CreateEPL("create objectarray schema C as (addprop int) inherits A");
            }

            _epService.EPAdministrator.CreateEPL("create window MyWindow.win:time(5 days) as C");

            EPStatement stmt = _epService.EPAdministrator.CreateEPL("select * from MyWindow");

            stmt.Events += _listener.Update;

            // select underlying
            EPStatement stmtInsert = _epService.EPAdministrator.CreateEPL("insert into MyWindow select mya.* from A as mya");

            if (typeTested == TypeTested.MAP)
            {
                _epService.EPRuntime.SendEvent(MakeMap(123, "abc"), "A");
            }
            else if (typeTested == TypeTested.OA)
            {
                _epService.EPRuntime.SendEvent(new Object[] { 123, "abc" }, "A");
            }
            EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), "myint,mystr,addprop".Split(','), new Object[] { 123, "abc", null });
            stmtInsert.Dispose();

            // select underlying plus property
            _epService.EPAdministrator.CreateEPL("insert into MyWindow select mya.*, 1 as addprop from A as mya");
            if (typeTested == TypeTested.MAP)
            {
                _epService.EPRuntime.SendEvent(MakeMap(456, "def"), "A");
            }
            else if (typeTested == TypeTested.OA)
            {
                _epService.EPRuntime.SendEvent(new Object[] { 456, "def" }, "A");
            }
            EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), "myint,mystr,addprop".Split(','), new Object[] { 456, "def", 1 });
        }
        private void RunStreamInsertAssertion(TypeTested typeTested, String epl, String fields, Object[] expected)
        {
            EPStatement stmt = _epService.EPAdministrator.CreateEPL(epl);

            stmt.Events += _listener.Update;
            if (TypeTested.MAP == typeTested)
            {
                _epService.EPRuntime.SendEvent(MakeMap(123, "abc"), "Src");
            }
            else
            {
                _epService.EPRuntime.SendEvent(new Object[] { 123, "abc" }, "Src");
            }
            EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields.Split(','), expected);
            stmt.Dispose();
        }