public void ExecuteSqlRuntimeTask_InvalidID(DatabaseType dbType) { var dt = new DataTable(); dt.Columns.Add("Lawl"); dt.Rows.Add(new object[] { 2 }); var db = GetCleanedServer(dbType, true); var tbl = db.CreateTable("Fish", dt); TableInfo ti; ColumnInfo[] cols; Import(tbl, out ti, out cols); string sql = @"UPDATE {T:0} Set {C:0} = 1"; IRuntimeTask task; IProcessTask pt; var dir = LoadDirectory.CreateDirectoryStructure(new DirectoryInfo(TestContext.CurrentContext.TestDirectory), "ExecuteSqlFileRuntimeTaskTests", true); var sqlArg = new IArgument[] { Mock.Of <IArgument>(x => x.Name == "Sql" && x.Value == sql && x.GetValueAsSystemType() == sql) }; var args = new RuntimeArgumentCollection(sqlArg, new StageArgs(LoadStage.AdjustRaw, db, dir)); pt = Mock.Of <IProcessTask>(x => x.Path == typeof(ExecuteSqlMutilation).FullName && x.GetAllArguments() == sqlArg ); task = new MutilateDataTablesRuntimeTask(pt, args, CatalogueRepository.MEF); task.Check(new ThrowImmediatelyCheckNotifier()); HICDatabaseConfiguration configuration = new HICDatabaseConfiguration(db.Server); var job = new ThrowImmediatelyDataLoadJob(); job.RegularTablesToLoad = new List <ITableInfo> { ti }; job.LookupTablesToLoad = new List <ITableInfo>(); job.Configuration = configuration; var ex = Assert.Throws <Exception>(() => task.Run(job, new GracefulCancellationToken())); StringAssert.Contains("Mutilate failed", ex.Message); StringAssert.Contains("Failed to find a TableInfo in the load with ID 0", ex.InnerException.Message); task.LoadCompletedSoDispose(Core.DataLoad.ExitCodeType.Success, new ThrowImmediatelyDataLoadEventListener()); }
public void GatherAndShare_LoadMetadata_WithReferenceProcessTaskArgument() { //create an object LoadMetadata lmd1 = WhenIHaveA <LoadMetadata>(); //setup Reflection / MEF SetupMEF(); RuntimeTaskFactory f = new RuntimeTaskFactory(Repository); var stg = Mock.Of <IStageArgs>(x => x.LoadStage == LoadStage.Mounting && x.DbInfo == new DiscoveredServer(new SqlConnectionStringBuilder()).ExpectDatabase("d")); //create a single process task for the load var pt1 = new ProcessTask(Repository, lmd1, LoadStage.Mounting); pt1.ProcessTaskType = ProcessTaskType.MutilateDataTable; pt1.LoadStage = LoadStage.AdjustRaw; pt1.Path = typeof(SafePrimaryKeyCollisionResolverMutilation).FullName; pt1.SaveToDatabase(); //give it a reference to an (unshared) object (ColumnInfo) pt1.CreateArgumentsForClassIfNotExists(typeof(SafePrimaryKeyCollisionResolverMutilation)); var pta = pt1.ProcessTaskArguments.Single(pt => pt.Name == "ColumnToResolveOn"); pta.SetValue(WhenIHaveA <ColumnInfo>()); pta.SaveToDatabase(); //check that reflection can assemble the master ProcessTask MutilateDataTablesRuntimeTask t = (MutilateDataTablesRuntimeTask)f.Create(pt1, stg); Assert.IsNotNull(((SafePrimaryKeyCollisionResolverMutilation)t.MEFPluginClassInstance).ColumnToResolveOn); //share to the second repository (which won't have that ColumnInfo) var lmd2 = ShareToNewRepository(lmd1); //create a new reflection factory for the new repo RuntimeTaskFactory f2 = new RuntimeTaskFactory(lmd2.CatalogueRepository); lmd2.CatalogueRepository.MEF = MEF; //when we create the shared instance it should not have a valid value for ColumnInfo (since it wasn't - and shouldn't be shared) MutilateDataTablesRuntimeTask t2 = (MutilateDataTablesRuntimeTask)f2.Create(lmd2.ProcessTasks.Single(), stg); Assert.IsNull(((SafePrimaryKeyCollisionResolverMutilation)t2.MEFPluginClassInstance).ColumnToResolveOn); }