PageRenderTime 24ms CodeModel.GetById 11ms app.highlight 7ms RepoModel.GetById 1ms 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
18using System;
19using System.Collections.Generic;
20using System.Linq;
21using System.Xml.Linq;
22using System.Text;
23using StockTraderRI.AcceptanceTests.TestInfrastructure.MockModels;
24using System.Data;
25using StockTraderRI.AcceptanceTests.Helpers;
26using System.Globalization;
27
28namespace StockTraderRI.AcceptanceTests.TestInfrastructure.DataProvider.ModuleDataProviders
29{
30    public class NewsDataProvider: DataProviderBase<News>
31    {
32        public NewsDataProvider()
33            : base()
34        { }
35
36        public override string GetDataFilePath()
37        {
38            return ConfigHandler.GetValue("NewsDataFile");
39        }
40
41        public override List<News> GetDataForId(string id)
42        {
43            List<News> news = new List<News>();
44
45            XDocument xDoc = XDocument.Load(GetDataFilePath());
46            foreach (XElement newsItem in xDoc.Descendants("NewsItems").Descendants("NewsItem")
47                .Where(newsItem => newsItem.Attribute(TestDataInfrastructure.GetTestInputData("TickerSymbol")).Value.Equals(id)))
48            {
49                news.Add(
50                    new News(
51                        id,
52                        newsItem.Attribute(TestDataInfrastructure.GetTestInputData("IconUri")).Value,
53                        DateTime.Parse(newsItem.Attribute(TestDataInfrastructure.GetTestInputData("PublishedDate")).Value, CultureInfo.InvariantCulture),
54                        newsItem.Elements("Title").ToList<XElement>()[0].Value,
55                        newsItem.Elements("Body").ToList<XElement>()[0].Value
56                        )
57                    );
58            }
59
60            return news;
61        }
62    }
63}