void cacheing_for_select_many() { before = () => { GameSchema.CreateSchema(seed); player1Id = new { Name = "Jane" }.InsertInto("Players"); game1Id = new { Title = "Mirror's Edge" }.InsertInto("Games"); game2Id = new { Title = "Gears of War" }.InsertInto("Games"); new { PlayerId = player1Id, GameId = game2Id }.InsertInto("Library"); }; it["maintains cache of select many"] = () => { var playerCollection = players.All() as dynamic; selectMany = playerCollection.Games(); selectMany.Count().should_be(1); new { PlayerId = player1Id, GameId = game1Id }.InsertInto("Library"); selectMany = playerCollection.Games(); selectMany.Count().should_be(1); }; it["cache is also applied for parent entries"] = () => { var playerCollection = players.All() as dynamic; var firstPlayer = playerCollection.First(); playerCollection.Games(); new { PlayerId = player1Id, GameId = game1Id }.InsertInto("Library"); ((int)firstPlayer.Games().Count()).should_be(1); }; it["allows the discarding of cache"] = () => { var playerCollection = players.All() as dynamic; selectMany = playerCollection.Games(); selectMany.Count().should_be(1); new { PlayerId = player1Id, GameId = game1Id }.InsertInto("Library"); selectMany = playerCollection.Games(new { discardCache = true }); selectMany.Count().should_be(2); }; }
void belongs_where_entity_belongs_more_than_one_relation() { before = () => { seed = new Seed(); GameSchema.CreateSchema(seed); players = new Players(); player1Id = new { Name = "Jane" }.InsertInto("Players"); player2Id = new { Name = "John" }.InsertInto("Players"); game1Id = new { Title = "Mirror's Edge" }.InsertInto("Games"); game2Id = new { Title = "Gears of War" }.InsertInto("Games"); new { PlayerId = player1Id, GameId = game2Id }.InsertInto("Library"); new { PlayerId = player2Id, GameId = game1Id }.InsertInto("Library"); new { PlayerId = player2Id, GameId = game2Id }.InsertInto("Library"); sqlQueries = new List <string>(); DynamicRepository.WriteDevLog = true; DynamicRepository.LogSql = new Action <object, string, object[]>( (sender, sql, @params) => { sqlQueries.Add(sql); }); allPlayers = players.All(); allPlayers.Include("Library"); allPlayers.Library().Include("Game"); }; it["updates all references that map to the belongs to entity"] = () => { (allPlayers.First().Library().First().Game().Title as object).should_be("Gears of War"); (allPlayers.Last().Library().First().Game().Title as object).should_be("Mirror's Edge"); (allPlayers.Last().Library().Last().Game().Title as object).should_be("Gears of War"); sqlQueries.Count.should_be(3); }; }
void cache_access_in_specific_order() { before = () => { GameSchema.CreateSchema(seed); players = new Players(); player1Id = new { Name = "Jane" }.InsertInto("Players"); player2Id = new { Name = "John" }.InsertInto("Players"); game1Id = new { Title = "Mirror's Edge" }.InsertInto("Games"); game2Id = new { Title = "Gears of War" }.InsertInto("Games"); new { PlayerId = player1Id, GameId = game2Id }.InsertInto("Library"); new { PlayerId = player2Id, GameId = game1Id }.InsertInto("Library"); sqlQueries = new List <string>(); DynamicRepository.WriteDevLog = true; DynamicRepository.LogSql = new Action <object, string, object[]>( (sender, sql, @params) => { sqlQueries.Add(sql); }); }; it["in query isn't run if entries are access independently"] = () => { var allPlayers = players.All() as dynamic; (allPlayers as IEnumerable <dynamic>).Count().should_be(2); foreach (var p in allPlayers) { (p.Games() as IEnumerable <dynamic>).Count().should_be(1); } (allPlayers.Games() as IEnumerable <dynamic>).Count().should_be(2); sqlQueries.Count().should_be(3); }; after = () => DynamicRepository.WriteDevLog = false; }
void before_each() { GameSchema.CreateSchema(seed); players = new Players(); new { Name = "Fluff To Ensure Different Id's" }.InsertInto("Players"); player1Id = new { Name = "Jane" }.InsertInto("Players"); player2Id = new { Name = "John" }.InsertInto("Players"); game1Id = new { Title = "Mirror's Edge" }.InsertInto("Games"); game2Id = new { Title = "Gears of War" }.InsertInto("Games"); new { PlayerId = player1Id, GameId = game2Id }.InsertInto("Library"); new { PlayerId = player2Id, GameId = game1Id }.InsertInto("Library"); }
public async Task <GameSchema> GetSchemaForGame(int gameId) { var uriBuilder = new UriBuilder("http://api.steampowered.com/ISteamUserStats/GetSchemaForGame/v2/"); var query = HttpUtility.ParseQueryString(uriBuilder.Query); query["key"] = STEAM_KEY; query["appid"] = gameId.ToString(); uriBuilder.Query = query.ToString(); var url = uriBuilder.ToString(); var request = new HttpRequestMessage(HttpMethod.Get, url); var client = clientFactory.CreateClient(); var response = await client.SendAsync(request); if (response.IsSuccessStatusCode) { string body = await response.Content.ReadAsStringAsync(); var gameSchemaDTO = JsonConvert.DeserializeObject <GameSchemaDTO>(body); return(GameSchema.ParseFromDTO(gameSchemaDTO, gameId)); } throw new Exception(response.StatusCode.ToString()); }