public void GetFetchSqlTest() { var id = HelperObjectFactory.GetRandomInt(0, 100); var value = new IdentifyingInfo { Id = id }; var parameters = new List <SQLiteParameter>(); var table = new GenreTable(); var expected = $"SELECT * FROM {TableFactory<Genre>.GetTable<GenreTable>().TableName} WHERE {GenreTable.IdColumnName} = @{GenreTable.IdColumnName};"; Assert.AreEqual(expected, table.GetFetchSql(value, ref parameters)); Assert.AreEqual(1, parameters.Count); parameters.Clear(); value = new IdentifyingInfo { Name = StringExtensions.GetRandomStringAsync(25).Result }; expected = $"SELECT * FROM {TableFactory<Genre>.GetTable<GenreTable>().TableName} WHERE {GenreTable.NameColumnName} = @{GenreTable.NameColumnName};"; Assert.AreEqual(expected, table.GetFetchSql(value, ref parameters)); Assert.AreEqual(1, parameters.Count); }
public void GetCreateSqlTest() { var table = new AlbumTable(); var expected = $"CREATE TABLE {TableFactory<Album>.GetTable<AlbumTable>().TableName} ({AlbumTable.IdColumnName} INTEGER NOT NULL PRIMARY KEY, {AlbumTable.NameColumnName} TEXT UNIQUE NOT NULL COLLATE NOCASE, {AlbumTable.YearColumnName} INTEGER NOT NULL, {AlbumTable.ArtistIdColumnName} INTEGER NOT NULL, {AlbumTable.GenreIdColumnName} INTEGER NOT NULL, FOREIGN KEY({AlbumTable.ArtistIdColumnName}) REFERENCES {TableFactory<Artist>.GetTable<ArtistTable>().TableName}({ArtistTable.IdColumnName}), FOREIGN KEY({AlbumTable.GenreIdColumnName}) REFERENCES {TableFactory<Genre>.GetTable<GenreTable>().TableName}({GenreTable.IdColumnName})) WITHOUT ROWID;"; Assert.AreEqual(expected, table.GetCreateSql()); }
public void ConstructorTest() { var boolNullable = new ArtistTable(); Assert.AreEqual("artists", TableFactory <Artist> .GetTable <ArtistTable>().TableName); Assert.IsNotNull(boolNullable); }
public void GetCreateSqlTest() { var table = new GenreTable(); var expected = $"CREATE TABLE {TableFactory<Genre>.GetTable<GenreTable>().TableName} ({GenreTable.IdColumnName} INTEGER NOT NULL PRIMARY KEY, {GenreTable.NameColumnName} TEXT UNIQUE NOT NULL COLLATE NOCASE) WITHOUT ROWID;"; Assert.AreEqual(expected, table.GetCreateSql()); }
public void ConstructorTest() { var boolNullable = new GenreTable(); Assert.AreEqual("genres", TableFactory <Genre> .GetTable <GenreTable>().TableName); Assert.IsNotNull(boolNullable); }
public void GetTableTest() { var t1 = TableFactory <Album> .GetTable <AlbumTable>(); Assert.IsInstanceOf(typeof(AlbumTable), t1); var t2 = TableFactory <Artist> .GetTable <ArtistTable>(); Assert.IsInstanceOf(typeof(ArtistTable), t2); var t3 = TableFactory <Genre> .GetTable <GenreTable>(); Assert.IsInstanceOf(typeof(GenreTable), t3); var s1 = TableFactory <Album> .GetTable <AlbumTable>(); Assert.IsTrue(ReferenceEquals(t1, s1)); var s2 = TableFactory <Artist> .GetTable <ArtistTable>(); Assert.IsTrue(ReferenceEquals(t2, s2)); var s3 = TableFactory <Genre> .GetTable <GenreTable>(); Assert.IsTrue(ReferenceEquals(t3, s3)); }
/// <summary> /// Creates the tables in the database. /// </summary> /// <exception cref="ArgumentNullException">The parameter was null.</exception> /// <exception cref="MissingMethodException"> /// In the .NET for Windows Store apps or the Portable Class Library, catch the /// base class exception, <see cref="T:System.MissingMemberException" />, instead. /// The type that is specified does not have a parameterless constructor. /// </exception> private async Task CreateDatabaseTablesAsync() { await DatabaseWrapper.ExecuteSqlWithParametersAsync(TableFactory <Album> .GetTable <AlbumTable>().GetCreateSql(), null); await DatabaseWrapper.ExecuteSqlWithParametersAsync(TableFactory <Artist> .GetTable <ArtistTable>().GetCreateSql(), null); await DatabaseWrapper.ExecuteSqlWithParametersAsync(TableFactory <Genre> .GetTable <GenreTable>().GetCreateSql(), null); }
public void GetUpdateSqlTest() { var id = HelperObjectFactory.GetRandomInt(0, 100); var value = new Genre(id, StringExtensions.GetRandomStringAsync(23).Result); var parameters = new List <SQLiteParameter>(); var table = new GenreTable(); var expected = $"UPDATE {TableFactory<Genre>.GetTable<GenreTable>().TableName} SET {GenreTable.NameColumnName} = @{GenreTable.NameColumnName} WHERE {GenreTable.IdColumnName} = @{GenreTable.IdColumnName};"; Assert.AreEqual(expected, table.GetUpdateSql(value, ref parameters)); Assert.AreEqual(2, parameters.Count); }
public void GetInsertSqlTest() { var id = HelperObjectFactory.GetRandomInt(0, 100); var value = new Genre(id, StringExtensions.GetRandomStringAsync(23).Result); var parameters = new List <SQLiteParameter>(); var table = new GenreTable(); var expected = $"INSERT OR IGNORE INTO {TableFactory<Genre>.GetTable<GenreTable>().TableName} ({GenreTable.IdColumnName}, {AlbumTable.NameColumnName}) VALUES(@{GenreTable.IdColumnName}, @{GenreTable.NameColumnName});"; Assert.AreEqual(expected, table.GetInsertSql(value, ref parameters)); Assert.AreEqual(2, parameters.Count); }
public void GetCountSqlTest() { var id = HelperObjectFactory.GetRandomInt(0, 100); var value = new IdentifyingInfo { Id = id }; var parameters = new List <SQLiteParameter>(); var table = new GenreTable(); var expected = $"SELECT COUNT(*) FROM {TableFactory<Genre>.GetTable<GenreTable>().TableName} WHERE {GenreTable.IdColumnName} = @{GenreTable.IdColumnName};"; Assert.AreEqual(expected, table.GetCountSql(value, ref parameters)); Assert.AreEqual(1, parameters.Count); }
private void ExecuteSqlWithParametersTest_Insert() { var album = HelperObjectFactory.MakeAlbum(AlbumId, ArtistId, GenreId, AlbumName, Year); var artist = HelperObjectFactory.MakeArtist(ArtistId, ArtistName); var genre = HelperObjectFactory.MakeGenre(GenreId, GenreName); var parameters = new List <SQLiteParameter>(); // Assert the tables exist Assert.AreEqual(1, _dataAccess.ExecuteSqlWithParametersAsync(TableFactory <Genre> .GetTable <GenreTable>().GetInsertSql(genre, ref parameters), parameters).Result); parameters.Clear(); Assert.AreEqual(1, _dataAccess.ExecuteSqlWithParametersAsync(TableFactory <Album> .GetTable <AlbumTable>().GetInsertSql(album, ref parameters), parameters).Result); parameters.Clear(); Assert.AreEqual(1, _dataAccess.ExecuteSqlWithParametersAsync(TableFactory <Artist> .GetTable <ArtistTable>().GetInsertSql(artist, ref parameters), parameters).Result); }
public void GetDeleteAlbumsByArtistSqlTest() { var id = HelperObjectFactory.GetRandomInt(0, 100); var value = new IdentifyingInfo { Id = id }; var parameters = new List <SQLiteParameter>(); var table = new ArtistTable(); var expected = $"DELETE FROM {TableFactory<Album>.GetTable<AlbumTable>().TableName} WHERE {AlbumTable.ArtistIdColumnName} = @{AlbumTable.ArtistIdColumnName};"; Assert.AreEqual(expected, table.GetDeleteAlbumsByArtistSql(value, ref parameters)); Assert.AreEqual(1, parameters.Count); }
public ComponentManager(IGame game, IGameMetadata gameMetadata, ExportFactory <IBrain, IBrainMetadata> brainFactory) { m_EvolutionLock = new object(); m_Game = game; m_GameMetadata = gameMetadata; m_Table = TableFactory.GetTable(gameMetadata.Table); m_ValidGames = new List <GameManager>(); //load accessory functions from brain assembly new CompositionContainer(new TypeCatalog(brainFactory.Metadata.BrainType)).ComposeParts(this); m_Population = brainFactory.Metadata.Population; m_MaxShot = 0; m_MaxBalls = 0; m_ShotCount = 1; m_BallCount = null; m_PlayingGamesCount = m_Population; m_BestScore = null; PlayWinner = false; Initialize((pop, play) => brainFactory.CreateExport().Value); }
private void ExecuteSqlWithParametersTest_Delete() { var parameters = new List <SQLiteParameter>(); // Assert the tables exist Assert.AreEqual(1, _dataAccess.ExecuteSqlWithParametersAsync(TableFactory <Album> .GetTable <AlbumTable>() .GetDeleteSql(new IdentifyingInfo { Id = AlbumId, FilterText = FilterText }, ref parameters), parameters) .Result); parameters.Clear(); Assert.AreEqual(1, _dataAccess.ExecuteSqlWithParametersAsync(TableFactory <Artist> .GetTable <ArtistTable>() .GetDeleteSql(new IdentifyingInfo { Id = ArtistId, FilterText = FilterText }, ref parameters), parameters) .Result); parameters.Clear(); Assert.AreEqual(1, _dataAccess.ExecuteSqlWithParametersAsync(TableFactory <Genre> .GetTable <GenreTable>() .GetDeleteSql(new IdentifyingInfo { Id = GenreId, FilterText = FilterText }, ref parameters), parameters) .Result); parameters.Clear(); }
private void frmEntity_Load(object sender, EventArgs e) { //Data.ConnString = WebConfig.GetConn("ConnString"); textBox1.Text = string.IsNullOrEmpty(WebConfig.GetApp("Project")) ? "Test" : WebConfig.GetApp("Project"); xmlFile = "".GetMapPath() + textBox1.Text + ".xml"; bool xmlExist = FileDirectory.FileExists(xmlFile); IList <TableEntity> list = TableFactory.GetTable(); foreach (TableEntity entity in list) { listBox.Items.Add((entity.isView ? "* " : "") + entity.Name, entity.isView ? false : true); if (!xmlExist) { OPList.Add(new TableOperator() { Table = entity.Name }); } else { Xml2 xml = new Xml2(xmlFile); string[] attrs = xml.GetAttr("root//Table[@Name='" + entity.Name + "']", "Name|Insert|Update|Delete|IsExistByID|SelectByID|SelectPageList|SelectListByFK|SelectListByAll|Entity|UpdateAndInsert").Split('|'); if (attrs[0].IsNullEmpty()) { OPList.Add(new TableOperator() { Table = entity.Name }); var info = OPList[OPList.Count - 1]; xml.AddNode("root", "Table", "Name|Entity|Insert|Update|Delete|IsExistByID|SelectByID|SelectPageList|SelectListByFK|SelectListByAll|UpdateAndInsert", "{0}|{9}|{1}|{2}|{3}|{4}|{5}|{6}|{7}|{8}|{10}".FormatWith( info.Table, info.Insert.ToString().ToLower(), info.Update.ToString().ToLower(), info.DeleteByID.ToString().ToLower(), info.IsExistByID.ToString().ToLower(), info.SelectByID.ToString().ToLower(), info.SelectPageList.ToString().ToLower(), info.SelectListByFK.ToString().ToLower(), info.SelectListByAll.ToString().ToLower(), info.Entity.ToString().ToLower(), info.UpdateAndInsert.ToString().ToLower() )); xml.Save(); } else { OPList.Add(new TableOperator() { Table = entity.Name, Insert = attrs[1] == "true" ? true : false, Update = attrs[2] == "true" ? true : false, DeleteByID = attrs[3] == "true" ? true : false, IsExistByID = attrs[4] == "true" ? true : false, SelectByID = attrs[5] == "true" ? true : false, SelectPageList = attrs[6] == "true" ? true : false, SelectListByFK = attrs[7] == "true" ? true : false, SelectListByAll = attrs[8] == "true" ? true : false, Entity = attrs[9] == "true" ? true : false, UpdateAndInsert = attrs[10] == "true" ? true : false, }); } xml.Close(); } } if (!xmlExist) { CreateXML(xmlFile); } if (listBox.Items.Count > 0) { listBox.SelectedIndex = 0; } this.Text = "Entity Tool [{2}] - {1}连接共有{0}个表".FormatWith(listBox.Items.Count, Data.DBType, TemplateName); }
private void ExecuteCountQueryWithParameters() { var parameters = new List <SQLiteParameter>(); // Assert the tables exist Assert.AreEqual(1, _dataAccess.ExecuteCountQueryWithParameters($"SELECT COUNT(*) FROM {TableFactory<Album>.GetTable<AlbumTable>().TableName};", parameters)); Assert.AreEqual(1, _dataAccess.ExecuteCountQueryWithParameters($"SELECT COUNT(*) FROM {TableFactory<Artist>.GetTable<ArtistTable>().TableName};", parameters)); Assert.AreEqual(1, _dataAccess.ExecuteCountQueryWithParameters($"SELECT COUNT(*) FROM {TableFactory<Genre>.GetTable<GenreTable>().TableName};", parameters)); }
public async Task ExecuteQueryWithParametersTests() { var parameters = new List <SQLiteParameter>(); ExecuteSqlWithParametersTest_Insert(); using (var cursor = await _dataAccess.ExecuteQueryWithParametersAsync($"SELECT * FROM {TableFactory<Genre>.GetTable<GenreTable>().TableName};", parameters)) { Assert.IsFalse(Cursor.IsNullOrEmpty(cursor)); Assert.AreEqual(2, cursor.GetRowValues().Count); } ExecuteSqlWithParametersTest_Delete(); }
public void ExecuteCountQueryWithParametersTest() { var parameters = new List <SQLiteParameter>(); // Assert the tables exist Assert.AreEqual(1, _dataAccess.ExecuteCountQueryWithParameters($"SELECT COUNT(name) FROM sqlite_master WHERE type='table' AND name='{TableFactory<Album>.GetTable<AlbumTable>().TableName}';", parameters)); Assert.AreEqual(1, _dataAccess.ExecuteCountQueryWithParameters($"SELECT COUNT(name) FROM sqlite_master WHERE type='table' AND name='{TableFactory<Artist>.GetTable<ArtistTable>().TableName}';", parameters)); Assert.AreEqual(1, _dataAccess.ExecuteCountQueryWithParameters($"SELECT COUNT(name) FROM sqlite_master WHERE type='table' AND name='{TableFactory<Genre>.GetTable<GenreTable>().TableName}';", parameters)); }