private static void RunAssertionDynamicDateFormat(RegressionEnvironment env) { var fields = "c0,c1,c2,c3".SplitCsv(); var builder = new SupportEvalBuilder("SupportBean_StringAlphabetic") .WithExpression(fields[0], "cast(A,long,dateformat:B)") .WithExpression(fields[1], "cast(A,datetime,dateformat:B)") .WithExpression(fields[2], "cast(A,datetimeoffset,dateformat:B)") .WithExpression(fields[3], "cast(A,dtx,dateformat:B)"); AssertDynamicDateFormat(builder, fields, "20100502", "yyyyMMdd"); AssertDynamicDateFormat(builder, fields, "20100502101112", "yyyyMMddhhmmss"); AssertDynamicDateFormat(builder, fields, null, "yyyyMMdd"); builder.Run(env); // invalid date try { env.SendEventBean(new SupportBean_StringAlphabetic("x", "yyyyMMddhhmmss")); } catch (EPException ex) { SupportMessageAssertUtil.AssertMessageContains(ex, "Exception parsing date 'x' format 'yyyyMMddhhmmss': Unparseable date: \"x\""); } // invalid format try { env.SendEventBean(new SupportBean_StringAlphabetic("20100502", "UUHHYY")); } catch (EPException ex) { SupportMessageAssertUtil.AssertMessageContains(ex, "Illegal pattern character 'U'"); } env.UndeployAll(); }
private void RunAssertionDynamicDateFormat() { var epl = "select " + "cast(a,date,dateformat:b) as c0," + "cast(a,long,dateformat:b) as c1" + " from SupportBean_StringAlphabetic"; EPStatement stmt = _epService.EPAdministrator.CreateEPL(epl); stmt.AddListener(_listener); RunAssertionDynamicDateFormat("20100502", "yyyyMMdd"); RunAssertionDynamicDateFormat("20100502101112", "yyyyMMddhhmmss"); RunAssertionDynamicDateFormat(null, "yyyyMMdd"); // invalid date try { _epService.EPRuntime.SendEvent(new SupportBean_StringAlphabetic("x", "yyyyMMddhhmmss")); } catch (EPException ex) { SupportMessageAssertUtil.AssertMessageContains(ex, "Exception parsing date 'x' format 'yyyyMMddhhmmss': String was not recognized as a valid DateTime"); } #if NO_ERROR_IN_CLR // invalid format try { _epService.EPRuntime.SendEvent(new SupportBean_StringAlphabetic("20100502", "UUHHYY")); } catch (EPException ex) { SupportMessageAssertUtil.AssertMessageContains(ex, "Illegal pattern character 'U'"); } #endif stmt.Dispose(); }
private void RunAssertionDynamicDateFormat(EPServiceProvider epService) { // try legacy date types var epl = "select " + "cast(a,date,dateformat:b) as c0," + "cast(a,dto,dateformat:b) as c1," + "cast(a,dtx,dateformat:b) as c2," + "cast(a,long,dateformat:b) as c3" + " from SupportBean_StringAlphabetic"; var stmt = epService.EPAdministrator.CreateEPL(epl); var listener = new SupportUpdateListener(); stmt.Events += listener.Update; RunAssertionDynamicDateFormat(epService, listener, "20100502", "yyyyMMdd"); RunAssertionDynamicDateFormat(epService, listener, "20100502101112", "yyyyMMddhhmmss"); RunAssertionDynamicDateFormat(epService, listener, null, "yyyyMMdd"); // invalid date try { epService.EPRuntime.SendEvent(new SupportBean_StringAlphabetic("x", "yyyyMMddhhmmss")); } catch (EPException ex) { SupportMessageAssertUtil.AssertMessageContains(ex, "Exception parsing date 'x' format 'yyyyMMddhhmmss': String was not recognized as a valid DateTime."); } #if NO_ERROR_IN_CLR // invalid format try { epService.EPRuntime.SendEvent(new SupportBean_StringAlphabetic("20100502", "UUHHYY")); } catch (EPException ex) { SupportMessageAssertUtil.AssertMessageContains(ex, "Illegal pattern character 'U'"); } #endif stmt.Dispose(); }