public async Task TestParseProducts() { string s = await File.ReadAllTextAsync("resources/common_boards.json"); JArray jarrProduct = JArray.Parse(s); Esk8Service ESS = new Esk8Service(logger); List <Product> Products = ProductParser.ParseProducts(jarrProduct); Assert.Equal(138, Products.Count); return; }
public async Task TestCombineProductCompanies() { Esk8Service ESS = new Esk8Service(logger); string rawCompanies = await File.ReadAllTextAsync("resources/common_companies.json"); string rawProducts = await File.ReadAllTextAsync("resources/common_boards.json"); JArray jarrCompany = JArray.Parse(rawCompanies); JArray jarrProduct = JArray.Parse(rawProducts); List <Company> companies = CompanyParser.ParseCompanies(jarrCompany); List <Product> products = ProductParser.ParseProducts(jarrProduct); List <Company> combined = CompanyParser.CombineCompanyLists(companies, products.Select(x => x.Company)); Assert.Equal(42, combined.Count); }
public async Task TestMakeEmailsFromMatches() { MailgunService MSS = new MailgunService(logger); string bstthreadloc = await File.ReadAllTextAsync("resources/bstthread.json"); JArray BSTThreadJson = JArray.Parse(bstthreadloc); RedditService RSS = new RedditService(logger); // Get BST thread string rawCompanies = await File.ReadAllTextAsync("resources/common_companies.json"); string rawProducts = await File.ReadAllTextAsync("resources/common_boards.json"); JArray jarrCompany = JArray.Parse(rawCompanies); JArray jarrProduct = JArray.Parse(rawProducts); List <Company> companies = CompanyParser.ParseCompanies(jarrCompany); List <Product> products = ProductParser.ParseProducts(jarrProduct); List <Company> combined = CompanyParser.CombineCompanyLists(companies, products.Select(x => x.Company)); Esk8Service ESS = new Esk8Service(logger); List <RegexCategory <Company> > CompRs = ESS.GetCompanyRegexs(companies); List <RegexCategory <Product> > ProdRs = ESS.GetProductRegexs(products); List <BSTComment> comments = RSS.ParseComments(BSTThreadJson, CompRs, ProdRs); // Get mock subscribers string subloc = await File.ReadAllTextAsync("resources/Subscribers.json"); JArray subArray = JArray.Parse(subloc); List <PostedSubscribeObject> psubs = SubscriberParser.ParseSubscribers(subArray); List <Subscriber> subs = psubs.Select(x => Subscriber.FromPostedSubscriber(x)).ToList(); MatchService LSS = new MatchService(logger); Dictionary <Subscriber, List <LambdaMatch> > matches = LSS.MakeMatches(subs, comments); List <MailgunEmail> emails = matches.Select(x => MSS.MakeEmail(x.Key, x.Value)).ToList(); }
public async Task <List <Product> > GetCommonBoards() { List <Product> products = new List <Product>(); try { HttpResponseMessage m = await Client.GetAsync(COMMONBOARDSURL); if (!m.IsSuccessStatusCode) { Logger.Log($"Failed while trying to get Common Products from Esk8 server. Code: {m.StatusCode}, Reason: {m.ReasonPhrase}"); return(null); } string productJson = await m.Content.ReadAsStringAsync(); JArray comps = JArray.Parse(productJson); products = ProductParser.ParseProducts(comps); return(products); } catch (Exception e) { Logger.Log($"An unknown error ocurred while deserializing the Common Products json file:\n{e.Message}"); return(null); } }
public async Task TestParseBSTThreadWithUntilDate() { string s = await File.ReadAllTextAsync("resources/bstthread.json"); JArray BSTThreadJson = JArray.Parse(s); RedditService RSS = new RedditService(logger); // Get Companies, Products, Regexes, etc string rawCompanies = await File.ReadAllTextAsync("resources/common_companies.json"); string rawProducts = await File.ReadAllTextAsync("resources/common_boards.json"); JArray jarrCompany = JArray.Parse(rawCompanies); JArray jarrProduct = JArray.Parse(rawProducts); List <Company> companies = CompanyParser.ParseCompanies(jarrCompany); List <Product> products = ProductParser.ParseProducts(jarrProduct); List <Company> combined = CompanyParser.CombineCompanyLists(companies, products.Select(x => x.Company)); Esk8Service ESS = new Esk8Service(logger); List <RegexCategory <Company> > CompRs = ESS.GetCompanyRegexs(companies); List <RegexCategory <Product> > ProdRs = ESS.GetProductRegexs(products); DateTimeOffset Aug42018 = new DateTimeOffset(2018, 8, 4, 0, 0, 0, TimeSpan.FromSeconds(0)); List <BSTComment> comments = RSS.ParseComments(BSTThreadJson, CompRs, ProdRs, Aug42018); // Assert that there are 29 items in this json Assert.Equal(18, comments.Count); // Assert that there are X items for WTB Assert.Equal(1, comments.Count(x => x.BuySellTradeStatus == BST.BUY)); // Assert that there are Y items for WTS Assert.Equal(17, comments.Count(x => x.BuySellTradeStatus == BST.SELL)); // Assert that there are 0 items for Trade Assert.Equal(0, comments.Count(x => x.BuySellTradeStatus == BST.TRADE)); }
public async Task TestMakeLambdaDelta() { string bstthreadloc = await File.ReadAllTextAsync("resources/bstthread.json"); JArray BSTThreadJson = JArray.Parse(bstthreadloc); RedditService RSS = new RedditService(logger); // Get BST thread string rawCompanies = await File.ReadAllTextAsync("resources/common_companies.json"); string rawProducts = await File.ReadAllTextAsync("resources/common_boards.json"); JArray jarrCompany = JArray.Parse(rawCompanies); JArray jarrProduct = JArray.Parse(rawProducts); List <Company> companies = CompanyParser.ParseCompanies(jarrCompany); List <Product> products = ProductParser.ParseProducts(jarrProduct); List <Company> combined = CompanyParser.CombineCompanyLists(companies, products.Select(x => x.Company)); Esk8Service ESS = new Esk8Service(logger); List <RegexCategory <Company> > CompRs = ESS.GetCompanyRegexs(companies); List <RegexCategory <Product> > ProdRs = ESS.GetProductRegexs(products); List <BSTComment> comments = RSS.ParseComments(BSTThreadJson, CompRs, ProdRs); // Get mock subscribers string subloc = await File.ReadAllTextAsync("resources/Subscribers.json"); JArray subArray = JArray.Parse(subloc); List <PostedSubscribeObject> psubs = SubscriberParser.ParseSubscribers(subArray); List <Subscriber> subs = psubs.Select(x => Subscriber.FromPostedSubscriber(x)).ToList(); Subscriber BoostedMeepoWowGoEvolveGuy = subs.FirstOrDefault(x => x.DocumentId == "*****@*****.**".ToLower()); Subscriber LiterallyEverythingGuy = subs.FirstOrDefault(x => x.DocumentId == "*****@*****.**".ToLower()); Subscriber WTSABackfire = subs.FirstOrDefault(x => x.DocumentId == "*****@*****.**".ToLower()); MatchService LSS = new MatchService(logger); Dictionary <Subscriber, List <LambdaMatch> > matches = LSS.MakeMatches(subs, comments); // Assert that 3 people had matches on this thread Assert.Equal(3, matches.Count); // Assert that Guy#1 had 10 matches, all of which are either Boosted, Meepo, WowGo, or Evolve below $1000 USD var bmwegMatches = matches[BoostedMeepoWowGoEvolveGuy]; Assert.Equal(10, bmwegMatches[0].Posts.Count); Assert.True(bmwegMatches[0].Posts.All(x => new string[] { "boosted", "wowgo", "meepo", "evolve" }.Contains(x.Company.ToLowerInvariant()))); Assert.True(bmwegMatches[0].Posts.All(x => x.Price <= bmwegMatches[0].FbMatch.Price)); Assert.True(bmwegMatches[0].Posts.All(x => x.Currency == "USD")); Assert.True(bmwegMatches[0].Posts.All(x => x.BuySellTradeStatus == BST.SELL)); // Assert that Guy#2 matched literally everything var leMatches = matches[LiterallyEverythingGuy]; Assert.Equal(comments.Count, leMatches[0].Posts.Count); // Comment count and return count should always be equal - this guy just wants to see everything! // Assert that Guy#3 has a single match for someome who wants to buy his Backfire var bfMatches = matches[WTSABackfire]; Assert.Single(bfMatches[0].Posts); Assert.True(bfMatches[0].Posts.All(x => x.Company.ToLower() == "backfire")); Assert.True(bfMatches[0].Posts.All(x => x.BuySellTradeStatus == BST.BUY)); }