public void VerifyOpenDatabaseReturnsReadWriteConnection() { using (Connection connection = Esent.CreateDatabase(this.database)) { Assert.IsInstanceOfType(connection, typeof(ReadWriteConnection)); } }
public void EsentCreateDatabaseUsesCreationModeNoneAsDefault() { Expect.Call(this.mockConnectionManager.CreateDatabase("mydatabase.edb", DatabaseCreationMode.None)).Return(this.dummyConnection); this.mocks.ReplayAll(); Esent.CreateDatabase("mydatabase.edb"); this.mocks.VerifyAll(); }
public static void CreateDatabase(TestContext ignored) { directory = "column_types_tests"; database = Path.Combine(directory, "columns.edb"); Directory.CreateDirectory(directory); tablename = "table"; using (Connection connection = Esent.CreateDatabase(database)) using (Transaction transaction = connection.BeginTransaction()) using (Table table = connection.CreateTable(tablename)) { table.CreateColumn(new ColumnDefinition("bool", ColumnType.Bool)); table.CreateColumn(new ColumnDefinition("byte", ColumnType.Byte)); table.CreateColumn(new ColumnDefinition("short", ColumnType.Int16)); table.CreateColumn(new ColumnDefinition("ushort", ColumnType.UInt16)); table.CreateColumn(new ColumnDefinition("int", ColumnType.Int32)); table.CreateColumn(new ColumnDefinition("uint", ColumnType.UInt32)); table.CreateColumn(new ColumnDefinition("long", ColumnType.Int64)); table.CreateColumn(new ColumnDefinition("float", ColumnType.Float)); table.CreateColumn(new ColumnDefinition("double", ColumnType.Double)); table.CreateColumn(new ColumnDefinition("datetime", ColumnType.DateTime)); table.CreateColumn(new ColumnDefinition("guid", ColumnType.Guid)); table.CreateColumn(new ColumnDefinition("text", ColumnType.Text)); table.CreateColumn(new ColumnDefinition("asciitext", ColumnType.AsciiText)); table.CreateColumn(new ColumnDefinition("binary", ColumnType.Binary)); transaction.Commit(); } }
public void TestNonFluentUpdateInterface() { using (Connection connection = Esent.CreateDatabase(this.database)) using (Transaction transaction = connection.BeginTransaction()) { Table table = connection.CreateTable("mytable"); table.CreateColumn(new ColumnDefinition("autoinc", ColumnType.Int32) { IsAutoincrement = true }); table.CreateColumn(new ColumnDefinition("myint", ColumnType.Int32)); table.CreateColumn(new ColumnDefinition("mystring", ColumnType.Text) { MaxSize = 200 }); Record record = table.NewRecord(); record["myint"] = 5; record["mystring"] = "hello"; record.Save(); transaction.Commit(); } using (Connection connection = Esent.OpenDatabase(this.database, DatabaseOpenMode.ReadOnly)) { Table table = connection.OpenTable("mytable"); Record record = table.First(); Assert.AreEqual(1, record["autoinc"]); Assert.AreEqual(5, record["myint"]); Assert.AreEqual("hello", record["mystring"]); } }
public void EsentCreateDatabasePassesCreationModeToConnectionFactory() { Expect.Call(this.mockConnectionManager.CreateDatabase("mydatabase.edb", DatabaseCreationMode.OverwriteExisting)).Return(this.dummyConnection); this.mocks.ReplayAll(); Esent.CreateDatabase("mydatabase.edb", DatabaseCreationMode.OverwriteExisting); this.mocks.VerifyAll(); }
public void InTransactionIsFalseWhenNotInTransaction() { using (var connection = Esent.CreateDatabase(this.database) as ConnectionBase) { Assert.IsFalse(connection.InTransaction); } }
public void TestFluentUpdateInterface() { using (Connection connection = Esent.CreateDatabase(this.database)) { connection.UsingTransaction(() => { Table table = connection.CreateTable("mytable") .CreateColumn(DefinedAs.Int32Column("autoinc").AsAutoincrement()) .CreateColumn(DefinedAs.Int32Column("myint")) .CreateColumn(DefinedAs.TextColumn("mystring").WithMaxSize(200)); table.NewRecord() .SetColumn("myint", 5) .SetColumn("mystring", "hello") .Save(); }); } using (Connection connection = Esent.OpenDatabase(this.database, DatabaseOpenMode.ReadOnly)) { Table table = connection.OpenTable("mytable"); Record record = table.First(); Assert.AreEqual(1, record["autoinc"]); Assert.AreEqual(5, record["myint"]); Assert.AreEqual("hello", record["mystring"]); } }
public void VerifyOpenDatabaseReadOnlyReturnsReadOnlyConnection() { using (Connection connection = Esent.CreateDatabase(this.database)) using (Connection readOnlyConnection = Esent.OpenDatabase(this.database, DatabaseOpenMode.ReadOnly)) { Assert.IsInstanceOfType(readOnlyConnection, typeof(ReadOnlyConnection)); } }
public void VerifyReadOnlyConnectionCannotCreateTable() { using (Connection connection = Esent.CreateDatabase(this.database)) using (Connection readOnlyConnection = Esent.OpenDatabase(this.database, DatabaseOpenMode.ReadOnly)) { readOnlyConnection.CreateTable("foo"); } }
public void VerifyTableCreationReturnsReadWriteTable() { using (Connection connection = Esent.CreateDatabase(this.database)) { Table table = connection.CreateTable("foo"); Assert.IsInstanceOfType(table, typeof(ReadWriteTable)); } }
public void InTransactionIsTrueWhenInTransaction() { using (var connection = Esent.CreateDatabase(this.database) as ConnectionBase) using (Transaction transaction = connection.BeginTransaction()) { Assert.IsTrue(connection.InTransaction); } }
public void InTransactionIsFalseWhenTransactionIsRolledBack() { using (var connection = Esent.CreateDatabase(this.database) as ConnectionBase) { Transaction trx = connection.BeginTransaction(); trx.Rollback(); Assert.IsFalse(connection.InTransaction); } }
public void VerifyBeginTransactionTwiceReturnsDifferentTransactions() { using (Connection connection = Esent.CreateDatabase(this.database)) using (Transaction transaction1 = connection.BeginTransaction()) using (Transaction transaction2 = connection.BeginTransaction()) { Assert.AreNotEqual(transaction1, transaction2); } }
public void VerifyReadOnlyConnectionReturnsReadOnlyTable() { using (Connection connection = Esent.CreateDatabase(this.database)) using (Connection readOnlyConnection = Esent.OpenDatabase(this.database, DatabaseOpenMode.ReadOnly)) { connection.CreateTable("foo"); Table table = readOnlyConnection.OpenTable("foo"); Assert.IsInstanceOfType(table, typeof(ReadOnlyTable)); } }
public void OverwriteDatabase() { using (Connection connection = Esent.CreateDatabase(this.database)) { } using (Connection connection = Esent.CreateDatabase(this.database, DatabaseCreationMode.OverwriteExisting)) { } }
public void VerifyReadOnlyTableCannotCreateColumn() { using (Connection connection = Esent.CreateDatabase(this.database)) using (Connection readOnlyConnection = Esent.OpenDatabase(this.database, DatabaseOpenMode.ReadOnly)) { connection.CreateTable("foo"); Table table = readOnlyConnection.OpenTable("foo"); table.CreateColumn(DefinedAs.AsciiTextColumn("col")); } }
public void VerifyReadOnlyTableCannotCreateNewRecord() { using (Connection connection = Esent.CreateDatabase(this.database)) using (Connection readOnlyConnection = Esent.OpenDatabase(this.database, DatabaseOpenMode.ReadOnly)) { connection.CreateTable("foo"); Table table = readOnlyConnection.OpenTable("foo"); readOnlyConnection.UsingTransaction(() => table.NewRecord()); } }
public void VerifyReadWriteTableReturnsReadWriteRecord() { using (Connection connection = Esent.CreateDatabase(this.database)) using (Transaction transaction = connection.BeginTransaction()) { Table table = connection.CreateTable("foo").CreateColumn(DefinedAs.AsciiTextColumn("text")); table.NewRecord().SetColumn("text", Any.String).Save(); Record record = table.First(); Assert.IsInstanceOfType(record, typeof(ReadWriteRecord)); } }
static void CreateDatabase() { using (Connection connection = Esent.CreateDatabase(Database)) using (Table table = connection.CreateTable("mytable")) { connection.UsingLazyTransaction(() => { table.CreateColumn(new ColumnDefinition("myid", ColumnType.Int32)); table.CreateColumn(new ColumnDefinition("mydata", ColumnType.Text)); }); } }
/// <summary> /// Perform the specified action on a read-only record. /// </summary> /// <param name="action">The action to perform</param> private void WithReadOnlyRecord(Action <Record> action) { using (Connection connection = Esent.CreateDatabase(this.database)) using (Connection readOnlyConnection = Esent.OpenDatabase(this.database, DatabaseOpenMode.ReadOnly)) using (Table table = connection.CreateTable("foo").CreateColumn(DefinedAs.AsciiTextColumn("text"))) using (Table readOnlyTable = readOnlyConnection.OpenTable("foo")) { connection.UsingTransaction(() => table.NewRecord().SetColumn("text", Any.String).Save()); Record record = readOnlyTable.First(); action(record); } }
public void InsertRecordWithoutTransaction() { using (Connection connection = Esent.CreateDatabase(this.database)) using (Table table = connection.CreateTable("table")) { try { Record record = table.NewRecord(); Assert.Fail("Expected an EsentException"); } catch (EsentException) { } } }
public void CreateDatabaseThrowsExceptionWhenDatabaseExists() { using (Connection connection = Esent.CreateDatabase(this.database)) { } try { Connection connection = Esent.CreateDatabase(this.database); Assert.Fail("Expected and EsentException"); } catch (EsentException) { } }
public static void CreateDatabase(TestContext ignored) { directory = "simple_table_fixture"; database = Path.Combine(directory, "mydatabase.edb"); Directory.CreateDirectory(directory); tablename = "mytable"; intColumn = "mycolumn"; using (Connection connection = Esent.CreateDatabase(database)) using (Table table = connection.CreateTable(tablename)) { table.CreateColumn(new ColumnDefinition(intColumn, ColumnType.Int32)); } }
public void Setup() { this.random = new Random(); this.data = new byte[DataSize]; this.random.NextBytes(this.data); this.connection = Esent.CreateDatabase("pixie\\esentperftest.db"); // Create the table this.table = connection.CreateTable("table"); using (var trx = connection.BeginTransaction()) { table.CreateColumn(DefinedAs.Int64Column("key")); table.CreateColumn(DefinedAs.BinaryColumn("data")); trx.Commit(); } }
public void TestFluentUpdateInterfaceWithRollback() { using (Connection connection = Esent.CreateDatabase(this.database)) { Table table = null; connection.UsingLazyTransaction(() => { table = connection.CreateTable("mytable") .CreateColumn(DefinedAs.Int32Column("autoinc").AsAutoincrement()) .CreateColumn(DefinedAs.Int32Column("myint")) .CreateColumn(DefinedAs.TextColumn("mystring").WithMaxSize(200)); }); connection.UsingLazyTransaction(() => table.NewRecord() .SetColumn("myint", 5) .SetColumn("mystring", "hello") .Save()); try { connection.UsingLazyTransaction(() => { table.First() .SetColumn("myint", 100) .SetColumn("mystring", "somethingelse") .Save(); throw new OutOfMemoryException("cancel this update"); }); } catch (OutOfMemoryException) { // we expected this } } using (Connection connection = Esent.OpenDatabase(this.database, DatabaseOpenMode.ReadOnly)) { Table table = connection.OpenTable("mytable"); Record record = table.First(); Assert.AreEqual(1, record["autoinc"]); Assert.AreEqual(5, record["myint"]); Assert.AreEqual("hello", record["mystring"]); } }
public void CreateTwoConnections() { using (Connection connection = Esent.CreateDatabase(this.database)) using (Connection anotherconnection = Esent.OpenDatabase(this.database)) using (Table anothertable = anotherconnection.CreateTable("table")) { Transaction transaction = anotherconnection.BeginTransaction(); anothertable.CreateColumn(new ColumnDefinition("column", ColumnType.Bool)); Record anotherrecord = anothertable.NewRecord(); anotherrecord["column"] = 1; anotherrecord.Save(); transaction.Commit(); using (Table table = connection.OpenTable("table")) { Record record = table.First(); Assert.AreEqual(true, record["column"]); } } }
public void ReplaceRecordWithoutTransaction() { using (Connection connection = Esent.CreateDatabase(this.database)) using (Table table = connection.CreateTable("table")) { Transaction trx = connection.BeginTransaction(); table.CreateColumn(new ColumnDefinition("column", ColumnType.Bool)); Record record = table.NewRecord(); record.Save(); trx.Commit(); try { record["column"] = Any.Boolean; Assert.Fail("Expected an EsentException"); } catch (EsentException) { } } }
///// <summary> ///// ///// </summary> ///// <param name="directory"></param> ///// <param name="path"></param> //public void Delete(string directory, string path) //{ // File.Delete(path); // File.Delete(System.IO.Path.Combine(directory, String.Format(CultureInfo.InvariantCulture, "{0}.chk", "edb"))); // foreach (string file in Directory.GetFiles(directory, String.Format(CultureInfo.InvariantCulture, "{0}*.log", "edb"))) // { // File.Delete(file); // } // foreach (string file in Directory.GetFiles(directory, String.Format(CultureInfo.InvariantCulture, "{0}*.jrs", "edb"))) // { // File.Delete(file); // } //} /// <summary> /// /// </summary> public string CreateDatabase() { try { if (File.Exists(OutputPath + @"\data.edb") == false) { _connection = Esent.CreateDatabase(OutputPath + @"\data.edb"); _table = _connection.CreateTable("Data"); _connection.UsingLazyTransaction(() => { _table.CreateColumn(new ColumnDefinition("Id", ColumnType.Int32)); // Filterable _table.CreateColumn(new ColumnDefinition("Type", ColumnType.Text)); // Filterable _table.CreateColumn(new ColumnDefinition("HostName", ColumnType.Text)); // Filterable _table.CreateColumn(new ColumnDefinition("IpAddress", ColumnType.Text)); // Filterable _table.CreateColumn(new ColumnDefinition("MacAddress", ColumnType.Text)); // Filterable _table.CreateColumn(new ColumnDefinition("Service", ColumnType.Text)); // Filterable _table.CreateColumn(new ColumnDefinition("Protocol", ColumnType.Text)); // Filterable _table.CreateColumn(new ColumnDefinition("Port", ColumnType.Text)); // Filterable _table.CreateColumn(new ColumnDefinition("Text", ColumnType.Text)); // Filterable _table.CreateColumn(new ColumnDefinition("PluginId", ColumnType.Text)); _table.CreateColumn(new ColumnDefinition("PluginName", ColumnType.Text)); _table.CreateColumn(new ColumnDefinition("PluginFamily", ColumnType.Text)); _table.CreateColumn(new ColumnDefinition("Severity", ColumnType.Text)); _table.CreateColumn(new ColumnDefinition("Solution", ColumnType.Text)); _table.CreateColumn(new ColumnDefinition("RiskFactor", ColumnType.Text)); _table.CreateColumn(new ColumnDefinition("Description", ColumnType.Text)); _table.CreateColumn(new ColumnDefinition("PluginPublicationDate", ColumnType.Text)); _table.CreateColumn(new ColumnDefinition("VulnPublicationDate", ColumnType.Text)); _table.CreateColumn(new ColumnDefinition("PatchPublicationDate", ColumnType.Text)); _table.CreateColumn(new ColumnDefinition("Synopsis", ColumnType.Text)); _table.CreateColumn(new ColumnDefinition("PluginOutput", ColumnType.Text)); _table.CreateColumn(new ColumnDefinition("PluginVersion", ColumnType.Text)); _table.CreateColumn(new ColumnDefinition("SeeAlso", ColumnType.Text)); _table.CreateColumn(new ColumnDefinition("CvssVector", ColumnType.Text)); _table.CreateColumn(new ColumnDefinition("CvssBaseScore", ColumnType.Text)); _table.CreateColumn(new ColumnDefinition("CvssTemporalScore", ColumnType.Text)); _table.CreateColumn(new ColumnDefinition("Cve", ColumnType.Text)); _table.CreateColumn(new ColumnDefinition("Bid", ColumnType.Text)); _table.CreateColumn(new ColumnDefinition("Xref", ColumnType.Text)); _table.CreateColumn(new ColumnDefinition("State", ColumnType.Text)); // Filterable _table.CreateColumn(new ColumnDefinition("Product", ColumnType.Text)); // Filterable _table.CreateColumn(new ColumnDefinition("Version", ColumnType.Text)); // Filterable _table.CreateColumn(new ColumnDefinition("ExtraInfo", ColumnType.Text)); _table.CreateColumn(new ColumnDefinition("ExploitabilityEase", ColumnType.Text)); _table.CreateColumn(new ColumnDefinition("ExploitAvailable", ColumnType.Text)); // Filterable _table.CreateColumn(new ColumnDefinition("ExploitFrameworkCanvas", ColumnType.Text)); _table.CreateColumn(new ColumnDefinition("ExploitFrameworkMetasploit", ColumnType.Text)); _table.CreateColumn(new ColumnDefinition("ExploitFrameworkCore", ColumnType.Text)); _table.CreateColumn(new ColumnDefinition("MetasploitName", ColumnType.Text)); _table.CreateColumn(new ColumnDefinition("CanvasPackage", ColumnType.Text)); }); _transaction = _connection.BeginTransaction(); } else { _connection = Esent.OpenDatabase(OutputPath + @"\data.edb"); _table = _connection.OpenTable("Data"); _transaction = _connection.BeginTransaction(); } return(string.Empty); } catch (Exception ex) { return(ex.Message); } }
/// <summary> /// Create a new database and return a connection to it. /// </summary> /// <param name="database">The database to create.</param> /// <returns>A connection to the newly created database.</returns> public static Connection CreateDatabase(string database) { return(Esent.CreateDatabase(database, DatabaseCreationMode.None)); }