コード例 #1
0
        public void GetGradeAverage_ShouldYieldArithmeticAverage_WhenThereIsOneNeutralGrade()
        {
            var article = new Article();
            AddGrades(article, 3);

            decimal grade = article.GetGradeAverage();

            Assert.That(grade, Is.EqualTo(3m));
        }
コード例 #2
0
        public void GetGradeAverage_ShouldYieldArithmeticAverage_WhenThereAreManyGrades()
        {
            var article = new Article();
            AddGrades(article, 2, 5, 2, 3, 2, 1, 4, 5);

            decimal grade = article.GetGradeAverage();

            Assert.That(grade, Is.EqualTo(3m));
        }
コード例 #3
0
        public void GetGradeAverage_ShouldYieldArithmeticAverageWithDecimals()
        {
            var article = new Article();
            AddGrades(article, 2);

            decimal grade = article.GetGradeAverage();

            Assert.That(grade, Is.EqualTo(2.5m));
        }
コード例 #4
0
        public void GetGradeAverage_ShouldYieldArithmeticAverageRoundedDownToTwoDecimals_WhenThereAreManyGrades()
        {
            var article = new Article();
            AddGrades(article, 4, 1);

            decimal grade = article.GetGradeAverage();

            Assert.That(grade, Is.EqualTo(2.66m));
        }
コード例 #5
0
 public ArticleDetailsModel(Article article, string currentUserName)
 {
     Title = article.Title;
     AuthorUserName = article.Author.UserName;
     GradeAverage = Format.Grade(article.GetGradeAverage());
     Summary = article.Summary;
     Body = article.Body;
     EmailAddress = article.EmailAddress;
     var userGrade = article.Grades.SingleOrDefault(g => g.User.UserName == currentUserName);
     GradeValue = (userGrade == null ? null : (int?)userGrade.GradeValue);
 }
コード例 #6
0
 public void GetGradeAverage_ShouldYield3_WhenThereAreNoGrades()
 {
     var article = new Article();
     decimal grade = article.GetGradeAverage();
     Assert.That(grade, Is.EqualTo(3m));
 }