public static void VerifyQuery(string query, MetadataWorkspace workspace, string expectedSql) { var providerServices = (DbProviderServices)((IServiceProvider)EntityProviderFactory.Instance).GetService(typeof(DbProviderServices)); var connection = new EntityConnection(workspace, new EntityConnection()); var commandTree = workspace.CreateEntitySqlParser().Parse(query).CommandTree; var entityCommand = (EntityCommand)providerServices.CreateCommandDefinition(commandTree).CreateCommand(); entityCommand.Connection = connection; Assert.Equal(StripFormatting(expectedSql), StripFormatting(entityCommand.ToTraceString())); }
public static void VerifyThrows <TException>(string query, MetadataWorkspace workspace, string resourceKey, bool isExactMatch, params string[] exceptionMessageParameters) { var exceptionThrown = false; try { var providerServices = (DbProviderServices)((IServiceProvider)EntityProviderFactory.Instance).GetService(typeof(DbProviderServices)); var connection = new EntityConnection(workspace, new SqlConnection()); var commandTree = workspace.CreateEntitySqlParser().Parse(query).CommandTree; var entityCommand = (EntityCommand)providerServices.CreateCommandDefinition(commandTree).CreateCommand(); entityCommand.Connection = connection; entityCommand.ToTraceString(); } catch (Exception e) { exceptionThrown = true; var innermostException = GetInnerMostException(e); Assert.IsType <TException>(innermostException); innermostException.ValidateMessage(typeof(DbContext).Assembly(), resourceKey, null, isExactMatch, exceptionMessageParameters); } Assert.True(exceptionThrown, "No excepion has been thrown."); }
public static void VerifyThrows <TException>(string query, MetadataWorkspace workspace, string expectedExeptionMessage) { var exceptionThrown = false; try { var providerServices = (DbProviderServices)((IServiceProvider)EntityProviderFactory.Instance).GetService(typeof(DbProviderServices)); var connection = new EntityConnection(workspace, new EntityConnection()); var commandTree = workspace.CreateEntitySqlParser().Parse(query).CommandTree; var entityCommand = (EntityCommand)providerServices.CreateCommandDefinition(commandTree).CreateCommand(); entityCommand.Connection = connection; entityCommand.ToTraceString(); } catch (Exception e) { exceptionThrown = true; var innermostException = GetInnerMostException(e); Assert.IsType <TException>(innermostException); Assert.Equal(expectedExeptionMessage, innermostException.Message); } Assert.True(exceptionThrown, "No excepion has been thrown."); }