public void TestThatConstructorInitializeEventArgs() { var fixture = new Fixture(); fixture.Customize <IDataSource>(e => e.FromFactory(() => MockRepository.GenerateMock <IDataSource>())); fixture.Customize <ITable>(e => e.FromFactory(() => MockRepository.GenerateMock <ITable>())); var dataSourceMock = fixture.CreateAnonymous <IDataSource>(); var targetTableMock = fixture.CreateAnonymous <ITable>(); var dataBlock = fixture.CreateAnonymous <int>(); var rowsInDataBlock = fixture.CreateAnonymous <int>(); var eventArgs = new ValidateDataInTargetTableEventArgs(dataSourceMock, targetTableMock, dataBlock, rowsInDataBlock); Assert.That(eventArgs, Is.Not.Null); Assert.That(eventArgs.DataSource, Is.Not.Null); Assert.That(eventArgs.DataSource, Is.EqualTo(dataSourceMock)); Assert.That(eventArgs.TargetTable, Is.Not.Null); Assert.That(eventArgs.TargetTable, Is.EqualTo(targetTableMock)); Assert.That(eventArgs.DataBlock, Is.EqualTo(dataBlock)); Assert.That(eventArgs.RowsInDataBlock, Is.EqualTo(rowsInDataBlock)); }
/// <summary> /// Event handler for handling data on a given target table. /// </summary> /// <param name="sender">Object which raises the event.</param> /// <param name="eventArgs">Arguments to the event.</param> private void HandleDataForTargetTable(object sender, IHandleDataEventArgs eventArgs) { if (sender == null) { throw new ArgumentNullException("sender"); } if (eventArgs == null) { throw new ArgumentNullException("eventArgs"); } var table = eventArgs.Table; var tableData = new Dictionary <ITable, IEnumerable <IEnumerable <IDataObjectBase> > > { { table, eventArgs.Data } }; var tuple = _tableInformations[table]; var dataSource = tuple.Item1; var command = tuple.Item2; var tableWorker = tuple.Item3; if (tableWorker.CancellationPending) { throw new ThreadInterruptedException(); } // Validate received data for the target table. if (DataValidators.Any()) { IValidateDataInTargetTableEventArgs validateDataInTargetTableEventArgs; lock (_syncRoot) { validateDataInTargetTableEventArgs = new ValidateDataInTargetTableEventArgs(dataSource, table, _tableDataBlock[table], tableData.Select(m => m.Value).Sum(m => m.Count())); } RaiseEvent(BeforeValidateDataInTargetTable, validateDataInTargetTableEventArgs); var validationWorkers = new Collection <BackgroundWorker>(); try { foreach (var dataValidator in DataValidators) { if (tableWorker.CancellationPending) { throw new ThreadInterruptedException(); } var validationWorker = new BackgroundWorker { WorkerReportsProgress = false, WorkerSupportsCancellation = true }; validationWorker.DoWork += ValidationDoWork; validationWorker.RunWorkerCompleted += WorkerCompleted; validationWorker.Disposed += (s, e) => validationWorkers.Remove((BackgroundWorker)s); validationWorkers.Add(validationWorker); validationWorker.RunWorkerAsync(new Tuple <IDataValidator, ITable, IDictionary <ITable, IEnumerable <IEnumerable <IDataObjectBase> > >, bool, IDeliveryEngineExecuteCommand>(dataValidator, table, tableData, eventArgs.EndOfData, command)); } while (validationWorkers.Any(m => m.IsBusy)) { if (tableWorker.CancellationPending) { throw new ThreadInterruptedException(); } Thread.Sleep(250); } } finally { foreach (var validationWorker in validationWorkers.Where(m => m.IsBusy)) { validationWorker.CancelAsync(); } while (validationWorkers.Any(m => m.IsBusy)) { Thread.Sleep(250); } while (validationWorkers.Count > 0) { var validationWorker = validationWorkers.ElementAt(0); validationWorker.Dispose(); validationWorkers.Remove(validationWorker); } } } if (tableWorker.CancellationPending) { throw new ThreadInterruptedException(); } // Archive the received data for the target table. if (command.ValidationOnly == false) { IArchiveDataForTargetTableEventArgs archiveDataForTargetTableEventArgs; lock (_syncRoot) { archiveDataForTargetTableEventArgs = new ArchiveDataForTargetTableEventArgs(dataSource, table, _tableDataBlock[table], tableData.Select(m => m.Value).Sum(m => m.Count())); } RaiseEvent(BeforeArchiveDataForTargetTable, archiveDataForTargetTableEventArgs); ArchiveVersionRepository.ArchiveTableData(tableData, command.IncludeEmptyTables, _syncRoot); } if (tableWorker.CancellationPending) { throw new ThreadInterruptedException(); } if (eventArgs.EndOfData) { return; } IGetDataForTargetTableEventArgs getDataForTargetTableEventArgs; lock (_syncRoot) { _tableDataBlock[table] += 1; getDataForTargetTableEventArgs = new GetDataForTargetTableEventArgs(dataSource, table, _tableDataBlock[table]); } RaiseEvent(BeforeGetDataForTargetTable, getDataForTargetTableEventArgs); }