public void AddEntryTest() { var logEntry1 = new Mock <ILogEntry>().SetupAllProperties(); var logEntry2 = new Mock <ILogEntry>().SetupAllProperties(); var logEntry3 = new Mock <ILogEntry>().SetupAllProperties(); GameLogImpl log = new(); InfoLevels level = InfoLevels.Error | InfoLevels.Warning; log.SetInfoLevel(level); bool isEntryCreated; Assert.Empty(log.Entries); isEntryCreated = false; log.AddEntry(InfoLevels.Error, () => { isEntryCreated = true; return(logEntry1.Object); }); Assert.Single(log.Entries); Assert.True(isEntryCreated); Assert.Equal(InfoLevels.Error, logEntry1.Object.InfoLevel); isEntryCreated = false; log.AddEntry(InfoLevels.Warning, () => { isEntryCreated = true; return(logEntry2.Object); }); Assert.Equal(2, log.Entries.Count()); Assert.True(isEntryCreated); Assert.Equal(InfoLevels.Warning, logEntry2.Object.InfoLevel); isEntryCreated = false; log.AddEntry(InfoLevels.Info, () => { isEntryCreated = true; return(logEntry3.Object); }); Assert.Equal(2, log.Entries.Count()); Assert.False(isEntryCreated); }
public void AddEntry(InfoLevels entryLevel, Func <ILogEntry> entry) { if ((entryLevel & _includedLevels) != InfoLevels.None) { var newEntry = entry(); newEntry.InfoLevel = entryLevel; _entries.Add(newEntry); } }
private static List <string> BuildUrls(LookupMethods method, InfoLevels infolevel = InfoLevels.Basic, int maxResults = 30, int width = 0, int height = 0, SizeOperators op = SizeOperators.Equal, int id = 0, string query = null, SortMethods sortby = SortMethods.Newest) { int maxPages = MaxResultsToPages(maxResults); List <string> toReturn = new List <string>(); for (int i = 0; i < maxPages; i++) { toReturn.Add(buildUrl(method, infolevel, i, width, height, op, id, query, sortby)); } return(toReturn); }
public void FlushTest() { var logEntry1 = new Mock <ILogEntry>().SetupAllProperties(); var logEntry2 = new Mock <ILogEntry>().SetupAllProperties(); var logEntry3 = new Mock <ILogEntry>().SetupAllProperties(); GameLogImpl log = new(); InfoLevels level = InfoLevels.Error; log.SetInfoLevel(level); log.AddEntry(InfoLevels.Error, () => logEntry1.Object); log.AddEntry(InfoLevels.Error, () => logEntry2.Object); Assert.Equal(2, log.Entries.Count()); log.Flush(); Assert.Empty(log.Entries); log.AddEntry(InfoLevels.Error, () => logEntry3.Object); Assert.Single(log.Entries); }
private static string buildUrl(LookupMethods method, InfoLevels infolevel = InfoLevels.Basic, int page = 1, int width = 0, int height = 0, SizeOperators op = SizeOperators.Equal, int id = 0, string query = null, SortMethods sortby = SortMethods.Newest) { if (AuthenticationKey == null || AuthenticationKey.Trim().Length == 0) { throw new NullReferenceException("API Key cannot be null!"); } if (page < 1) { page = 1; } if ((width <= 0 && height > 0) || (width > 0 && height <= 0)) { throw new ArgumentException("Both Width and height must be specified!"); } string toReturn = baseUrl + AuthenticationKey + "&method=" + method; switch (infolevel) { //case InfoLevels.Basic: case InfoLevels.IncludeCategory: toReturn += "&info_level=2"; break; case InfoLevels.IncludeCategoryCollectionAndGroup: toReturn += "&info_level=3"; break; } if (page > 1) { toReturn += "&page=" + page; } if (width > 0) { toReturn += "&width=" + width + "&height=" + height; } switch (op) { //case SizeOperators.Equal: case SizeOperators.Max: toReturn += "&operator=max"; break; case SizeOperators.Min: toReturn += "&operator=min"; break; } if (id > 0) { toReturn += "&id=" + id; } if (method == LookupMethods.search || method == LookupMethods.user) { toReturn += "&term=" + Uri.EscapeDataString(query); } switch (sortby) { case SortMethods.Favorites: toReturn += "&sort=favorites"; break; case SortMethods.Newest: toReturn += "&sort=newest"; break; case SortMethods.Rating: toReturn += "&sort=rating"; break; case SortMethods.Views: toReturn += "&sort=views"; break; } return(toReturn += "&check_last=1"); }
public static async Task <List <Wallpaper> > QueryAsync(LookupMethods method, InfoLevels level = InfoLevels.Basic, int maxResults = 30, Size?size = null, SizeOperators op = SizeOperators.Equal, int id = 0, string searchterm = null, SortMethods sortBy = SortMethods.Newest) { int width = 0; int height = 0; SizeToParams(size, out width, out height); List <string> urls = BuildUrls(method, level, maxResults, width, height, op, id, searchterm, sortBy); return(await Task.Run(() => { try { return Get(urls); } catch (Exception) { return null; } })); }
public void SetInfoLevel(InfoLevels includedLevel) { _includedLevels = includedLevel; }