Guest User

Untitled

a guest
May 25th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.38 KB | None | 0 0
  1. [TestClass]
  2. public class XmlFormatDetectorTest : BDDTest<XmlFormatDetectorTest>
  3. {
  4. [TestMethod]
  5. public void Detects_that_a_file_follows_the_FHNBransjestandard1_format()
  6. {
  7. Given.we_got_a_file("FNHBransjestandard1.xml");
  8. When.we_try_to_detect_the_file_format();
  9. Then.fileformat.ShouldBe(KnownFileFormats.FNHBransjestandard1);
  10. }
  11.  
  12. [TestMethod]
  13. public void Detects_that_a_file_follows_the_FHNBransjestandard103_format()
  14. {
  15. Given.we_got_a_file("FNHBransjestandard103.xml");
  16. When.we_try_to_detect_the_file_format();
  17. Then.fileformat.ShouldBe(KnownFileFormats.FNHBransjestandard103);
  18. }
  19.  
  20. [TestMethod]
  21. public void Detects_that_a_file_is_unknown()
  22. {
  23. Given.we_got_a_file("BHRamberg.xml");
  24. When.we_try_to_detect_the_file_format();
  25. Then.fileformat.ShouldBe(KnownFileFormats.Unknown);
  26. }
  27.  
  28. [TestMethod]
  29. public void Empty_xml_document_is_of_unknown_format()
  30. {
  31. xml = new XDocument();
  32. When.we_try_to_detect_the_file_format();
  33. Then.fileformat.ShouldBe(KnownFileFormats.Unknown);
  34. }
  35.  
  36. private void we_got_a_file(string filename)
  37. {
  38. using (var xmlReader = new XmlTextReader(resources.GetResourceFile(filename)))
  39. {
  40. xml = XDocument.Load(xmlReader);
  41. }
  42. }
  43.  
  44. private void we_try_to_detect_the_file_format()
  45. {
  46. fileformat = formatDetector.FindFileFormat(xml);
  47. }
  48.  
  49. private KnownFileFormats fileformat;
  50. private XmlFormatDetector formatDetector;
  51. private ResourceRepository resources;
  52. private XDocument xml;
  53.  
  54. [TestInitialize]
  55. public void Setup()
  56. {
  57. formatDetector = new XmlFormatDetector();
  58. resources = new ResourceRepository();
  59. }
  60. }
  61.  
  62. [TestClass]
  63. public class StaffPaymentReportTest : BDDTest<StaffPaymentReportTest>
  64. {
  65. [TestMethod]
  66. public void Should_find_company_numbers_in_reports()
  67. {
  68. Given.we_have_a_File_with_multiple_companies();
  69. When.we_try_to_find_company_numbers();
  70. Then.companyNumbers.ShouldHave(2);
  71. }
  72.  
  73. [TestMethod]
  74. public void Should_find_company_numbers_even_if_formatted()
  75. {
  76. Given.we_have_a_file_with_formatted_company_number();
  77. When.we_try_to_find_company_numbers();
  78. Then.companyNumbers.ShouldHave(1);
  79. }
  80.  
  81. [TestInitialize]
  82. public void We_have_a_staff_payment_report()
  83. {
  84. staffPaymentReport = new StaffPaymentReport(new CompanyNumberValidator());
  85. xmlReportParser = new XmlReportParser();
  86. resourceRepository = new ResourceRepository();
  87. }
  88.  
  89. private void we_have_a_file_with_formatted_company_number()
  90. {
  91. filename = "ForetaksnummerFormatering.xml";
  92. }
  93.  
  94. private void we_have_a_File_with_multiple_companies()
  95. {
  96. filename = "Flere_Bedrift_Noder_Med_Personer.xml";
  97. }
  98.  
  99. private void we_try_to_find_company_numbers()
  100. {
  101. using (var file = resourceRepository.GetResourceFile(filename))
  102. {
  103. parsedFile = xmlReportParser.Parse(file, filename);
  104. companyNumbers = staffPaymentReport.FindCompanyNumber(parsedFile.DataTable);
  105. }
  106. }
  107.  
  108. private StaffPaymentReport staffPaymentReport;
  109. private ResourceRepository resourceRepository;
  110. private XmlReportParser xmlReportParser;
  111. private List<string> companyNumbers;
  112. private ParsedReport parsedFile;
  113. private string filename;
  114. }
Add Comment
Please, Sign In to add comment