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

/V2.2/trunk/RI/StockTraderRI.Tests.AcceptanceTest/StockTraderRI.Tests.AcceptanceTest/TestInfrastructure/DataProvider/DataProviderBase.cs

#
C# | 80 lines | 53 code | 11 blank | 16 comment | 5 complexity | 41c0a197eeb6066c0f89725ac84c8070 MD5 | raw file
  1. //===================================================================================
  2. // Microsoft patterns & practices
  3. // Composite Application Guidance for Windows Presentation Foundation and Silverlight
  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.Text;
  21. using System.Xml.Serialization;
  22. using System.Xml;
  23. namespace StockTraderRI.Tests.AcceptanceTest.TestInfrastructure
  24. {
  25. public abstract class DataProviderBase<TEntity> : IDataProvider<TEntity>, IDisposable
  26. {
  27. XmlSerializer xmlSerializer = null;
  28. XmlTextReader xmlReader = null;
  29. protected DataProviderBase()
  30. {
  31. xmlSerializer = new XmlSerializer(typeof(List<TEntity>));
  32. xmlReader = new XmlTextReader(GetDataFilePath());
  33. }
  34. public virtual List<TEntity> GetData()
  35. {
  36. return (List<TEntity>)(xmlSerializer.Deserialize(xmlReader));
  37. }
  38. public virtual List<TEntity> GetDataForId(string id)
  39. {
  40. throw new NotImplementedException();
  41. }
  42. public virtual int GetCount()
  43. {
  44. return ((List<TEntity>)xmlSerializer.Deserialize(xmlReader)).Count;
  45. }
  46. public abstract string GetDataFilePath();
  47. #region IDisposable Members
  48. public void Dispose()
  49. {
  50. Dispose(true);
  51. GC.SuppressFinalize(this);
  52. }
  53. #endregion
  54. protected virtual void Dispose(bool disposing)
  55. {
  56. if (disposing)
  57. {
  58. if (null != xmlSerializer)
  59. {
  60. xmlSerializer = null;
  61. }
  62. if (null != xmlReader)
  63. {
  64. xmlReader = null;
  65. }
  66. }
  67. }
  68. }
  69. }