public void ClaimTestAndMarkSuccess() { using (var connProvider = new SqliteConnectionProvider("claimtest")) { var repo = new TestRepository(connProvider); repo.EnsureSchema(); repo.CreateTestRun("prod"); repo.SaveBenchmark("prod", "/this/that", "mytestimage", new byte[] { 1, 2, 3 }); repo.SaveTestImage(1, "/this/that", "mytestimage", new byte[] { 1, 2, 3 }); var claimedImage = repo.ClaimNextTestImage("test"); Assert.Equal(1, claimedImage.TestRunId); Assert.Equal("/this/that", claimedImage.Path); var benchmark = repo.GetBenchmark(claimedImage.Application, claimedImage.Path); var testImage = repo.GetTestImage(claimedImage.TestRunId, claimedImage.Path); Assert.Equal(new byte[] { 1, 2, 3 }, benchmark); Assert.Equal(new byte[] { 1, 2, 3 }, testImage); repo.MarkTestImageSuccess(1, "/this/that"); Assert.Null(repo.ClaimNextTestImage("test")); var testRun = repo.GetTestRun(1); Assert.Equal("Submitted", testRun.TestImages[0].State); } }
public void Setup() { var connectionProvider = new SqliteConnectionProvider(); connectionProvider.SetConnectionString(string.Format("Data Source={0}", DatabasePath)); schemaProvider = new SqliteSchemaProvider(connectionProvider); }
public void ClaimTestAndMarkDifference() { using (var connProvider = new SqliteConnectionProvider("claimtest")) { var repo = new TestRepository(connProvider); repo.EnsureSchema(); repo.CreateTestRun("prod"); repo.SaveBenchmark("prod", "/this/that", "mytestimage", new byte[] { 1, 2, 3 }); repo.SaveTestImage(1, "/this/that", "mytestimage", new byte[] { 1, 2, 3 }); var claimedImage = repo.ClaimNextTestImage("test"); Assert.Equal(1, claimedImage.TestRunId); Assert.Equal("/this/that", claimedImage.Path); repo.MarkTestImageDifferent(1, "/this/that", new byte[] { 2, 3 }); Assert.Null(repo.ClaimNextTestImage("test")); var testRun = repo.GetTestRun(1); Assert.Equal("Different", testRun.TestImages[0].State); var diff = repo.GetDifferenceImage(1, "/this/that"); Assert.Equal(new byte[] { 2, 3 }, diff); } }
public void BasicRepoTests() { using (var connProvider = new SqliteConnectionProvider("basicRepoTests")) { var repo = new TestRepository(connProvider); repo.EnsureSchema(); repo.CreateTestRun("prod"); repo.SaveBenchmark("prod", "/this/that", "mybenchmark", new byte[] { 1, 2, 3, 4 }); repo.SaveReferenceImage(1, "/this/that", "myreferenceimage", new byte[] { 1, 2, 3, 4 }); repo.SaveTestImage(1, "/this/that", "mytestimage", new byte[] { 1, 2, 3, 4 }); repo.SaveTestImage(1, "/this/that2", "mytestimage", new byte[] { 1, 2, 3, 4 }); repo.SetTestRunEnd(1, new DateTime(2001, 2, 4)); var testRun = repo.GetTestRun(1); Assert.Equal("prod", testRun.Application); Assert.NotNull(testRun.End); Assert.Equal("myreferenceimage", testRun.ReferenceImages[0].Name); Assert.Equal("/this/that", testRun.ReferenceImages[0].Path); Assert.Equal("mytestimage", testRun.TestImages[0].Name); Assert.Equal("/this/that", testRun.TestImages[0].Path); Assert.Equal("Submitted", testRun.TestImages[0].State); var benchmark = repo.GetBenchmark("prod", "/this/that"); Assert.Equal(new byte[] { 1, 2, 3, 4 }, benchmark); var testImage = repo.GetTestImage(1, "/this/that"); Assert.Equal(new byte[] { 1, 2, 3, 4 }, testImage); } }
public SqliteContext(string databaseFile) : base(null) { var provider = new SqliteConnectionProvider(databaseFile); _pool = new SqliteConnectionPool(1, 10, provider); }
public void TestImageWithoutBenchmarkCantBeClaimed() { using (var connProvider = new SqliteConnectionProvider("claimtest")) { var repo = new TestRepository(connProvider); repo.EnsureSchema(); repo.CreateTestRun("prod"); repo.SaveTestImage(1, "/this/that", "mytestimage", new byte[] { 1, 2, 3 }); Assert.Null(repo.ClaimNextTestImage("test")); var testRun = repo.GetTestRun(1); Assert.Equal(ImageState.NoBenchmark, testRun.TestImages[0].State); } }
public void DeleteTestRun() { using (var connProvider = new SqliteConnectionProvider("claimtest")) { var repo = new TestRepository(connProvider); repo.EnsureSchema(); repo.CreateTestRun("prod"); repo.SaveReferenceImage(1, "/this/that", "refImage", new byte[] { 1, 2, 3 }); repo.SaveTestImage(1, "/this/that", "mytestimage", new byte[] { 1, 2, 3 }); repo.DeleteTestRun(1); Assert.Null(repo.GetTestRun(1)); Assert.Null(repo.GetTestImage(1, "/this/that")); Assert.Null(repo.GetReferenceImage(1, "/this/that")); } }
private void SetupServiceLocator() { var generatorItemFactory = new GeneratorItemFactory(_serviceLocatorMock.Object); var generatorItemList = new GeneratorTemplate(generatorItemFactory, _defaultSourceProvider, new Mock <ILogger>().Object); var connectionProviderFactory = new ConnectionProviderFactory(_serviceLocatorMock.Object); var generatorItemQuery = new GeneratorItemQuery(connectionProviderFactory); var configMock = new Mock <IConfiguration>(); var sqliteConnectionPRovider = new SqliteConnectionProvider(configMock.Object); _serviceLocatorMock.Setup(sl => sl.GetService(It.Is <Type>(t => t == typeof(GeneratorTemplate)))) .Returns(generatorItemList); _serviceLocatorMock.Setup(sl => sl.GetService(It.Is <Type>(t => t == typeof(GeneratorItemQuery)))) .Returns(generatorItemQuery); _serviceLocatorMock.Setup(sl => sl.GetService(It.Is <Type>(t => t == typeof(SqliteConnectionProvider)))) .Returns(sqliteConnectionPRovider); }
// Create an extension method for the IServiceCollection public static void AddDatabase(this IServiceCollection services, string connectionString) { var currentAssembly = typeof(Startup).GetTypeInfo().Assembly; var provider = new SqliteConnectionProvider(connectionString); // Dapper config DefaultTypeMap.MatchNamesWithUnderscores = true; // Run the migrations using (var connection = provider.GetConnectionAsync().Result) { var migrator = new SqliteDatabaseMigrator(connection, currentAssembly); migrator.MigrateToLatest(); } // Add the service services.AddSingleton <IDbConnectionProvider>(provider); // Add repos services.AddSingleton <IPackageRepository, Database.Repositories.PackageRepository>(); //services.AddSingleton<ITarballRepository, TarballRepository>(); }