PageRenderTime 47ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 1ms

/V1/trunk/Source/StockTraderRI/StockRI.Tests.AcceptanceTests/TestInfrastructure/DataProvider/ModuleDataProviders/NewsDataProvider.cs

#
C# | 63 lines | 41 code | 6 blank | 16 comment | 0 complexity | 270630947f5a631265d97ce8cfc8be28 MD5 | raw file
  1. //===============================================================================
  2. // Microsoft patterns & practices
  3. // Composite Application Guidance for Windows Presentation Foundation
  4. //===============================================================================
  5. // Copyright (c) Microsoft Corporation. All rights reserved.
  6. // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY
  7. // OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT
  8. // LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  9. // FITNESS FOR A PARTICULAR PURPOSE.
  10. //===============================================================================
  11. // The example companies, organizations, products, domain names,
  12. // e-mail addresses, logos, people, places, and events depicted
  13. // herein are fictitious. No association with any real company,
  14. // organization, product, domain name, email address, logo, person,
  15. // places, or events is intended or should be inferred.
  16. //===============================================================================
  17. using System;
  18. using System.Collections.Generic;
  19. using System.Linq;
  20. using System.Xml.Linq;
  21. using System.Text;
  22. using StockTraderRI.AcceptanceTests.TestInfrastructure.MockModels;
  23. using System.Data;
  24. using StockTraderRI.AcceptanceTests.Helpers;
  25. using System.Globalization;
  26. namespace StockTraderRI.AcceptanceTests.TestInfrastructure.DataProvider.ModuleDataProviders
  27. {
  28. public class NewsDataProvider: DataProviderBase<News>
  29. {
  30. public NewsDataProvider()
  31. : base()
  32. { }
  33. public override string GetDataFilePath()
  34. {
  35. return ConfigHandler.GetValue("NewsDataFile");
  36. }
  37. public override List<News> GetDataForId(string id)
  38. {
  39. List<News> news = new List<News>();
  40. XDocument xDoc = XDocument.Load(GetDataFilePath());
  41. foreach (XElement newsItem in xDoc.Descendants("NewsItems").Descendants("NewsItem")
  42. .Where(newsItem => newsItem.Attribute(TestDataInfrastructure.GetTestInputData("TickerSymbol")).Value.Equals(id)))
  43. {
  44. news.Add(
  45. new News(
  46. id,
  47. newsItem.Attribute(TestDataInfrastructure.GetTestInputData("IconUri")).Value,
  48. DateTime.Parse(newsItem.Attribute(TestDataInfrastructure.GetTestInputData("PublishedDate")).Value, CultureInfo.InvariantCulture),
  49. newsItem.Elements("Title").ToList<XElement>()[0].Value,
  50. newsItem.Elements("Body").ToList<XElement>()[0].Value
  51. )
  52. );
  53. }
  54. return news;
  55. }
  56. }
  57. }