Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [TestClass]
- public class XmlFormatDetectorTest : BDDTest<XmlFormatDetectorTest>
- {
- [TestMethod]
- public void Detects_that_a_file_follows_the_FHNBransjestandard1_format()
- {
- Given.we_got_a_file("FNHBransjestandard1.xml");
- When.we_try_to_detect_the_file_format();
- Then.fileformat.ShouldBe(KnownFileFormats.FNHBransjestandard1);
- }
- [TestMethod]
- public void Detects_that_a_file_follows_the_FHNBransjestandard103_format()
- {
- Given.we_got_a_file("FNHBransjestandard103.xml");
- When.we_try_to_detect_the_file_format();
- Then.fileformat.ShouldBe(KnownFileFormats.FNHBransjestandard103);
- }
- [TestMethod]
- public void Detects_that_a_file_is_unknown()
- {
- Given.we_got_a_file("BHRamberg.xml");
- When.we_try_to_detect_the_file_format();
- Then.fileformat.ShouldBe(KnownFileFormats.Unknown);
- }
- [TestMethod]
- public void Empty_xml_document_is_of_unknown_format()
- {
- xml = new XDocument();
- When.we_try_to_detect_the_file_format();
- Then.fileformat.ShouldBe(KnownFileFormats.Unknown);
- }
- private void we_got_a_file(string filename)
- {
- using (var xmlReader = new XmlTextReader(resources.GetResourceFile(filename)))
- {
- xml = XDocument.Load(xmlReader);
- }
- }
- private void we_try_to_detect_the_file_format()
- {
- fileformat = formatDetector.FindFileFormat(xml);
- }
- private KnownFileFormats fileformat;
- private XmlFormatDetector formatDetector;
- private ResourceRepository resources;
- private XDocument xml;
- [TestInitialize]
- public void Setup()
- {
- formatDetector = new XmlFormatDetector();
- resources = new ResourceRepository();
- }
- }
- [TestClass]
- public class StaffPaymentReportTest : BDDTest<StaffPaymentReportTest>
- {
- [TestMethod]
- public void Should_find_company_numbers_in_reports()
- {
- Given.we_have_a_File_with_multiple_companies();
- When.we_try_to_find_company_numbers();
- Then.companyNumbers.ShouldHave(2);
- }
- [TestMethod]
- public void Should_find_company_numbers_even_if_formatted()
- {
- Given.we_have_a_file_with_formatted_company_number();
- When.we_try_to_find_company_numbers();
- Then.companyNumbers.ShouldHave(1);
- }
- [TestInitialize]
- public void We_have_a_staff_payment_report()
- {
- staffPaymentReport = new StaffPaymentReport(new CompanyNumberValidator());
- xmlReportParser = new XmlReportParser();
- resourceRepository = new ResourceRepository();
- }
- private void we_have_a_file_with_formatted_company_number()
- {
- filename = "ForetaksnummerFormatering.xml";
- }
- private void we_have_a_File_with_multiple_companies()
- {
- filename = "Flere_Bedrift_Noder_Med_Personer.xml";
- }
- private void we_try_to_find_company_numbers()
- {
- using (var file = resourceRepository.GetResourceFile(filename))
- {
- parsedFile = xmlReportParser.Parse(file, filename);
- companyNumbers = staffPaymentReport.FindCompanyNumber(parsedFile.DataTable);
- }
- }
- private StaffPaymentReport staffPaymentReport;
- private ResourceRepository resourceRepository;
- private XmlReportParser xmlReportParser;
- private List<string> companyNumbers;
- private ParsedReport parsedFile;
- private string filename;
- }
Add Comment
Please, Sign In to add comment