public void TestSkipSetnbs() { // The database now contains one star (Tobian, A5401532), with one // colleague (Bunn, A4800524). Only Bunn is a true colleague, and he // has one publication in common with Tobian. // Generate the report string JournalWeightsFilename = AppDomain.CurrentDomain.BaseDirectory + "\\Test Data\\TestStarColleaguesReport\\" + "pubmed_jifs.xls"; // Add Bunn's setnb to SetnbsToSkip ArrayList SetnbsToSkip = new ArrayList(); SetnbsToSkip.Add("A4800524"); StringWriter writer = new StringWriter(); StarColleaguesReport.Generate(writer, DB, JournalWeightsFilename, SetnbsToSkip, null, true); StringReader actual = new StringReader(writer.ToString()); // Read the expected output from the test file StreamReader expected = new StreamReader( AppDomain.CurrentDomain.BaseDirectory + "\\Test Data\\TestStarColleaguesReport\\" + "TobianBunnReport.csv" ); // Verify that the header is intact but that there are no other rows. string ActualLine; string ExpectedLine; ActualLine = actual.ReadLine(); Assert.IsNotNull(ActualLine); string[] ActualValues = ActualLine.Split(new char[] { ',' }); Assert.IsFalse(expected.EndOfStream); ExpectedLine = expected.ReadLine(); string[] ExpectedValues = ExpectedLine.Split(new char[] { ',' }); Assert.AreEqual(ActualValues.Length, ExpectedValues.Length); for (int i = 0; i < ActualValues.Length; i++) { Assert.AreEqual(ActualValues[i], ExpectedValues[i]); } // Verify that the report contains no other rows after the header. Assert.IsTrue(actual.ReadToEnd() == ""); }
public void TestReportGeneration() { // The database now contains one star (Tobian, A5401532), with one // colleague (Bunn, A4800524). Only Bunn is a true colleague, and he // has one publication in common with Tobian. // Generate the report string JournalWeightsFilename = AppDomain.CurrentDomain.BaseDirectory + "\\Test Data\\TestStarColleaguesReport\\" + "pubmed_jifs.xls"; ArrayList SetnbsToSkip = new ArrayList(); StringWriter writer = new StringWriter(); StarColleaguesReport.Generate(writer, DB, JournalWeightsFilename, SetnbsToSkip, null, true); StringReader actual = new StringReader(writer.ToString()); // Read the expected output from the test file StreamReader expected = new StreamReader( AppDomain.CurrentDomain.BaseDirectory + "\\Test Data\\TestStarColleaguesReport\\" + "TobianBunnReport.csv" ); // Verify that each row was written correctly column by column (to provide // good debug data) string ActualLine; string ExpectedLine; int Row = 0; while ((ActualLine = actual.ReadLine()) != null) { Row++; string[] ActualValues = ActualLine.Split(new char[] { ',' }); Assert.IsFalse(expected.EndOfStream); ExpectedLine = expected.ReadLine(); string[] ExpectedValues = ExpectedLine.Split(new char[] { ',' }); Assert.AreEqual(ActualValues.Length, ExpectedValues.Length, "Row " + Row.ToString() + " has incorrect number of columns\nExpected: " + ExpectedLine + "\n Actual: " + ActualLine); for (int Col = 0; Col < ActualValues.Length; Col++) { Assert.AreEqual(ActualValues[Col], ExpectedValues[Col], "Row " + Row.ToString() + ", column " + (Col + 1).ToString()); } } Assert.IsTrue(expected.EndOfStream); }