コード例 #1
0
        public void Test4(string values, int result)
        {
            prog = new Program();

            var outcome = prog.PersistentFileClose(values);

            Assert.True(outcome == -1, $"When trying to close a file  in persistent mode: Trying to close a file which was not opened before should return -1 instead you returned: {outcome}");



            outcome = prog.PersistentFileOpen(values);
            if (outcome == result) //file could be opened or not
            {
                if (result == 0)   // file should now be open
                {
                    outcome = prog.PersistentFileClose("something weird");
                    Assert.True(outcome == -1, $"We have an open file but tried closing some other file which did not work, state: {outcome}");
                    outcome = prog.PersistentFileClose(values);
                    Assert.True(outcome == 0, $"We have an open file but closing it did not work, state: {outcome}");
                    outcome = prog.PersistentFileClose(values);
                    Assert.True(outcome == -1, "We tried closing an open file twice but the system does not return the correct state: -1");
                }
            }
            else //file open did not work correctly
            {
                Assert.True(false, "File Opening is not working correctly! To close a persistent file it needs to be open first.");
            }
        }
コード例 #2
0
        public void Test3(string values, int result, int retries)
        {
            prog = new Program();

            var outcome = prog.PersistentFileOpen(values);

            Assert.True(outcome == result, $"When trying to open a file  in persistent mode which requires an object variable: You should have returned state: {result} but did return {outcome}.");

            if (retries > 0)
            {
                if (result == 0)
                {
                    outcome = prog.PersistentFileOpen(values);
                    Assert.True(outcome == 1, "When trying to open a file  in persistent mode: Opening a file the 2nd time but did not get correct response!");
                }
                else
                {
                    outcome = prog.PersistentFileOpen(values);
                    Assert.True(outcome == result, $"When trying to open a file  in persistent mode: You should have returned file state: {result} but did return {outcome}.");
                }
            }
            else
            {
                prog    = new Program();
                outcome = prog.PersistentFileOpen(values);
                Assert.True(outcome == result, $"When trying to open a file  in persistent mode: Opening the file a 2nd time after closing the object once. You should have returned file state:{result} but did return {outcome}.");
            }
            try
            {
                prog.PersistentFileClose(values);
            }
            catch (Exception) //this needed to be added to stop some files from remaining open after not disposing the stream correctly
            { }
        }
コード例 #3
0
        public void Test5(string values, int result, int lines, string line)
        {
            prog = new Program();

            var outcome = prog.PersistentFileRead(lines);

            Assert.True(outcome.Length == 0, $"When trying to read a file  in persistent mode: Trying to read from a file which is not open did return {outcome.Length} lines.");

            var openCheck = prog.PersistentFileOpen(values);

            Assert.True(openCheck == result, $"When trying to read a file  in persistent mode: Trying to open a file for persistent access did not work.");

            if (result != 0)
            {
                return;
            }
            openCheck = prog.PersistentFileClose(values);
            Assert.True(openCheck == result, $"Trying to close a file for persistent access did not work.");
            if (result != 0)
            {
                return;
            }


            outcome = prog.PersistentFileRead(lines);
            Assert.True(outcome.Length == 0, $"Trying to read from a file which is not open did return {outcome.Length} lines.");

            prog.PersistentFileOpen(values);
            outcome = prog.PersistentFileRead(lines);
            Assert.True(outcome[lines - 1].Trim().Equals(line.Trim()), $"From the file, you should have returned {lines} lines where line nr.{lines - 1} is:\n {line} \nbut did return:\n {outcome[lines - 1]}.");

            Assert.True(outcome[lines - 1].Trim().Equals(line.Trim()), $"Reading a second time should return the same result.\nFrom the file, you should have returned {lines} lines where line nr.{lines - 1} is:\n {line} \nbut did return:\n {outcome[lines - 1]}.");

            openCheck = prog.PersistentFileClose(values.Trim());
            Assert.True(openCheck == result, $"Trying to close a file for persistent access did not work.");
        }
コード例 #4
0
 public UnitTest1()
 {
     prog = new Program();
 }