public void TestThatEqualsReturnsFalseIfTargetNameIsNotEqualOnNameObjects()
        {
            var fixture = new Fixture();

            fixture.Customize <INamedObject>(e => e.FromFactory(() =>
            {
                var nameObjectMock = MockRepository.GenerateMock <INamedObject>();
                nameObjectMock.Expect(m => m.NameTarget)
                .Return(fixture.CreateAnonymous <string>())
                .Repeat.Any();
                return(nameObjectMock);
            }));

            var comparer = new NameTargetComparer();

            Assert.That(comparer, Is.Not.Null);

            var x = fixture.CreateAnonymous <INamedObject>();
            var y = fixture.CreateAnonymous <INamedObject>();

            Assert.That(comparer.Equals(x, y), Is.False);

            x.AssertWasCalled(m => m.NameTarget, opt => opt.Repeat.Times(1));
            y.AssertWasCalled(m => m.NameTarget, opt => opt.Repeat.Times(1));
        }
        public void TestThatGetHashCodeThrowsArgumentNullExceptionIfNameObjectIsNull()
        {
            var comparer = new NameTargetComparer();

            Assert.That(comparer, Is.Not.Null);

            Assert.Throws <ArgumentNullException>(() => comparer.GetHashCode(null));
        }
        public void TestThatEqualsThrowsArgumentNullExceptionIfYIsNull()
        {
            var fixture = new Fixture();

            fixture.Customize <INamedObject>(e => e.FromFactory(() => MockRepository.GenerateMock <INamedObject>()));

            var comparer = new NameTargetComparer();

            Assert.That(comparer, Is.Not.Null);

            Assert.Throws <ArgumentNullException>(() => comparer.Equals(fixture.CreateAnonymous <INamedObject>(), null));
        }
        public void TestThatGetHashCodeGetsHashCode()
        {
            var fixture = new Fixture();

            fixture.Customize <INamedObject>(e => e.FromFactory(() =>
            {
                var nameObjectMock = MockRepository.GenerateMock <INamedObject>();
                nameObjectMock.Expect(m => m.NameTarget)
                .Return(fixture.CreateAnonymous <string>())
                .Repeat.Any();
                return(nameObjectMock);
            }));

            var comparer = new NameTargetComparer();

            Assert.That(comparer, Is.Not.Null);

            var namedObject = fixture.CreateAnonymous <INamedObject>();

            Assert.That(comparer.GetHashCode(namedObject), Is.EqualTo(namedObject.NameTarget.GetHashCode()));

            namedObject.AssertWasCalled(m => m.NameTarget, opt => opt.Repeat.Times(3));
        }
        public void TestThatGetHashCodeThrowsDeliveryEngineSystemExceptionIfTargetNameOnNamedObjectIsNull()
        {
            var fixture = new Fixture();

            fixture.Customize <INamedObject>(e => e.FromFactory(() =>
            {
                var nameObjectMock = MockRepository.GenerateMock <INamedObject>();
                nameObjectMock.Expect(m => m.NameTarget)
                .Return(null)
                .Repeat.Any();
                return(nameObjectMock);
            }));

            var comparer = new NameTargetComparer();

            Assert.That(comparer, Is.Not.Null);

            var namedObject = fixture.CreateAnonymous <INamedObject>();

            Assert.Throws <DeliveryEngineSystemException>(() => comparer.GetHashCode(namedObject));

            namedObject.AssertWasCalled(m => m.NameTarget, opt => opt.Repeat.Times(2));
        }
Exemple #6
0
        /// <summary>
        /// Execute the delivery engine to create and write the delivery format.
        /// </summary>
        /// <param name="command">Command for executing the delivery engine.</param>
        public virtual void Execute(IDeliveryEngineExecuteCommand command)
        {
            if (command == null)
            {
                throw new ArgumentNullException("command");
            }
            try
            {
                // Get the data source.
                RaiseEvent(BeforeGetDataSource, new GetDataSourceEventArgs());
                var dataSource = MetadataRepository.DataSourceGet();
                if (!string.IsNullOrEmpty(command.OverrideArchiveInformationPackageId))
                {
                    dataSource.ArchiveInformationPackageId = command.OverrideArchiveInformationPackageId;
                }
                ArchiveVersionRepository.DataSource = dataSource;

                // Archive the metadata for the data source.
                if (command.ValidationOnly == false)
                {
                    RaiseEvent(BeforeArchiveMetadata, new ArchiveMetadataEventArgs(dataSource));
                    ArchiveVersionRepository.ArchiveMetaData();
                }

                // Handle and archive any target tables included in the data source.
                DataRepository.OnHandleData += HandleDataForTargetTable;
                DataRepository.OnClone      += DataRepositoryCloned;
                var tableWorkers = new Collection <BackgroundWorker>();
                try
                {
                    var namedObjectComparer = new NameTargetComparer();
                    var targetTables        = dataSource.Tables
                                              .Where(m => string.IsNullOrEmpty(m.NameTarget) == false && (string.IsNullOrEmpty(command.Table) || Regex.IsMatch(m.NameTarget, command.Table, RegexOptions.Compiled)))
                                              .Distinct(namedObjectComparer)
                                              .OfType <ITable>()
                                              .ToList();
                    foreach (var targetTable in targetTables)
                    {
                        while (tableWorkers.Count(m => m.IsBusy) >= (command.TablesHandledSimultaneity <= 0 ? 1 : command.TablesHandledSimultaneity) && _errors.Any() == false)
                        {
                            Thread.Sleep(250);
                        }
                        if (_errors.Any())
                        {
                            throw _errors.ElementAt(0);
                        }
                        var tableWorker = new BackgroundWorker
                        {
                            WorkerReportsProgress      = false,
                            WorkerSupportsCancellation = true
                        };
                        tableWorker.DoWork             += HandleTargetTableDoWork;
                        tableWorker.RunWorkerCompleted += WorkerCompleted;
                        tableWorker.Disposed           += (sender, eventArgs) => tableWorkers.Remove((BackgroundWorker)sender);
                        tableWorkers.Add(tableWorker);
                        tableWorker.RunWorkerAsync(new Tuple <ITable, IDataSource, IDeliveryEngineExecuteCommand>(targetTable, dataSource, command));
                    }
                    while (tableWorkers.Any(m => m.IsBusy))
                    {
                        if (_errors.Any())
                        {
                            throw _errors.ElementAt(0);
                        }
                        Thread.Sleep(250);
                    }
                }
                finally
                {
                    foreach (var tableWorker in tableWorkers.Where(m => m.IsBusy))
                    {
                        tableWorker.CancelAsync();
                    }
                    while (tableWorkers.Any(m => m.IsBusy))
                    {
                        Thread.Sleep(250);
                    }
                    while (tableWorkers.Count > 0)
                    {
                        var tableWorker = tableWorkers.ElementAt(0);
                        tableWorker.Dispose();
                        tableWorkers.Remove(tableWorker);
                    }
                }
            }
            catch (DeliveryEngineAlreadyHandledException)
            {
            }
            catch (Exception ex)
            {
                lock (_syncRoot)
                {
                    ExceptionHandler.HandleException(ex);
                }
            }
            finally
            {
                lock (_syncRoot)
                {
                    while (_tableInformations.Count > 0)
                    {
                        _tableInformations.Clear();
                    }
                }
                while (_errors.Count > 0)
                {
                    _errors.Clear();
                }
            }
        }
        public void TestThatConstructorInitializeComparer()
        {
            var comparer = new NameTargetComparer();

            Assert.That(comparer, Is.Not.Null);
        }