public IEnumerable <SavedSource> GetSources(SourceOrder order = SourceOrder.None) { const string defaultCommand = "SELECT * FROM program"; string commandOrder; var conn = Connect(); using var command = conn.CreateCommand(); if (order == SourceOrder.None) { commandOrder = "ORDER BY priority desc, id"; } else if (order == SourceOrder.Reverse) { commandOrder = "ORDER BY priority desc, id desc"; } else { throw new InvalidEnumArgumentException(nameof(order), (int)order, typeof(SourceOrder)); } command.CommandText = $"{defaultCommand} {commandOrder}"; using var reader = command.ExecuteReader(); while (reader.Read()) { yield return(SavedSource.FromReader(reader)); } }
public void SaveReturnsASavedSource() { LatestServerSource source = new LatestServerSource("whatever", @"X:\path\to", "filename.DayZProfile"); SavedSource savedSource = source.Save(); Assert.AreEqual(@"X:\path\to\filename.DayZProfile", savedSource.Filename); Assert.IsNull(savedSource.Address); Assert.IsNull(savedSource.Name); }
public DataServiceTests() { for (int i = 1; i <= 100; i++) { var ss = new SavedSource(i, $"http://example.com/{i / 2}", "1000", MakeSource(i), i % 5 - 2); saved[i - 1] = ss; service.SaveSource(ss.TaskUrl, ss.LanguageId, i % 5 - 2, Encoding.UTF8.GetBytes(ss.SourceCode)); } }
public void CanBeConstructedFromASavedSource() { SavedSource savedSource = new SavedSource(); savedSource.Filename = @"X:\path\to\some.DayZProfile"; LatestServerSource source = new LatestServerSource(savedSource); Assert.AreEqual(@"X:\path\to", source.ProfileDirectory); Assert.AreEqual("some.DayZProfile", source.ProfileFilename); }
public void SaveReturnsASavedSource() { SavedServerSource serverSource = new SavedServerSource(new Server("1.2.3.4", 5678), "SERVER NAME"); SavedSource savedSource = serverSource.Save(); Assert.AreEqual("1.2.3.4:5678", savedSource.Address); Assert.AreEqual("SERVER NAME", savedSource.Name); Assert.IsNull(savedSource.Filename); }
public void CanBeConstructedFromASavedSource() { SavedSource savedSource = new SavedSource(); savedSource.Address = "1.2.3.4:5678"; savedSource.Name = "SERVER NAME"; SavedServerSource source = new SavedServerSource(savedSource); Assert.AreEqual("1.2.3.4:5678", source.Address); Assert.AreEqual("SERVER NAME", source.ServerName); }
public SavedSource?GetSourceById(int id) { var conn = Connect(); using var command = conn.CreateCommand(); command.CommandText = "SELECT * FROM program WHERE id = @id"; command.Parameters.Add(new SQLiteParameter("@id", id)); using var reader = command.ExecuteReader(); return(reader.Read() ? SavedSource.FromReader(reader) : null); }
public IEnumerable <SavedSource> GetSourcesByUrl(string url) { var conn = Connect(); using var command = conn.CreateCommand(); command.CommandText = "SELECT * FROM program WHERE TaskUrl = @url"; command.Parameters.Add(new SQLiteParameter("@url", url)); using var reader = command.ExecuteReader(); while (reader.Read()) { yield return(SavedSource.FromReader(reader)); } }
public override int GetHashCode() { unchecked { var hashCode = base.GetHashCode(); hashCode = (hashCode * 397) ^ (SavedSource != null ? SavedSource.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (To != null ? To.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (Cc != null ? Cc.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (Bcc != null ? Bcc.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (DisplayName != null ? DisplayName.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (Subject != null ? Subject.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (Attachments != null ? Attachments.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (Body != null ? Body.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (Result != null ? Result.GetHashCode() : 0); return(hashCode); } }