Пример #1
0
        public void ImportScoresFromFile_WithJustOneLine_ReturnsGraderWithCorrectScoreList()
        {
            const string FIRST_LINE = "KING, MADISON, 85";



            StringBuilder sb = new StringBuilder();

            sb.Append(FIRST_LINE);


            //creating a streamReader to feed into ImportScoresFromFile
            using (var stream = new MemoryStream(Encoding.UTF8.GetBytes(sb.ToString())))
            {
                using (var streamReader = new StreamReader(stream))
                {
                    var grader = new Grader();
                    grader.ImportScoresFromFile(streamReader);

                    //we now need to check that the grader's scorelist matches what we loaded into the stream reader
                    Assert.IsTrue(grader.ScoreList.Count == 1);

                    //first item should be equal to the first line;
                    Assert.That(FIRST_LINE, Is.EqualTo(grader.ScoreList[0].LastName + SEPARATOR + grader.ScoreList[0].FirstName + SEPARATOR + grader.ScoreList[0].Score));
                }
            }
        }
Пример #2
0
        public void ImportScoresFromFile_WithNegativeNumbers_ReturnsGraderWithScoreList()
        {
            const string FIRST_LINE  = "KING, MADISON, -5";
            const string SECOND_LINE = "BUNDY, TERESSA, -1";


            StringBuilder sb = new StringBuilder();

            sb.Append(FIRST_LINE);
            sb.Append(Environment.NewLine);
            sb.Append(SECOND_LINE);


            //creating a streamReader to feed into ImportScoresFromFile
            using (var stream = new MemoryStream(Encoding.UTF8.GetBytes(sb.ToString())))
            {
                using (var streamReader = new StreamReader(stream))
                {
                    var grader = new Grader();
                    grader.ImportScoresFromFile(streamReader);

                    //we now need to check that the grader's scorelist matches what we loaded into the stream reader
                    Assert.IsTrue(grader.ScoreList.Count == 2);

                    //first item should be equal to the first line;
                    Assert.That(FIRST_LINE, Is.EqualTo(grader.ScoreList[0].LastName + SEPARATOR + grader.ScoreList[0].FirstName + SEPARATOR + grader.ScoreList[0].Score));

                    //second item should be equal to the second line
                    Assert.That(SECOND_LINE, Is.EqualTo(grader.ScoreList[1].LastName + SEPARATOR + grader.ScoreList[1].FirstName + SEPARATOR + grader.ScoreList[1].Score));
                }
            }
        }
Пример #3
0
        public void ImportScoresFromFile_WithUnixEndOfLine_ReturnsGraderCorrectCountOfScores()
        {
            const string FIRST_LINE  = "KING, MADISON, 85";
            const string SECOND_LINE = "BUNDY, TERESSA, 88";


            StringBuilder sb = new StringBuilder();

            sb.Append(FIRST_LINE);
            sb.Append("\n");
            sb.Append(SECOND_LINE);



            //creating a streamReader to feed into ImportScoresFromFile
            using (var stream = new MemoryStream(Encoding.UTF8.GetBytes(sb.ToString())))
            {
                using (var streamReader = new StreamReader(stream))
                {
                    var grader = new Grader();
                    grader.ImportScoresFromFile(streamReader);

                    //we now need to check that the grader's scorelist matches what we loaded into the stream reader
                    Assert.IsTrue(grader.ScoreList.Count == 2);
                }
            }
        }
Пример #4
0
        public void ImportScoresFromFile_WithLongList_ReturnsGraderCorrectCountOfScores()
        {
            const string FIRST_LINE    = "KING, MADISON, 85";
            int          numberOfLines = 100000;

            StringBuilder sb = new StringBuilder();

            for (int i = 1; i <= numberOfLines; i++)
            {
                sb.Append(FIRST_LINE);
                sb.Append(Environment.NewLine);
            }



            //creating a streamReader to feed into ImportScoresFromFile
            using (var stream = new MemoryStream(Encoding.UTF8.GetBytes(sb.ToString())))
            {
                using (var streamReader = new StreamReader(stream))
                {
                    var grader = new Grader();
                    grader.ImportScoresFromFile(streamReader);

                    //we now need to check that the grader's scorelist matches what we loaded into the stream reader
                    Assert.IsTrue(grader.ScoreList.Count == numberOfLines);
                }
            }
        }
Пример #5
0
        public void ImportScoresFromFile_WithEmptyFile_ReturnsEmptyScoreList()
        {
            //creating a streamReader to feed into ImportScoresFromFile
            using (var stream = new MemoryStream(Encoding.UTF8.GetBytes(String.Empty)))
            {
                using (var streamReader = new StreamReader(stream))
                {
                    var grader = new Grader();
                    grader.ImportScoresFromFile(streamReader);

                    //list should have a count of zero
                    Assert.IsTrue(grader.ScoreList.Count == 0);
                }
            }
        }
Пример #6
0
        public void ImportScoresFromFile_WithInvalidScore_ThrowsException()
        {
            const string FIRST_LINE  = "KING, MADISON, 85";
            const string SECOND_LINE = "BUNDY, TERESSA, 88";

            bool expectedExceptionThrown = false;

            StringBuilder sb = new StringBuilder();

            sb.Append(Environment.NewLine);
            sb.Append(FIRST_LINE);
            sb.Append(SECOND_LINE);
            sb.Append("LASTNAME, FIRSTNAME, INVALIDSCORE");
            sb.Append(Environment.NewLine);

            //creating a streamReader to feed into ImportScoresFromFile
            using (var stream = new MemoryStream(Encoding.UTF8.GetBytes(sb.ToString())))
            {
                using (var streamReader = new StreamReader(stream))
                {
                    var grader = new Grader();

                    try
                    {
                        grader.ImportScoresFromFile(streamReader);
                    }
                    catch (Exception e)
                    {
                        //exception has been thrown as expected
                        expectedExceptionThrown = true;
                    }

                    if (!expectedExceptionThrown)
                    {
                        Assert.Fail();
                    }
                }
            }
        }