private IDeliveryEngine CreateSut(bool useDataValidators, IExceptionHandler exceptionHandler)
        {
            if (exceptionHandler == null)
            {
                throw new ArgumentNullException(nameof(exceptionHandler));
            }

            IContainer containerMock = MockRepository.GenerateMock <IContainer>();

            IInformationLogger informationLoggerMock = MockRepository.GenerateMock <IInformationLogger>();

            informationLoggerMock.Expect(m => m.LogInformation(Arg <string> .Is.NotNull))
            .WhenCalled(e => Debug.WriteLine(e.Arguments.ElementAt(0)))
            .Repeat.Any();
            informationLoggerMock.Expect(m => m.LogWarning(Arg <string> .Is.NotNull))
            .WhenCalled(e => Debug.WriteLine(e.Arguments.ElementAt(0)))
            .Repeat.Any();

            IConfigurationRepository configurationRepositoryMock = MockRepository.GenerateMock <IConfigurationRepository>();
            IMetadataRepository      metadataRepository          = new OldToNewMetadataRepository(RepositoryTestHelper.GetSourcePathForOracleTest(), new ConfigurationValues());

            containerMock.Expect(m => m.Resolve <IMetadataRepository>())
            .Return(metadataRepository)
            .Repeat.Any();

            ICollection <IDataManipulator> dataManipulatorCollection;

            using (var windsorContainer = new WindsorContainer())
            {
                windsorContainer.Register(Component.For <IContainer>().Instance(containerMock).LifeStyle.Transient);
                windsorContainer.Register(Component.For <IInformationLogger>().Instance(informationLoggerMock).LifeStyle.Transient);
                windsorContainer.Register(Component.For <IMetadataRepository>().Instance(metadataRepository).LifeStyle.Transient);

                IConfigurationProvider dataManipulatorsConfigurationProvider = new DataManipulatorsConfigurationProvider();
                dataManipulatorsConfigurationProvider.AddConfiguration(windsorContainer);

                dataManipulatorCollection = windsorContainer.ResolveAll <IDataManipulator>();
                windsorContainer.Dispose();
            }
            containerMock.Expect(m => m.ResolveAll <IDataManipulator>())
            .Return(dataManipulatorCollection.ToArray())
            .Repeat.Any();
            IDataRepository dataRepository = new OracleDataRepository(new OracleClientFactory(), new DataManipulators(containerMock));

            containerMock.Expect(m => m.Resolve <IDataRepository>())
            .Return(dataRepository)
            .Repeat.Any();
            IDocumentRepository       documentRepositoryMock = MockRepository.GenerateMock <IDocumentRepository>();
            IArchiveVersionRepository archiveRepository      = new ArchiveVersionRepository(new DirectoryInfo(ConfigurationManager.AppSettings["ArchivePath"]));

            ICollection <IDataValidator> dataValidatorCollection = useDataValidators ? new Collection <IDataValidator> {
                new PrimaryKeyDataValidator(dataRepository), new ForeignKeysDataValidator(dataRepository), new MappingDataValidator()
            } : new Collection <IDataValidator>();

            containerMock.Expect(m => m.ResolveAll <IDataValidator>())
            .Return(dataValidatorCollection.ToArray())
            .Repeat.Any();
            IDataValidators dataValidators = new DataValidators(containerMock);

            return(new DeliveryEngine.BusinessLogic.DeliveryEngine(configurationRepositoryMock, metadataRepository, dataRepository, documentRepositoryMock, dataValidators, archiveRepository, exceptionHandler));
        }
コード例 #2
0
        public void TestThatDataRepositoryGetsDataFromOracle()
        {
            var containerMock = MockRepository.GenerateMock <IContainer>();

            var informationLoggerMock = MockRepository.GenerateMock <IInformationLogger>();

            informationLoggerMock.Expect(m => m.LogInformation(Arg <string> .Is.NotNull))
            .WhenCalled(e => Debug.WriteLine(e.Arguments[0]))
            .Repeat.Any();

            var metadataRepository = new OldToNewMetadataRepository(RepositoryTestHelper.GetSourcePathForOracleTest(), new ConfigurationValues());

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

            ICollection <IDataManipulator> dataMainpulatorCollection;

            using (var windsorContainer = new WindsorContainer())
            {
                windsorContainer.Register(Component.For <IContainer>().Instance(containerMock).LifeStyle.Transient);
                windsorContainer.Register(Component.For <IInformationLogger>().Instance(informationLoggerMock).LifeStyle.Transient);
                windsorContainer.Register(Component.For <IMetadataRepository>().Instance(metadataRepository).LifeStyle.Transient);
                var dataManipulatorsConfigurationProvider = new DataManipulatorsConfigurationProvider();
                dataManipulatorsConfigurationProvider.AddConfiguration(windsorContainer);
                dataMainpulatorCollection = windsorContainer.ResolveAll <IDataManipulator>();
                windsorContainer.Dispose();
            }
            containerMock.Expect(m => m.ResolveAll <IDataManipulator>())
            .Return(dataMainpulatorCollection.ToArray())
            .Repeat.Any();

            var oracleClientFactory = new OracleClientFactory();

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

            var dataManipulators = new DataManipulators(containerMock);

            Assert.That(dataManipulators, Is.Not.Null);
            Assert.That(dataManipulators, Is.Not.Empty);

            var dataRepository = new OracleDataRepository(oracleClientFactory, dataManipulators);

            Assert.That(dataRepository, Is.Not.Null);
            containerMock.Expect(m => m.Resolve <IDataRepository>())
            .Return(dataRepository)
            .Repeat.Any();

            var startTime       = DateTime.MinValue;
            var numberOfRecords = 0;

            dataRepository.OnHandleData += (s, e) =>
            {
                Assert.That(s, Is.Not.Null);
                Assert.That(e, Is.Not.Null);
                Assert.That(e.Table, Is.Not.Null);
                Assert.That(e.Data, Is.Not.Null);

                numberOfRecords += e.Data.Count();
                if (e.EndOfData)
                {
                    // ReSharper disable AccessToModifiedClosure
                    Debug.WriteLine("{0} has been selected for the table named {1} in {2}", numberOfRecords, e.Table.NameTarget, new TimeSpan(DateTime.Now.Ticks - startTime.Ticks));
                    // ReSharper restore AccessToModifiedClosure
                    numberOfRecords = 0;
                }
            };

            var dataSource = metadataRepository.DataSourceGet();

            Assert.That(dataSource, Is.Not.Null);
            Assert.That(dataSource.Tables, Is.Not.Null);
            Assert.That(dataSource.Tables, Is.Not.Empty);
            foreach (var table in dataSource.Tables)
            {
                startTime = DateTime.Now;
                dataRepository.DataGetFromTable(table);
            }
        }