Beispiel #1
0
        public void TestFileOutput()
        {
            string resource = "AssignmentTests.Resources.t1.in";
            using(TempFileWrapper outFile = new TempFileWrapper(Path.GetTempFileName ()),
                  inFile = TestHelper.ExtractResourceToTempFile (resource))
            {
                this.Runner.StartApp (new string[] {"-output", outFile, inFile});

                List<string> lines = this.Runner.GetOutputLines ();
                lines.RemoveAll ((string line) => (new Regex("^\\s*$")).IsMatch (line));

                Assert.AreEqual (0, lines.Count, this.Runner.ExtendedMessage ().WithMessages ("Unexpected output on console", "Expected all output to file"));

                using(FileStream outputReadStream = File.Open(outFile, FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    StreamReader reader = new StreamReader(outputReadStream);
                    List<string> fileLines = new List<string>();
                    String line;
                    while((line = reader.ReadLine ()) != null) {
                        fileLines.Add (line);
                    }

                    fileLines.RemoveAll ((string s) => (new Regex("^\\s*$")).IsMatch (s));

                    Assert.AreEqual (3 * 7, fileLines.Count, this.Runner.ExtendedMessage ().WithMessages ("Unexpected number of lines in output file", "Note: this test should produce no loan errors"));
                }
            }
        }
Beispiel #2
0
        public void TestFileOutput()
        {
            using(TempFileWrapper outFile = new TempFileWrapper(Path.GetTempFileName ()),
                  inFile = TestHelper.ExtractResourceToTempFileWithName ("AssignmentTests.Resources.r1-full.in", "test range.txt"))
            {
                this.Runner.StartApp (new string[] {"-output", outFile, inFile});

                List<string> lines = this.Runner.GetOutputLines ();
                Dictionary<R2OutputLineType,List<string>> categorizedLines = this.CategorizeLines (lines);

                int total = 0;
                foreach (R2OutputLineType type in Enum.GetValues (typeof(R2OutputLineType))) {
                    total += categorizedLines[type].Count;
                }

                Assert.AreEqual (0, total, this.Runner.ExtendedMessage ().WithMessages ("Program provided unexpected output", "All output should be to file"));

                using(FileStream outputReadStream = File.Open(outFile, FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    StreamReader reader = new StreamReader(outputReadStream);
                    List<string> fileLines = new List<string>();
                    String line;
                    while((line = reader.ReadLine ()) != null) {
                        fileLines.Add (line);
                    }
                    categorizedLines = this.CategorizeLines(fileLines);

                    Assert.AreEqual (1, categorizedLines[R2OutputLineType.Header].Count,
                                     this.Runner.ExtendedMessage ().WithMessage ("Program had unexpected number of header lines in output file"));
                    Assert.AreEqual (4, categorizedLines[R2OutputLineType.Range].Count,
                                     this.Runner.ExtendedMessage ().WithMessage ("Program had unexpected number of range lines in output file"));
                }
            }
        }
Beispiel #3
0
        public void TestFileOutputWithBatchLoad()
        {
            // Use the T1 input file multiple times
            // The temp file wrapper semantics will give different range names
            using(TempFileWrapper outFile = new TempFileWrapper(Path.GetTempFileName ()),
                  inFile = TestHelper.ExtractResourceToTempFile ("AssignmentTests.Resources.t1.in"),
                  inFile2 = TestHelper.ExtractResourceToTempFile ("AssignmentTests.Resources.t2-frmarm.in"))
            {
                this.Runner.StartApp (new string[] {"-output", outFile, inFile, inFile2});
                this.Runner.WriteInputLine ("");

                List<string> lines = this.Runner.GetOutputLines ();
                lines.RemoveAll ((string s) => (new Regex("^\\s*$")).IsMatch (s));

                Assert.AreEqual (0, lines.Count, this.Runner.ExtendedMessage ().WithMessages ("Unexpected output on console", "Expected all output to file"));

                using(FileStream outputReadStream = File.Open(outFile, FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    StreamReader reader = new StreamReader(outputReadStream);
                    List<string> fileLines = new List<string>();
                    String line;
                    while((line = reader.ReadLine ()) != null) {
                        fileLines.Add (line);
                    }

                    fileLines.RemoveAll ((string s) => (new Regex("^\\s*$")).IsMatch (s));

                    // 7 * (3 + 2) + 1 == seven lines for each transaction, three transactions in first file, two in second, one bonus line for margin amount
                    Assert.AreEqual (7 * (3 + 2) + 1, fileLines.Count, this.Runner.ExtendedMessage ().WithMessages ("Unexpected number of lines in output file", "Note: this test should produce no loan errors"));
                }
            }
        }