protected override void AssertState(DataTable data, TDataContext dataContext, DataTable[] allData, ITestOutputHelper testOutputHelper) { // You can use some helper methods to perform some quality assertions // on the data table, ensuring the view contract still matches the entity type // used in the DbQuery<TEntity> or DbSet<TEntity>. data.AssertHasModelProperties <TEntity>(testOutputHelper); }
protected override void AssertState(DataTable data, TDataContext dataContext, DataTable[] allData, ITestOutputHelper testOutputHelper) { Assert.True(data != null, "Failed to execute test against database object. Data Table is null"); var actualColumnNames = data.Columns.Cast <DataColumn>().Select(i => i.ColumnName).ToArray(); var hasAllExpectedColumns = true; foreach (var expected in this.ExpectedReturnColumnNames) { if (!actualColumnNames.Contains(expected, StringComparer.InvariantCultureIgnoreCase)) { this.TestOutputHelper.WriteLine($"{DbObjectType} {this.DbObjectName} failed to return expected column named {expected}"); hasAllExpectedColumns = false; } } foreach (var actual in actualColumnNames) { if (!ExpectedReturnColumnNames.Contains(actual, StringComparer.InvariantCultureIgnoreCase)) { this.TestOutputHelper.WriteLine($"{DbObjectType} {this.DbObjectName} returned an unexpected column named {actual}"); hasAllExpectedColumns = false; } } Assert.True(hasAllExpectedColumns); }
/// <summary> /// Create a data context outside of the AppContext with default options. NOTE: the returned data context is not tracked by the app context and must be disposed by the caller if it implements IDisposable. /// </summary> public TDataContext CreateDataContext <TDataContext, T>() where T : class, new() where TDataContext : DataContext <T>, new() { TDataContext result = new TDataContext(); result.InitializeDataContext(this); return(result); }
/// <summary> /// Creates a new Data Context for a specific DataContext type /// /// Provided merely for compleness sake here - same as new YourDataContext() /// </summary> /// <typeparam name="TDataContext"></typeparam> /// <returns></returns> public static TDataContext GetDataContext <TDataContext>() where TDataContext : DataContext, new() { var DataContexts = new TDataContext(); DataContexts.ObjectTrackingEnabled = false; return(DataContexts); // (TDataContext)Activator.CreateInstance<TDataContext>(); }
/// <summary> /// Retrieve a data context from the app context or create it with default options. /// </summary> public TDataContext GetOrCreateDataContext <TDataContext, T>() where T : class, new() where TDataContext : DataContext <T>, new() { Type type = typeof(TDataContext); TDataContext result = (TDataContext)GetSharedDataObject(type); if (result == null) { lock (_sharedObjectsSyncRoot) { result = (TDataContext)GetSharedDataObject(type); if (result == null) { result = CreateDataContext <TDataContext, T>(); AddSharedDataObject(type, result); } } } return(result); }
/// <summary> /// (hook) /// Write your assert statements here. /// You can reference the entities in the data context, or examine the data tables populated from the ACT method. /// </summary> /// <param name="data">First data table read</param> /// <param name="dataContext">EF Data Context</param> /// <param name="allData">All the data table read</param> /// <param name="testOutputHelper">Test Output Helper. Use this to write messages to the test output.</param> protected abstract void AssertState(DataTable data, TDataContext dataContext, DataTable[] allData, ITestOutputHelper testOutputHelper);
/// <summary> /// (hook) /// Return the sql text to execute as part of the ACT phase of the test. /// Or you may modify the data context directly. /// </summary> /// <returns>the sql text to execute</returns> protected abstract SqlRequest Act(IDbTestRunnerContext context, TDataContext dataContext, ITestOutputHelper testOutputHelper);
protected override SqlRequest Act(IDbTestRunnerContext context, TDataContext dataContext, ITestOutputHelper testOutputHelper) { var functionParameters = GetParametersForDbObject(this.FunctionName, context); return(this.InvokeTableFunction(this.FunctionName, this.SchemaName, functionParameters)); }
protected override SqlRequest Act(IDbTestRunnerContext context, TDataContext dataContext, ITestOutputHelper testOutputHelper) { // return just an empty data set so we can examine the shape of the return object. return(SqlRequest.ReturnNoRows(this.GetQualifiedTableOrViewName <TEntity>(this.TableOrViewName, this.Schema))); }
protected override SqlRequest Arrange(IDbTestRunnerContext context, TDataContext dataContext, ITestOutputHelper testOutputHelper) { return(this.DoNothing()); }
protected override SqlRequest Act(IDbTestRunnerContext context, TDataContext dataContext, ITestOutputHelper testOutputHelper) { var parameters = this.GetParametersForDbObject(this.StoredProcedureName, context); return(this.ExecuteStoredProcedure(this.DbObjectName, this.SchemaName, parameters)); }