public void MTGSetTest() { MTGSet set = new MTGSet("testName", "testCode"); Assert.AreEqual("testName", set.setName); Assert.AreEqual("testCode", set.setCode); }
public void Seed() { if (_contexto.MTGSet.Any()) { return; // Banco de dados ja foi Populado } var sets = new MTGSetRepository(); var cards = new MTGCardRepository(); int i = 0; var dataSet = sets.BuscarSet(); var dataCard = cards.BuscarCard(); foreach (var item in dataSet) { var aux = item.released_at.Split('-'); var year = int.Parse(aux[0]); var month = int.Parse(aux[1]); var day = int.Parse(aux[2]); MTGSet M = new MTGSet(i, item.id, item.name, new DateTime(year, month, day), item.card_count); _contexto.Add(M); _contexto.SaveChanges(); } foreach (var item in dataCard) { // Criar rotina de guardar cards em banco } }
public void SaveIconForSet(MTGSet set) { byte[] image = apiCaller.GetSetIcon(set).Result; if (image != null) { set.IconSvgBase64 = Convert.ToBase64String(image); } }
public SetData() { // Read set data from JSON file and populate setList array string path = "C:\\stuff\\unity3d\\MTG\\MTG\\Assets\\_Imported\\Static Data\\SetList.json"; if (!File.Exists(path)) { Debug.LogError("Unable to open set data file:" + path); } string[] setDefStr = File.ReadAllLines(path); Debug.Log(setDefStr); setList = MTGSet.CreateFromJSON(setDefStr.ToString()); Debug.Log(setList); }
public async Task <byte[]> GetSetIcon(MTGSet set) { //a delay here so our ip doesn't get blocked from the api for sending too many requests if we're adding several new sets System.Threading.Thread.Sleep(200); try { var response = await httpClient.GetAsync(set.IconSvgUri); return(await response.Content.ReadAsByteArrayAsync()); } catch (Exception x) { Console.WriteLine("Failed getting icon from api for set: " + set.Name + " Exception: " + x.Message); } return(null); }
public void TestCard() { // Arrange var set = new MTGSet(1, "abc123", "conflux", new DateTime(2020, 01, 01), 300); // Act MTGCard mtgcard = new MTGCard(1, "path to exile", false, false, false, false, true, false, "W", "1", TypeRarity.Uncommon, "instant", "", "", "", "Exile target creature. " + "Its controller may search their library for a basic land card, put that card onto the " + "battlefield tapped, then shuffle their library.", "", "", 0, 0, 15, set); //Assert Assert.Equal(1, mtgcard.MTGSet.Id); Assert.Equal(300, mtgcard.MTGSet.SetLenght); Assert.Equal(1, mtgcard.Id); Assert.Equal(TypeRarity.Uncommon, mtgcard.Rarity); }
public void TestSet() { //Arrange int id = 1; string idSet = "ABC"; string name = "Theros"; DateTime lauchdate = new DateTime(2020, 10, 04); int setlenght = 358; //Act var mtgset = new MTGSet(id, idSet, name, lauchdate, setlenght); //Assert Assert.Equal(id, mtgset.Id); Assert.Equal(name, mtgset.Name); Assert.Equal(lauchdate, mtgset.LaunchDate); Assert.Equal(setlenght, mtgset.SetLenght); Assert.Equal(idSet, mtgset.IdSet); }
public void UpdateSet(MTGSet set) { _context.MTGSet.Add(set).State = Microsoft.EntityFrameworkCore.EntityState.Modified; }
public void AddSet(MTGSet set) { _context.MTGSet.Add(set); }
public async Task DoWork(CancellationToken stoppingToken) { while (!stoppingToken.IsCancellationRequested) { await Task.Delay(frequency, stoppingToken); executionCount++; Console.WriteLine("Getting all sets from api"); string allSetsJson = apiCaller.GetAllCardSets().Result; dynamic helper = Newtonsoft.Json.JsonConvert.DeserializeObject <dynamic>(allSetsJson); ICollection <MTGSet> dbSets = setData.GetSets(); foreach (var apiSet in helper.data) { MTGSet dbSet = dbSets.Where(s => s.Code == (string)apiSet.code).FirstOrDefault(); if (dbSet == null) { MTGSet s = Newtonsoft.Json.JsonConvert.DeserializeObject <MTGSet>(Convert.ToString(apiSet)); setData.SaveIconForSet(s); setData.AddSet(s); Console.WriteLine("Added " + (string)apiSet.Name + " as a new set"); } } Console.WriteLine("Saving set changes..."); setData.SaveChanges(); Console.WriteLine("Finished updating sets, starting on cards"); Console.WriteLine("Getting cards from api..."); string allCardsJson = apiCaller.GetAllCards().Result; ICollection <MTGCard> apiCards = Newtonsoft.Json.JsonConvert.DeserializeObject <ICollection <MTGCard> >(allCardsJson); Console.WriteLine("Converting to hash"); //converting to hash allows us to loop quicker through all cards HashSet <string> apiCardIds = apiCards.Select(a => a.Id).ToHashSet <string>(); HashSet <string> dbCardIds = cardData.GetAllIds(); //getting only ids from db instead of getting everything then only taking ids Console.WriteLine("Starting on cards"); int count = 0; ICollection <MTGCard> cards = new List <MTGCard>(); foreach (string apiCardId in apiCardIds) { if (!dbCardIds.Contains(apiCardId)) { cards.Add(apiCards.FirstOrDefault(c => c.Id == apiCardId)); //save every 100 to maintain speed if (count % 100 == 0) { Console.WriteLine("Quicksave ---------------------------------------------------------------"); cardData.AddMultiple(cards); cardData.SaveChanges(); cards.Clear(); } count++; } } Console.WriteLine("Saved " + count + " new cards..."); cardData.SaveChanges(); Console.WriteLine("Database update complete."); } }
public void MTGSetEmptyCodeTest() { MTGSet set = new MTGSet("testName", String.Empty); }
public void MTGSetNullCodeTest() { MTGSet set = new MTGSet("testName", null); }
public void MTGSetEmptyNameTest() { MTGSet set = new MTGSet(String.Empty, "testCode"); }
public void MTGSetNullNameTest() { MTGSet set = new MTGSet(null, "testCode"); }