public static bool IsFavourite(FavouriteType type, string id) { if (KnownFavourites.ContainsKey(type)) { return(KnownFavourites[type].Any(s => s == id)); } return(false); }
public async Task Test_GetFavourite(FavouriteType favouriteType, string id) { // Arrange await _client.SetFavouriteAsync(favouriteType, SetType.Add, id); // Act var result = await _client.GetFavouriteAsync(favouriteType, id); // Assert Assert.IsTrue(result.Value); }
public async Task Test_ListFavourite(FavouriteType favouriteType, string id) { // Arrange var response = await _client.SetFavouriteAsync(favouriteType, SetType.Add, id); // Act var result = await _client.ListFavouriteAsync(favouriteType, new List <string> { id }); // Assert Assert.IsTrue(result.Items.All(a => a == true)); }
public static async Task ModifyFavourite(int id, FavouriteType type, bool add) { string idFieldName; string actionId; switch (type) { case FavouriteType.Anime: idFieldName = "aid"; actionId = add ? "13" : "14"; break; case FavouriteType.Manga: idFieldName = "mid"; actionId = add ? "38" : "39"; break; case FavouriteType.Character: idFieldName = "cid"; actionId = add ? "42" : "43"; break; case FavouriteType.Person: idFieldName = "vaid"; actionId = add ? "47" : "48"; break; default: throw new ArgumentOutOfRangeException(nameof(type), type, null); } try { var client = await MalHttpContextProvider.GetHttpContextAsync(); var charCont = new List <KeyValuePair <string, string> > { new KeyValuePair <string, string>(idFieldName, id.ToString()), new KeyValuePair <string, string>("csrf_token", client.Token) }; var contentchar = new FormUrlEncodedContent(charCont); await client.PostAsync($"/includes/ajax.inc.php?s=1&t={actionId}", contentchar); } catch (WebException) { MalHttpContextProvider.ErrorMessage("Favourites"); } }
public static async Task ModifyFavourite(int id, FavouriteType type, bool add) { string idFieldName; string actionId; switch (type) { case FavouriteType.Anime: idFieldName = "aid"; actionId = add ? "13" : "14"; break; case FavouriteType.Manga: idFieldName = "mid"; actionId = add ? "38" : "39"; break; case FavouriteType.Character: idFieldName = "cid"; actionId = add ? "42" : "43"; break; case FavouriteType.Person: idFieldName = "vaid"; actionId = add ? "47" : "48"; break; default: throw new ArgumentOutOfRangeException(nameof(type), type, null); } try { var client = await MalHttpContextProvider.GetHttpContextAsync(); var charCont = new List<KeyValuePair<string, string>> { new KeyValuePair<string, string>(idFieldName, id.ToString()), new KeyValuePair<string, string>("csrf_token", client.Token) }; var contentchar = new FormUrlEncodedContent(charCont); await client.PostAsync($"/includes/ajax.inc.php?s=1&t={actionId}", contentchar); } catch (WebException) { MalHttpContextProvider.ErrorMessage("Favourites"); } }
public static async Task RemoveFavourite(FavouriteType type, string id) { _changedSth = true; KnownFavourites[type].Remove(id); await MalFavouriteQuery.ModifyFavourite(int.Parse(id), type, false); }
public static bool IsFavourite(FavouriteType type, string id) { return(KnownFavourites[type].Any(s => s == id)); }
public static void ForceNewSet(FavouriteType type, List <string> favs) { _changedSth = true; KnownFavourites[type] = favs; }
public static bool IsFavourite(FavouriteType type, string id) { return KnownFavourites[type].Any(s => s == id); }
public static void ForceNewSet(FavouriteType type,List<string> favs) { _changedSth = true; KnownFavourites[type] = favs; }
public async Task Test_ToggleFavourite(FavouriteType favouriteType, string id) { var result = await _client.ToggleFavouriteAsync(favouriteType, id); Assert.IsTrue(result.Value); }