public void Should_Add_Migration() { var migration = new Migration(); migration.Version = "0.0"; var migrationsService = new MigrationsService(); migrationsService.Register(migration); migrationsService.Migrations.Contains(migration).Should().BeTrue("because we just added this migration"); }
private static void Main(string[] args) { var gateway = new MigrationsService(); var dispatcher = new CommandDispatcher(gateway); var result = dispatcher.DispatchCommand(args); if (result.Wait) { Console.ReadKey(); } Environment.ExitCode = result.Success ? 0 : 1; }
static async Task Main(string[] args) { // Path to the database file var dbPath = @"..\..\..\..\..\data\test.db"; // Path to the file that contains list of files with migrations var migrationsPath = @"..\..\..\..\..\db\migrations.txt"; var builder = new DbContextOptionsBuilder() { }; builder.UseSqlite($"Data Source={dbPath}"); var migrationService = new MigrationsService(builder.Options); await migrationService.MigrateAsync(migrationsPath); }
public void Should_Skip_Migrations_Prior_To_Detected_Version() { var sourceMigrations = new List<IMigration>() { Mock.Of<IMigration>(m => m.Version == "0.0"), Mock.Of<IMigration>(m => m.Version == "0.0.1"), }; var versionDetector = Mock.Of<IVersionDetector>(v => v.GetVersion() == "0.0"); var migrationsService = new MigrationsService(versionDetector); foreach (var migration in sourceMigrations) migrationsService.Register(migration); migrationsService.Migrate("0.1"); int index = 0; Mock.Get(sourceMigrations.Skip(index++).First()).Verify(mockmigration => mockmigration.Apply(), Times.Never); Mock.Get(sourceMigrations.Skip(index++).First()).Verify(mockmigration => mockmigration.Apply()); }
public void Should_Apply_All_Migrations_Up_To_Given_Version() { var sourceMigrations = new List<IMigration>() { Mock.Of<IMigration>(m => m.Version == "0.0"), Mock.Of<IMigration>(m => m.Version == "0.0.1"), Mock.Of<IMigration>(m => m.Version == "0.1"), }; var migrationsService = new MigrationsService(); foreach (var migration in sourceMigrations) migrationsService.Register(migration); migrationsService.Migrate("", "0.1"); int index = 0; Mock.Get(sourceMigrations.Skip(index++).First()).Verify(mockmigration => mockmigration.Apply()); Mock.Get(sourceMigrations.Skip(index++).First()).Verify(mockmigration => mockmigration.Apply()); Mock.Get(sourceMigrations.Skip(index++).First()).Verify(mockmigration => mockmigration.Apply(), Times.Never); }
public void ShouldDeploySmartIdentityMigrations() { using (var testrpcRunner = new TestRPCEmbeddedRunner()) { try { testrpcRunner.RedirectOuputToDebugWindow = true; testrpcRunner.StartTestRPC(); var web3 = new Web3(); var addressFrom = (web3.Eth.Accounts.SendRequestAsync()).Result[0]; // Deploy the contract and add the multiplier to the constructor var transactionHash = MigrationsService.DeployContractAsync(web3, addressFrom, new HexBigInteger(900000)).Result; Assert.IsNotNull(transactionHash); var receipt = web3.Eth.Transactions.GetTransactionReceipt.SendRequestAsync(transactionHash).Result; Assert.IsNotNull(receipt); } finally { testrpcRunner.StopTestRPC(); } } }
public void Should_List_Migrations_In_Order_By_Version() { var sourceMigrations = new List<Migration>() { new Migration {Version = "0.0"}, new Migration { Version = "0.0.1" }, new Migration { Version = "0.1" }, new Migration { Version = "0.2" }, new Migration { Version = "0.2.1" }, }; var migrationsService = new MigrationsService(); migrationsService.Register(sourceMigrations[3]); migrationsService.Register(sourceMigrations[0]); migrationsService.Register(sourceMigrations[4]); migrationsService.Register(sourceMigrations[1]); migrationsService.Register(sourceMigrations[2]); var migrations = migrationsService.Migrations; for (var i = 0; i < migrations.Count; i++) migrations[i].Should().Be(sourceMigrations[i]); }
static async Task Main(string[] args) { var logPath = @"E:\proj\my\ImageGallery\log\pexel"; var pixel_dbPath = @"E:\proj\my\ImageGallery\pixel.db"; //var im_dbPath = @"E:\proj\my\ImageGallery\im.db"; var im_dbPath = @"E:\proj\my\ImageGallery\test.im.db"; //var jsonDbPath= @"E:\proj\my\ImageGallery\db.json"; var jsonDbPath = @"E:\proj\my\ImageGallery\test.db.json"; var userAgentsPath = @"E:\proj\github\ichensky\ImageGallery\data\useragents.txt"; var pixelMigrationsPath = @"E:\proj\github\ichensky\ImageGallery\src\db\pixel.txt"; var imMigrationsPath = @"E:\proj\github\ichensky\ImageGallery\src\db\im.txt"; var pathToGoogleKeys = @"E:\proj\github\ichensky\ImageGallery\keys\google"; var msVisionKeysPath = @"E:\proj\github\ichensky\ImageGallery\keys\msvisionkeys.txt"; LogManager.Configuration = LoggerService.DefaultConfiguration(logPath); var logger = LogManager.GetLogger(Services.Logger.log.ToString()); var userAgents = await File.ReadAllLinesAsync(userAgentsPath); var userAgentsService = new UserAgentService(logger, userAgents); var stopwatchService = new StopwatchService(logger); var attemptService = new AttemptService(logger); var httpClientSerive = new HttpClientService(logger, stopwatchService, userAgentsService); var usersParser = new UsersParser(logger, httpClientSerive, attemptService); var imagesParser = new ImagesParser(logger, httpClientSerive, attemptService); var imageMetaParser = new ImageMetaParser(logger, httpClientSerive, attemptService); var fileLoader = new FileLoader(logger, httpClientSerive, attemptService); var googleService = new GoogleService(logger, pathToGoogleKeys); var msvisionService = new MSVisionService(logger, msVisionKeysPath); var pixel_builder = new DbContextOptionsBuilder().UseSqlite($"Data Source={pixel_dbPath}"); var imBuilder = new DbContextOptionsBuilder().UseSqlite($"Data Source={im_dbPath}"); //await googleService.Clean(); //var migrationService = new MigrationsService(pixel_builder.Options); //logger.Info("Applying migrations to database."); //await migrationService.MigrateAsync(migrationsPath); var pixelService = new PixelService(logger, pixel_builder.Options, usersParser, imagesParser, imageMetaParser, fileLoader, googleService, msvisionService); //await pixelService.UpdateUsers(5514); //await pixelService.UpdateUsersImages(16124); //await pixelService.UpdateImagesMeta(388970); //await pixelService.PixelImagesToGoogle(); //await pixelService.CleanGoogleImages(); //-- //-- //await pixelService.LoadMSVisionMeta(); //-- //-- //var jsonDb = await pixelService.GenJsonDb(); //File.WriteAllText(jsonDbPath, jsonDb); //-- //-- if (File.Exists(im_dbPath)) { var err = "Deleting database file ..."; logger.Warn(err); File.Delete(im_dbPath); } var migrationService = new MigrationsService(imBuilder.Options); logger.Info("Applying migrations to database."); await migrationService.MigrateAsync(imMigrationsPath); //var im_connection = new Microsoft.Data.Sqlite.SqliteConnection($"DataSource={im_dbPath}"); //im_connection.Open(); //var connectionInMemory = new Microsoft.Data.Sqlite.SqliteConnection("DataSource=:memory:"); //connectionInMemory.Open(); //var builderInMemory = new DbContextOptionsBuilder().UseSqlite(connectionInMemory); //im_connection.BackupDatabase(connectionInMemory); var pixelToImageGalleryService = new PixelToImageGalleryService( logger, pixel_builder.Options, imBuilder.Options); //builderInMemory.Options); //-- //var jsonDb = await pixelToImageGalleryService.GenJsonDb(); //File.WriteAllText(jsonDbPath, jsonDb); //-- var json = File.ReadAllText(jsonDbPath); await pixelToImageGalleryService.GenDb(json); //connectionInMemory.BackupDatabase(im_connection); Console.WriteLine("Hello World!"); }