public void ToJson_Object_AreEqual() { var response = new GameResponse() { game = new Game() { board = new Board() { size = 1, tiles = "##" }, id = "id1", maxTurns = 1200, turn = 1, heroes = new List <Vindinium.Serialization.Hero>() { new Vindinium.Serialization.Hero() { name = "HERO 4 ever" }, } }, token = "ABCDEF1234" }; var act = response.ToJson(); var exp = "{\"game\":{\"board\":{\"size\":1,\"tiles\":\"##\"},\"finished\":false,\"heroes\":[{\"crashed\":false,\"elo\":0,\"gold\":0,\"id\":0,\"life\":0,\"mineCount\":0,\"name\":\"HERO 4 ever\",\"pos\":null,\"spawnPos\":null}],\"id\":\"id1\",\"maxTurns\":1200,\"turn\":1},\"hero\":null,\"playUrl\":null,\"token\":\"ABCDEF1234\",\"viewUrl\":null}"; Assert.AreEqual(exp, act); }
public bool Update(Game newGame) { GameResponse gm = null; gm = GetAll(); try { var res = gm.Games.Find(x => x.Id == newGame.Id); if (res != null) { res.Description = newGame.Description; res.IsActive = newGame.IsActive; res.Picture = newGame.Picture; res.Size = newGame.Size; res.Title = newGame.Title; res.Selected = newGame.Selected; res.TorrentUrl = newGame.TorrentUrl; string json = gm.ToJson(); File.WriteAllText(JsonDbPath, json); return(true); } else { return(false); } } catch (Exception e) { return(false); } }
public bool Delete(string id) { GameResponse gm = null; gm = GetAll(); int res = gm.Games.RemoveAll(x => x.Id == id); if (res != 0) { string json = gm.ToJson(); File.WriteAllText(JsonDbPath, json); return(true); } else { return(false); } }
public bool Add(ref Game newGame) { GameResponse gm = null; gm = GetAll(); newGame.GameId = gm.Games.Count + 1; newGame.Id = Guid.NewGuid().ToString().Replace("-", ""); gm?.Games.Add(newGame); string json = gm.ToJson(); try { File.WriteAllText(JsonDbPath, json); return(true); } catch (Exception ex) { return(false); } }