public async Task GetLatestTokenInformationOneRegionMoreThanTwoTokens() { var connection = new SqliteConnection("DataSource=:memory"); try { await connection.OpenAsync(); var options = new DbContextOptionsBuilder <WoWTokenContext>() .UseSqlite(connection) .Options; using (var context = new WoWTokenContext(options)) { context.Tokens.RemoveRange(await context.Tokens.ToListAsync()); context.SaveChanges(); var latestToken = new Data.Models.Database.WoWToken() { LastUpdatedTimestamp = new DateTimeOffset(DateTime.UtcNow).ToUnixTimeSeconds(), Price = 1240000000, Region = "us" }; var beforeLastToken = new Data.Models.Database.WoWToken() { LastUpdatedTimestamp = new DateTimeOffset(DateTime.UtcNow.AddMinutes(-5)).ToUnixTimeSeconds(), Price = 1230000000, Region = "us" }; await context.Database.EnsureCreatedAsync(); await context.Tokens.AddAsync(latestToken); await context.Tokens.AddAsync(beforeLastToken); await context.Tokens.AddAsync(new Data.Models.Database.WoWToken() { LastUpdatedTimestamp = new DateTimeOffset(DateTime.UtcNow.AddMinutes(-10)).ToUnixTimeSeconds(), Price = 1235000000, Region = "us" }); await context.SaveChangesAsync(); var tokenService = new TokenService(context); var latestTokenFromDatabase = await tokenService.GetLatestTokenInformationAsync("us"); Assert.AreEqual(latestToken.Price, latestTokenFromDatabase.Price); Assert.AreEqual("us", latestTokenFromDatabase.Region); Assert.AreEqual(latestToken.Price - beforeLastToken.Price, latestTokenFromDatabase.PriceDifference); } } finally { connection.Close(); } }
/// <summary> /// Initialize a new instance of <see cref="TokenSyncService" />. /// </summary> /// <param name="wowTokenContext">The WoWToken context.</param> /// <param name="settings">The application settings.</param> public TokenSyncService( WoWTokenContext wowTokenContext, IOptions <AppSettings> settings) { this.wowTokenContext = wowTokenContext; this.battleNetClientId = settings.Value.BattleNetClientId; this.battleNetClientSecret = settings.Value.BattleNetClientSecret; this.battleNetApiUrl = settings.Value.BattleNetApiUrl; this.battleNetCNApiUrl = settings.Value.BattleNetCNApiUrl; this.battleNetOAuthApiUrl = settings.Value.BattleNetOAuthApiUrl; this.battleNetCNOAuthApiUrl = settings.Value.BattleNetCNOAuthApiUrl; }
/// <summary> /// Initialize a new instance of <see cref="TokenService" />. /// </summary> /// <param name="wowTokenContext">The WoWToken context.</param> public TokenService(WoWTokenContext wowTokenContext) { this.wowTokenContext = wowTokenContext; }