public void InsertTest()
        {
            int packageSize = 3;
            int totalCount  = 5;

            adapter.Execute(@"
                            DROP TABLE IF EXISTS test.buffer_test;
                            CREATE TABLE test.buffer_test (
                              id int(11) NOT NULL,
                              value varchar(255) DEFAULT NULL,
                              PRIMARY KEY (id)
                            )
                            ENGINE = INNODB;
                            ");

            InsertBuffer buffer = new InsertBuffer(adapter, packageSize, "test.buffer_test", false, "id", "value");

            for (int i = 0; i < totalCount; i++)
            {
                buffer.Add(i, $"value_{i}");
            }

            //автоматическая вставка
            var firstResult = adapter.SelectScalar <int>("SELECT COUNT(bt.id) FROM test.buffer_test bt");

            Assert.AreEqual(firstResult.Value, packageSize);

            //принудитеьная вставка
            buffer.Insert();
            var secondResult = adapter.SelectScalar <int>("SELECT COUNT(bt.id) FROM test.buffer_test bt");

            Assert.AreEqual(secondResult.Value, totalCount);
        }
Beispiel #2
0
        public void CacheTest()
        {
            CacheOptions options = new CacheOptions()
            {
                CacheSize         = 1000,
                SlidingExpiration = new TimeSpan(0, 1, 0)
            };
            var myDictionaryQuery = adapter.GetCacheQuery("my_dictionary", "SELECT id FROM test.my_dictionary WHERE code = '{0}'", options);

            string code  = "code_1";
            var    table = myDictionaryQuery.Get(false, code);

            if (table.Rows.Count == 0)
            {
                adapter.Execute($"INSERT INTO test.my_dictionary SET id = 1, code = '{code}'");
            }

            var value = myDictionaryQuery.GetScalar <int>(false, code);

            Assert.IsNotNull(value);
            Assert.AreEqual(value.Value, 1);
        }