예제 #1
0
        public void NewEmptyBookHasNoGrades()
        {
            // arrange / act
            File.Delete(FileName);
            var book = new FileSystemBook(BookName);

            // assert
            Assert.False(book.HasGrades);
        }
예제 #2
0
        public void CannotAddInvalidLetterGrade()
        {
            // arrange
            File.Delete(FileName);
            var book = new FileSystemBook(BookName);

            // act / assert
            Assert.Throws <ArgumentException>(() => book.AddGrade('L'));
            Assert.False(book.HasGrades);
        }
예제 #3
0
        public void CannotAddOutside0To100()
        {
            // arrange
            File.Delete(FileName);
            var book = new FileSystemBook(BookName);

            // act / assert
            Assert.Throws <ArgumentException>(() => book.AddGrade(-1));
            Assert.Throws <ArgumentException>(() => book.AddGrade(100.0001));
            Assert.False(book.HasGrades);
        }
예제 #4
0
        public void ExistingBookFileTest()
        {
            // arrange
            File.Delete(FileName);
            File.WriteAllText(FileName, "44 55 66 B A 77");
            // act
            var book = new FileSystemBook(BookName);

            // assert
            Assert.True(book.HasGrades);
        }
예제 #5
0
        public void AddingValidGradeMakesHasGradesTrue()
        {
            // arrange
            File.Delete(FileName);
            var book = new FileSystemBook(BookName);

            // act
            book.AddGrade(12);

            // assert
            Assert.True(book.HasGrades);
        }
예제 #6
0
        public void AddGradeRaisesGradeAddedEvent()
        {
            // arrange
            var book = new FileSystemBook(BookName);

            book.GradeAdded        += GradeAdded;
            _gradeAddedEventCounter = 0;

            // act
            book.AddGrade(1);

            // assert
            Assert.Equal(1, _gradeAddedEventCounter);
        }
예제 #7
0
        public void AddingManyGradesAddsToFile()
        {
            // arrange
            File.Delete(FileName);
            var book = new FileSystemBook(BookName);

            // act
            book.AddGrade(20);
            book.AddGrade(30);

            // assert
            var fileContent = File.ReadAllText(FileName);

            Assert.Equal("20 30", fileContent);
        }
예제 #8
0
        public void AddingOneGradeAddsToFile()
        {
            // arrange
            File.Delete(FileName);
            var book = new FileSystemBook(BookName);

            // act
            book.AddGrade(10);

            // assert
            var fileContent = File.ReadAllText(FileName);
            var grade       = double.Parse(fileContent);

            Assert.Equal(10, grade);
        }
예제 #9
0
        public void CanComputeStatistics()
        {
            // arrange
            File.Delete(FileName);
            var book = new FileSystemBook(BookName);

            book.AddGrade(56.2);
            book.AddGrade(70.4);
            book.AddGrade(42.1);

            // act
            var stats = book.ComputeStatistics();

            // assert
            Assert.Equal(56.23, stats.Average, 2);
            Assert.Equal(42.1, stats.Low);
            Assert.Equal(70.4, stats.High);
            Assert.Equal('F', stats.Letter);
        }