예제 #1
0
        public async Task <IDbConnection> SetUp()
        {
            var connection = new SQLiteConnection(ConnectionString);

            ProductOrderInit.Init(ConnectionString);
            DapperSqlGenerator.Configure(ConnectionString).Entity <TestProduct>(a =>
            {
                // Ignoring non-trivial mapping for testing
                a.Property(x => x.MaybeGuid).Ignore();
                a.Property(x => x.Guid).Ignore();
                a.Property(x => x.Duration).Ignore();
            });
            connection.Open();

            var namespaceName = Assembly.GetExecutingAssembly().GetName().Name + ".TestMigrations";
            var applied       = await connection.InitDatabase(Assembly.GetExecutingAssembly(), namespaceName, new SimpleMigrationOptions { ForceApplyMissing = true });

            Assert.AreEqual(1, applied);

            var p1 = new TestProduct
            {
                Kind    = 5,
                Name    = "Product 1",
                Content = "Empty box",
                Value   = -5,
                Enum    = TestEnum.All,
                Date    = DateTime.UtcNow
            };

            var inserted1 = await connection.InsertReturnAsync(p1);

            Id1 = inserted1.Id;
            Assert.AreNotEqual(0, Id1);

            var p2 = new TestProduct
            {
                Kind    = 7,
                Name    = "Product 2",
                Content = "Full box",
                Value   = 987,
                Enum    = TestEnum.None,
                Date    = DateTime.UtcNow
            };

            var inserted2 = await connection.InsertReturnAsync(p2);

            Id2 = inserted2.Id;
            Assert.AreNotEqual(0, Id2);
            Assert.AreNotEqual(Id1, Id2);

            return(connection);
        }
예제 #2
0
        public async Task TestMigrateSqliteOnce()
        {
            var connectionString = "Data Source=:memory:";

            await using var connection = new SQLiteConnection(connectionString);
            ProductOrderInit.Init(connectionString);
            connection.Open();

            var namespaceName = Assembly.GetExecutingAssembly().GetName().Name + ".TestMigrations";
            var applied       = await connection.InitDatabase(Assembly.GetExecutingAssembly(), namespaceName);

            Assert.AreEqual(1, applied);

            applied = await connection.InitDatabase(Assembly.GetExecutingAssembly(), namespaceName, new SimpleMigrationOptions { ForceApplyMissing = true });

            Assert.AreEqual(0, applied);
        }
예제 #3
0
 public void Init()
 {
     ProductOrderInit.Init("pgNew");
     ProductOrderInit.Init("sqlNew");
     AdapterFactory.AdapterLookup = AdapterLookup;
 }
예제 #4
0
 public void Init()
 {
     ProductOrderInit.Init();
 }