private MigrationRunner CreateRunner(Action <IServiceCollection> initAction = null)
        {
            initAction?.Invoke(_serviceCollection);
            var serviceProvider = _serviceCollection
                                  .BuildServiceProvider();

            var runner = (MigrationRunner)serviceProvider.GetRequiredService <IMigrationRunner>();

            _fakeVersionLoader   = new TestVersionLoader(runner, runner.VersionLoader.VersionTableMetaData);
            runner.VersionLoader = _fakeVersionLoader;

            var readTableDataResult = new DataSet();

            readTableDataResult.Tables.Add(new DataTable());

            _processorMock.Setup(x => x.ReadTableData(It.IsAny <string>(), It.IsAny <string>()))
            .Returns(readTableDataResult);
            _processorMock.Setup(x => x.SchemaExists(It.Is <string>(s => s == runner.VersionLoader.VersionTableMetaData.SchemaName)))
            .Returns(true);

            _processorMock.Setup(x => x.TableExists(It.Is <string>(s => s == runner.VersionLoader.VersionTableMetaData.SchemaName),
                                                    It.Is <string>(t => t == runner.VersionLoader.VersionTableMetaData.TableName)))
            .Returns(true);

            return(runner);
        }
Example #2
0
        public void SetUp()
        {
            _applicationContext  = new Random().Next();
            _migrationList       = new SortedList <long, IMigrationInfo>();
            _runnerContextMock   = new Mock <IRunnerContext>(MockBehavior.Loose);
            _processorMock       = new Mock <IMigrationProcessor>(MockBehavior.Loose);
            _migrationLoaderMock = new Mock <IMigrationInformationLoader>(MockBehavior.Loose);
            _profileLoaderMock   = new Mock <IProfileLoader>(MockBehavior.Loose);
            _profileLoaderMock.SetupGet(l => l.SupportsParameterlessApplyProfile).Returns(true);

            _announcer = new Mock <IAnnouncer>();
            _stopWatch = new Mock <IStopWatch>();
            _stopWatch.Setup(x => x.Time(It.IsAny <Action>())).Returns(new TimeSpan(1)).Callback((Action a) => a.Invoke());

            var options = new ProcessorOptions
            {
                PreviewOnly = false
            };

            _processorMock.SetupGet(x => x.Options).Returns(options);
            _processorMock.SetupGet(x => x.ConnectionString).Returns(IntegrationTestOptions.SqlServer2008.ConnectionString);

            _runnerContextMock.SetupGet(x => x.Namespace).Returns("FluentMigrator.Tests.Integration.Migrations");
            _runnerContextMock.SetupGet(x => x.Announcer).Returns(_announcer.Object);
            _runnerContextMock.SetupGet(x => x.StopWatch).Returns(_stopWatch.Object);
            _runnerContextMock.SetupGet(x => x.Targets).Returns(new[] { Assembly.GetExecutingAssembly().ToString() });
            _runnerContextMock.SetupGet(x => x.Connection).Returns(IntegrationTestOptions.SqlServer2008.ConnectionString);
            _runnerContextMock.SetupGet(x => x.Database).Returns("sqlserver");
            _runnerContextMock.SetupGet(x => x.ApplicationContext).Returns(_applicationContext);

            _migrationLoaderMock.Setup(x => x.LoadMigrations()).Returns(() => _migrationList);

            _runner = new MigrationRunner(Assembly.GetAssembly(typeof(MigrationRunnerTests)), _runnerContextMock.Object, _processorMock.Object)
            {
                MigrationLoader = _migrationLoaderMock.Object,
                ProfileLoader   = _profileLoaderMock.Object,
            };

            _fakeVersionLoader = new TestVersionLoader(_runner, _runner.VersionLoader.VersionTableMetaData);

            _runner.VersionLoader = _fakeVersionLoader;

            _processorMock.Setup(x => x.SchemaExists(It.Is <string>(s => s == _runner.VersionLoader.VersionTableMetaData.SchemaName)))
            .Returns(true);

            _processorMock.Setup(x => x.TableExists(It.Is <string>(s => s == _runner.VersionLoader.VersionTableMetaData.SchemaName),
                                                    It.Is <string>(t => t == _runner.VersionLoader.VersionTableMetaData.TableName)))
            .Returns(true);
        }
        public void SetUp()
        {
            _migrationList       = new SortedList <long, IMigration>();
            _runnerContextMock   = new Mock <IRunnerContext>(MockBehavior.Loose);
            _processorMock       = new Mock <IMigrationProcessor>(MockBehavior.Loose);
            _migrationLoaderMock = new Mock <IMigrationLoader>(MockBehavior.Loose);
            _profileLoaderMock   = new Mock <IProfileLoader>(MockBehavior.Loose);

            _announcer = new Mock <IAnnouncer>();
            _stopWatch = new Mock <IStopWatch>();

            var options = new ProcessorOptions
            {
                PreviewOnly = false
            };

            _processorMock.SetupGet(x => x.Options).Returns(options);

            _runnerContextMock.SetupGet(x => x.Namespace).Returns("FluentMigrator.Tests.Integration.Migrations");
            _runnerContextMock.SetupGet(x => x.Announcer).Returns(_announcer.Object);
            _runnerContextMock.SetupGet(x => x.StopWatch).Returns(_stopWatch.Object);
            _runnerContextMock.SetupGet(x => x.Target).Returns(Assembly.GetExecutingAssembly().ToString());
            _runnerContextMock.SetupGet(x => x.Connection).Returns(IntegrationTestOptions.SqlServer2008.ConnectionString);
            _runnerContextMock.SetupGet(x => x.Database).Returns("sqlserver");

            _migrationLoaderMock.SetupGet(x => x.Migrations).Returns(_migrationList);

            _runner = new MigrationRunner(Assembly.GetAssembly(typeof(MigrationRunnerTests)), _runnerContextMock.Object, _processorMock.Object)
            {
                MigrationLoader = _migrationLoaderMock.Object,
                ProfileLoader   = _profileLoaderMock.Object,
            };

            _fakeVersionLoader = new TestVersionLoader(_runner, _runner.VersionLoader.VersionTableMetaData);

            _runner.VersionLoader = _fakeVersionLoader;

            _processorMock.Setup(x => x.SchemaExists(It.Is <string>(s => s == _runner.VersionLoader.VersionTableMetaData.SchemaName)))
            .Returns(true);

            _processorMock.Setup(x => x.TableExists(It.Is <string>(s => s == _runner.VersionLoader.VersionTableMetaData.SchemaName),
                                                    It.Is <string>(t => t == _runner.VersionLoader.VersionTableMetaData.TableName)))
            .Returns(true);
        }
        public void SetUp()
        {
            _migrationList = new SortedList<long, IMigration>();
            _runnerContextMock = new Mock<IRunnerContext>(MockBehavior.Loose);
            _processorMock = new Mock<IMigrationProcessor>(MockBehavior.Loose);
            _migrationLoaderMock = new Mock<IMigrationLoader>(MockBehavior.Loose);
            _profileLoaderMock = new Mock<IProfileLoader>(MockBehavior.Loose);

            _announcer = new Mock<IAnnouncer>();
            _stopWatch = new Mock<IStopWatch>();

            var options = new ProcessorOptions
                            {
                                PreviewOnly = false
                            };

            _processorMock.SetupGet(x => x.Options).Returns(options);

            _runnerContextMock.SetupGet(x => x.Namespace).Returns("FluentMigrator.Tests.Integration.Migrations");
            _runnerContextMock.SetupGet(x => x.Announcer).Returns(_announcer.Object);
            _runnerContextMock.SetupGet(x => x.StopWatch).Returns(_stopWatch.Object);
            _runnerContextMock.SetupGet(x => x.Target).Returns(Assembly.GetExecutingAssembly().ToString());
            _runnerContextMock.SetupGet(x => x.Connection).Returns(IntegrationTestOptions.SqlServer2008.ConnectionString);
            _runnerContextMock.SetupGet(x => x.Database).Returns("sqlserver");

            _migrationLoaderMock.SetupGet(x => x.Migrations).Returns(_migrationList);

            _runner = new MigrationRunner(Assembly.GetAssembly(typeof(MigrationRunnerTests)), _runnerContextMock.Object, _processorMock.Object)
                        {
                            MigrationLoader = _migrationLoaderMock.Object,
                            ProfileLoader = _profileLoaderMock.Object,
                        };

            _fakeVersionLoader = new TestVersionLoader(_runner, _runner.VersionLoader.VersionTableMetaData);

            _runner.VersionLoader = _fakeVersionLoader;

            _processorMock.Setup(x => x.SchemaExists(It.Is<string>(s => s == _runner.VersionLoader.VersionTableMetaData.SchemaName)))
                          .Returns(true);

            _processorMock.Setup(x => x.TableExists(It.Is<string>(s => s == _runner.VersionLoader.VersionTableMetaData.SchemaName),
                                                    It.Is<string>(t => t == _runner.VersionLoader.VersionTableMetaData.TableName)))
                          .Returns(true);
        }