public void Visible_Should_Throw_ArgumentNullException_If_Categories_Is_Null() { IQueryable<Category> categories = null; var ex = Assert.Throws<ArgumentNullException>(() => CategoryExtensions.Visible(categories)); Assert.Equal(nameof(categories), ex.ParamName); }
/// <summary> /// Get all medals on the game /// </summary> public IEnumerable <Medal> GetMedals(Platform platform) { Log.DebugFormat("Fetching medals on platform {0}...", platform); string server; switch (platform) { case Platform.XBOX: server = "api-xbox-console.worldoftanks.com"; break; case Platform.PS: server = "api-ps4-console.worldoftanks.com"; break; default: throw new ArgumentOutOfRangeException(nameof(platform), platform, null); } var url = $"https://{server}/wotx/encyclopedia/achievements/?application_id={ApplicationId}"; var json = GetContentSync($"Achievements.{platform}.json", url, WebCacheAge, false, Encoding.UTF8).Content; var o = JObject.Parse(json); var status = (string)o["status"]; if (status != "ok") { var error = o["error"]; Log.Error($"Error: {(string)error["code"]} - {(string)error["message"]}"); throw new ApplicationException($"Error calling WG API: {(string)error["code"]} - {(string)error["message"]}"); } var medals = new List <Medal>(); var data = o["data"]; foreach (var t in data.Cast <JProperty>()) { var ti = t.Value; var medal = new Medal { Platform = platform, Code = t.Name, Category = CategoryExtensions.Parse((string)ti["category"]), Name = (string)ti["name"], Section = SectionExtensions.Parse((string)ti["section"]), Type = TypeExtensions.Parse((string)ti["type"]), Description = (string)ti["description"], HeroInformation = (string)ti["hero_info"], Condition = (string)ti["condition"] }; medals.Add(medal); } return(medals); }
public void VisibleFrom_Should_Throw_ArgumentNullException_If_Categories_Is_Null() { IQueryable<Category> categories = null; DateTime fromDate = DateTime.Today; var ex = Assert.Throws<ArgumentNullException>(() => CategoryExtensions.VisibleFrom(categories, fromDate)); Assert.Equal(nameof(categories), ex.ParamName); }
public void ByParent_Should_Throw_ArgumentNullException_If_Categories_Is_Null() { IQueryable<Category> categories = null; Guid parentId = Guid.NewGuid(); var ex = Assert.Throws<ArgumentNullException>(() => CategoryExtensions.ByParent(categories, parentId)); Assert.Equal(nameof(categories), ex.ParamName); }
public void ByParent_Should_Throw_ArgumentException_If_ParentId_Is_Empty() { var c1 = Category.Create("c1", "c1", "c1"); var c2 = Category.Create("c2", "c2", "c2"); var c3 = Category.Create("c3", "c3", "c3"); IQueryable<Category> categories = new Category[] { c1, c2, c3 }.AsQueryable(); Guid parentId = Guid.Empty; var ex = Assert.Throws<ArgumentException>(() => CategoryExtensions.ByParent(categories, parentId)); Assert.Equal(nameof(parentId), ex.ParamName); }
public void Active_Should_Return_Only_Categories_Not_Deleted() { var c1 = Category.Create("c1", "c1", "c1"); var c2 = Category.Create("c2", "c2", "c2"); var c3 = Category.Create("c3", "c3", "c3"); c3.Delete(); IQueryable<Category> categories = new Category[] { c1, c2, c3 }.AsQueryable(); var activeCategories = CategoryExtensions.Active(categories).ToArray(); Assert.True(activeCategories.All(c => !c.Deleted)); }
public void ByParent_Should_Return_Only_Categories_With_The_Specified_Parent() { var c1 = Category.Create("c1", "c1", "c1"); var c2 = Category.Create("c2", "c2", "c2"); var c3 = Category.Create("c3", "c3", "c3"); c2.SetParentCategory(c3); IQueryable<Category> categories = new Category[] { c1, c2 }.AsQueryable(); Guid parentId = c3.Id; var categoriesWithParent = CategoryExtensions.ByParent(categories, parentId).ToArray(); Assert.True(categoriesWithParent.All(c => c.Parent.Id == parentId)); }
public void VisibleFrom_Should_Returns_Only_Categories_With_VisibleFrom_Date_Greater_Than_The_Specified_Date() { DateTime fromDate = DateTime.Today; var c1 = Category.Create("c1", "c1", "c1"); var c2 = Category.Create("c2", "c2", "c2"); var c3 = Category.Create("c3", "c3", "c3"); c1.SetAsVisible(fromDate, null); c2.SetAsVisible(); IQueryable<Category> categories = new Category[] { c1, c2, c3 }.AsQueryable(); var categoriesVisible = CategoryExtensions.VisibleFrom(categories, fromDate).ToArray(); Assert.True(categoriesVisible.All(c => c.VisibleFrom >= fromDate && c.IsVisible)); }
public void VisibleTill_Should_Returns_Only_Categories_With_VisibleTo_Date_Previous_Than_The_Specified_Date() { DateTime tillDate = DateTime.Today.AddDays(3); var c1 = Category.Create("c1", "c1", "c1"); var c2 = Category.Create("c2", "c2", "c2"); var c3 = Category.Create("c3", "c3", "c3"); c1.SetAsVisible(DateTime.Today, tillDate); c2.SetAsVisible(DateTime.Today, DateTime.Today.AddDays(1)); IQueryable<Category> categories = new Category[] { c1, c2, c3 }.AsQueryable(); var categoriesVisible = CategoryExtensions.VisibleFrom(categories, tillDate).ToArray(); Assert.True(categoriesVisible.All(c => c.VisibleTo <= tillDate && c.IsVisible)); }
public void Visible_Should_Return_Only_Categories_Where_Today_Date_Is_Between_VisibleFrom_And_VisibleTo() { var c1 = Category.Create("c1", "c1", "c1"); var c2 = Category.Create("c2", "c2", "c2"); var c3 = Category.Create("c3", "c3", "c3"); var today = DateTime.Today; c1.SetAsVisible(); c2.SetAsVisible(today, today.AddDays(2)); IQueryable<Category> categories = new Category[] { c1, c2, c3 }.AsQueryable(); var visibleCategories = CategoryExtensions.Visible(categories); var now = DateTime.Now; Assert.Equal(2, visibleCategories.Count()); Assert.True(visibleCategories.All(c => c.IsVisible && c.VisibleFrom <= now && (!c.VisibleTo.HasValue || c.VisibleTo >= now))); }
public void EnsureInValidCategoriesReturnUnknown() { Assert.AreEqual(Category.Unknown, CategoryExtensions.ParseCategory("BadCategory"), "Expected Unknown result"); }
public void EnsureValidCategoriesAreParsed() { Assert.AreEqual(Category.Artist, CategoryExtensions.ParseCategory("Artist"), "Expected Artist result"); }