private static bool CanSafelyPruneMerge(IdentifyingInfo idInfo, ILexEntry entry) { return(entry != null && entry.DateModified == idInfo.modificationTime && entry.DateModified.Kind != DateTimeKind.Unspecified && idInfo.modificationTime.Kind != DateTimeKind.Unspecified); }
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 ILexExampleSentence GetOrMakeExample(ILexSense sense, IdentifyingInfo idInfo) { //nb, has no guid or dates ILexExampleSentence x = new LexExampleSentence(); sense.ExamplesOS.Append(x); return(x); }
private static IdentifyingInfo CreateFullIdInfo(Guid g) { IdentifyingInfo idInfo = new IdentifyingInfo(); idInfo.id = g.ToString(); idInfo = AddDates(idInfo); return(idInfo); }
public void NewEntryWithGuid() { IdentifyingInfo idInfo = new IdentifyingInfo(); idInfo.id = Guid.NewGuid().ToString(); ILexEntry e = _merger.GetOrMakeEntry(idInfo); Assert.AreEqual(idInfo.id, e.Guid.ToString()); }
public void GetHashCodeTest() { var swc1 = HelperObjectFactory.MakeIdentifyingInfo(); var swc2 = HelperObjectFactory.MakeIdentifyingInfo(); var swc3 = new IdentifyingInfo(swc1); Assert.AreEqual(swc1.GetHashCode(), swc1.GetHashCode()); Assert.AreEqual(swc1.GetHashCode(), swc3.GetHashCode()); Assert.AreNotEqual(swc1.GetHashCode(), swc2.GetHashCode()); }
public void NewEntryTakesGivenDates() { IdentifyingInfo idInfo = new IdentifyingInfo(); idInfo = AddDates(idInfo); ILexEntry e = _merger.GetOrMakeEntry(idInfo); Assert.AreEqual(idInfo.creationTime, e.DateCreated); Assert.AreEqual(idInfo.modificationTime, e.DateModified);; }
private ILexSense CreateSense(ILexEntry entry, ref IdentifyingInfo idInfo, ref Guid guid) { ILexSense s = new LexSense(); entry.SensesOS.Append(s); if (guid != Guid.Empty) { SetGuid(s, guid); } return(s); }
[Test] public void NewEntryWithTextIdIgnoresIt() { IdentifyingInfo idInfo = new IdentifyingInfo(); idInfo.id = "hello"; ILexEntry e = _merger.GetOrMakeEntry(idInfo); //no attempt is made to use that id Assert.IsNotNull(e.Guid); Assert.AreNotSame(Guid.Empty, e.Guid); }
public void GetDeleteAlbumsByArtistSqlExceptionTest() { var value = new IdentifyingInfo { Id = null }; var parameters = new List <SQLiteParameter>(); var table = new ArtistTable(); Assert.That(() => table.GetDeleteAlbumsByArtistSql(value, ref parameters), Throws.ArgumentException); }
public void GetIdFromNameExceptionTest() { var id = HelperObjectFactory.GetRandomInt(0, 100); var value = new IdentifyingInfo { Id = id }; var parameters = new List <SQLiteParameter>(); var table = new ArtistTable(); Assert.That(() => table.GetIdFromNameSql(value, ref parameters), Throws.ArgumentException); }
public void GetIdFromNameTest() { var value = new IdentifyingInfo { Name = StringExtensions.GetRandomStringAsync(25).Result }; var parameters = new List <SQLiteParameter>(); var table = new ArtistTable(); var expected = $"SELECT {ArtistTable.IdColumnName} FROM {table.TableName} WHERE {ArtistTable.NameColumnName} = @{ArtistTable.NameColumnName};"; Assert.AreEqual(expected, table.GetIdFromNameSql(value, ref parameters)); Assert.AreEqual(1, parameters.Count); }
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); }
/// <summary> /// Creates a SQL query string to fetch a value from the database table based on criteria relevant to the type of /// value. /// </summary> /// <param name="value">The value to use for data or criteria.</param> /// <param name="parameters"> /// A <see cref="List{T}" /> of <see cref="SQLiteParameter" /> populated with the values need to /// complete the query. /// </param> public virtual string GetFetchSql(IdentifyingInfo value, ref List <SQLiteParameter> parameters) { if (value.Id.HasValue) { var idParameter = SqliteExtensions.Create(IdColumnName, DbType.Int32, value.Id.Value); parameters.Add(idParameter); } else if (!value.Name.IsNullOrEmpty()) { var nameParameter = SqliteExtensions.Create(NameColumnName, DbType.String, value.Name); parameters.Add(nameParameter); } return($"SELECT * FROM {TableName} {GenerateWhereString(GenerateWhereClauses(parameters))};"); }
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); }
public void EqualsTest() { var swc1 = HelperObjectFactory.MakeIdentifyingInfo(); var swc2 = HelperObjectFactory.MakeIdentifyingInfo(); var swc3 = new IdentifyingInfo(swc1); Assert.IsFalse(swc1.Equals((object)null)); Assert.IsFalse(swc1.Equals(null)); Assert.IsTrue(swc1.Equals((object)swc1)); Assert.IsTrue(swc1.Equals(swc1)); Assert.IsFalse(swc1.Equals(swc2)); Assert.IsTrue(swc1.Equals(swc3)); }
public ILexSense GetOrMakeSense(ILexEntry entry, IdentifyingInfo idInfo) { Guid guid = GetGuidOrEmptyFromIdString(idInfo.id); bool canPrune; ILexSense sense = TryToFindMatchingSense(guid, idInfo, out canPrune); if (canPrune) { return(null); } if (sense != null) { return(sense); } return(CreateSense(entry, ref idInfo, ref guid)); }
[Test] public void ChangedEntryFound() { Guid g = Guid.NewGuid(); IdentifyingInfo idInfo = CreateFullIdInfo(g); LexEntry e = new LexEntry(); this.Cache.LangProject.LexDbOA.EntriesOC.Add(e); e.Guid = g; e.DateCreated = idInfo.creationTime; e.DateModified = new DateTime(e.DateCreated.Ticks + 100); ILexEntry found = _merger.GetOrMakeEntry(idInfo); Assert.AreEqual(idInfo.creationTime, found.DateCreated); }
public ILexEntry GetOrMakeEntry(IdentifyingInfo idInfo) { Guid guid = GetGuidOrEmptyFromIdString(idInfo.id); bool canPrune; ILexEntry entry = TryToFindMatchingEntry(guid, idInfo, out canPrune); if (canPrune) { return(null); } if (entry != null) { return(entry); } return(CreateEntry(ref idInfo, ref guid)); }
public string GetDeleteAlbumsByArtistSql(IdentifyingInfo value, ref List <SQLiteParameter> parameters) { SQLiteParameter idParameter; if (value.Id.HasValue) { idParameter = SqliteExtensions.Create(AlbumTable.ArtistIdColumnName, DbType.Int32, value.Id.Value); parameters.Add(idParameter); } else { throw new ArgumentException(Resources.IdOrNameNotProvided, nameof(value)); } return($"DELETE FROM {_albumTable.TableName} WHERE {AlbumTable.ArtistIdColumnName} = {idParameter.ParameterName};"); }
/// <summary> /// Creates a SQL query string to fetch the id of an item from its name /// </summary> /// <param name="value">The value to use for data or criteria.</param> /// <param name="parameters"> /// A <see cref="List{T}" /> of <see cref="SQLiteParameter" /> populated with the values need to /// complete the query. /// </param> public virtual string GetIdFromNameSql(IdentifyingInfo value, ref List <SQLiteParameter> parameters) { SQLiteParameter nameParameter; if (!value.Name.IsNullOrEmpty()) { nameParameter = SqliteExtensions.Create(NameColumnName, DbType.String, value.Name); parameters.Add(nameParameter); } else { throw new ArgumentException(Resources.IdOrNameNotProvided, nameof(value)); } return($"SELECT {IdColumnName} FROM {TableName} WHERE {NameColumnName} = {nameParameter.ParameterName};"); }
private ILexSense TryToFindMatchingSense(Guid guid, IdentifyingInfo idInfo, out bool canPrune) { canPrune = false; //no date info avail on senses ILexSense sense = null; if (guid != Guid.Empty) { int hvo = _cache.GetIdFromGuid(guid); if (hvo > 0) { sense = LexSense.CreateFromDBObject(_cache, hvo); } return(sense); } return(null); }
public void ConstructorAndPropertiesTests() { int? id = HelperObjectFactory.GetRandomInt(); const string filterText = "filter text"; var name = StringExtensions.GetRandomStringAsync(25).Result; var ii = HelperObjectFactory.MakeIdentifyingInfo(id, filterText, name); Assert.AreEqual(id, ii.Id); Assert.AreEqual(filterText, ii.FilterText); Assert.AreEqual(name, ii.Name); var ii2 = new IdentifyingInfo(ii); Assert.AreEqual(id, ii2.Id); Assert.AreEqual(filterText, ii2.FilterText); Assert.AreEqual(name, ii2.Name); }
private ILexEntry TryToFindMatchingEntry(Guid guid, IdentifyingInfo idInfo, out bool canPrune) { ILexEntry entry = null; if (guid != Guid.Empty) { int hvo = _cache.GetIdFromGuid(guid); if (hvo > 0) { entry = LexEntry.CreateFromDBObject(_cache, hvo); } canPrune = CanSafelyPruneMerge(idInfo, entry); return(entry); } canPrune = false; return(null); }
/// <summary> /// Creates a SQL query string to delete the rows meeting the criteria relevant to the type of value. /// </summary> /// <param name="value">The value to use for data or criteria.</param> /// <param name="parameters"> /// A <see cref="List{T}" /> of <see cref="SQLiteParameter" /> populated with the values need to /// complete the query. /// </param> /// <exception cref="ArgumentException">Thrown if the id and name are both null.</exception> public virtual string GetDeleteSql(IdentifyingInfo value, ref List <SQLiteParameter> parameters) { if (value.Id.HasValue) { var idParameter = SqliteExtensions.Create(IdColumnName, DbType.Int32, value.Id.Value); parameters.Add(idParameter); } else if (!value.Name.IsNullOrEmpty()) { var idParameter = SqliteExtensions.Create(NameColumnName, DbType.String, value.Name); parameters.Add(idParameter); } else { throw new ArgumentException(Resources.IdOrNameNotProvided, nameof(value)); } return($"DELETE FROM {TableName} {GenerateWhereString(GenerateWhereClauses(parameters))};"); }
private ILexEntry CreateEntry(ref IdentifyingInfo idInfo, ref Guid guid) { ILexEntry entry = new LexEntry(); //entry.Guid = guid; not avail yet _cache.LangProject.LexDbOA.EntriesOC.Add(entry); SetGuid(entry, guid); if (idInfo.creationTime > DateTime.MinValue) { entry.DateCreated = idInfo.creationTime; } if (idInfo.modificationTime > DateTime.MinValue) { entry.DateModified = idInfo.modificationTime; } return(entry); }
private ILexEntry MakeSimpleEntry() { IdentifyingInfo idInfo = new IdentifyingInfo(); return(_merger.GetOrMakeEntry(idInfo)); }
public void NewEntryTakesGivenDates() { IdentifyingInfo idInfo = new IdentifyingInfo(); idInfo = AddDates(idInfo); ILexEntry e = _merger.GetOrMakeEntry(idInfo); Assert.AreEqual(idInfo.creationTime, e.DateCreated ); Assert.AreEqual(idInfo.modificationTime, e.DateModified);; }
private static IdentifyingInfo AddDates(IdentifyingInfo idInfo) { idInfo.creationTime = DateTime.Parse("2003-08-07T08:42:42+07:00"); idInfo.modificationTime = DateTime.Parse("2005-01-01T01:11:11+01:00"); return idInfo; }
private ILexEntry MakeSimpleEntry() { IdentifyingInfo idInfo = new IdentifyingInfo(); return _merger.GetOrMakeEntry(idInfo); }
private static IdentifyingInfo AddDates(IdentifyingInfo idInfo) { idInfo.creationTime = DateTime.Parse("2003-08-07T08:42:42+07:00"); idInfo.modificationTime = DateTime.Parse("2005-01-01T01:11:11+01:00"); return(idInfo); }
private static IdentifyingInfo CreateFullIdInfo(Guid g) { IdentifyingInfo idInfo = new IdentifyingInfo(); idInfo.id = g.ToString(); idInfo = AddDates(idInfo); return idInfo; }