コード例 #1
0
        public async Task CategoryCompleteTask_CompleteCategory_NoImplementation()
        {
            // Arrange
            var categoryScoreId = 123;
            var categoryId      = 444;
            var categoryScore   = new CategoryScore {
                CategoryId = categoryId, Score = 100, Id = categoryScoreId
            };
            var categoryScores = new[] { categoryScore };
            var category       = new Category {
                Id = categoryId, CategoryType = CategoryType.Uptime
            };

            categoryScoreRepository.Setup(csr => csr.ReadAsync(category)).ReturnsAsync(categoryScores);
            categoryRepository.Setup(r => r.ReadAsync(categoryScore.CategoryId)).ReturnsAsync(category);
            this.categoryCompleteFactory.Setup(mf => mf.GetService(CategoryType.Uptime)).Returns((ICategoryCompleteLogic)null);

            // Act
            var result = await categoryCompleteTask.CompleteCategory(categoryId);

            // Assert
            this.categoryScoreRepository.VerifyAll();
            this.logger.Verify(l => l.LogError(It.IsAny <string>(), (string)null), Times.Once);
            Assert.That(result, Is.True);
        }
コード例 #2
0
        public void CategoryCompleteTask_CompleteCategory_Error()
        {
            // Arrange// Arrange
            var categoryScoreId = 123;
            var categoryId      = 444;
            var categoryScore   = new CategoryScore {
                CategoryId = categoryId, Score = 100, Id = categoryScoreId
            };
            var categoryScores = new[] { categoryScore };
            var category       = new Category {
                Id = categoryId, CategoryType = CategoryType.Uptime
            };

            categoryScoreRepository.Setup(csr => csr.ReadAsync(category)).ReturnsAsync(categoryScores);
            categoryRepository.Setup(r => r.ReadAsync(categoryScore.CategoryId)).ReturnsAsync(category);
            var mockCategoryCompleteLogic = new Mock <ICategoryCompleteLogic>();
            var testException             = new Exception("TestException");

            mockCategoryCompleteLogic.Setup(l => l.CompleteCategory(category)).Throws(testException);
            this.categoryCompleteFactory.Setup(mf => mf.GetService(CategoryType.Uptime)).Returns(mockCategoryCompleteLogic.Object);

            // Act
            var result = Assert.ThrowsAsync <Exception>(() => categoryCompleteTask.CompleteCategory(categoryId));

            // Assert
            this.categoryScoreRepository.VerifyAll();
            Assert.That(result, Is.EqualTo(testException));
        }
コード例 #3
0
        public async Task CategoryCompleteTask_CompleteCategory_AllScored()
        {
            // Arrange
            var categoryScoreId = 123;
            var categoryId      = 444;
            var categoryScore   = new CategoryScore {
                CategoryId = categoryId, Score = 100, Id = categoryScoreId
            };
            var categoryScores = new[] { categoryScore };
            var category       = new Category {
                Id = categoryId, CategoryType = CategoryType.Uptime
            };

            categoryScoreRepository.Setup(csr => csr.ReadAsync(category)).ReturnsAsync(categoryScores);
            categoryRepository.Setup(r => r.ReadAsync(categoryScore.CategoryId)).ReturnsAsync(category);
            var mockCategoryCompleteLogic = new Mock <ICategoryCompleteLogic>();

            mockCategoryCompleteLogic.Setup(l => l.CompleteCategory(category)).Returns(Task.FromResult(0));
            this.categoryCompleteFactory.Setup(mf => mf.GetService(CategoryType.Uptime)).Returns(mockCategoryCompleteLogic.Object);

            // Act
            var result = await categoryCompleteTask.CompleteCategory(categoryId);

            // Assert
            this.categoryScoreRepository.VerifyAll();
            Assert.That(result, Is.True);
        }
コード例 #4
0
        private CategoryScore BuildCategoryScore(ScoreCategory a_scoreCategory, int a_score, List <int> a_faceValues)
        {
            CategoryScore categoryScore = new CategoryScore(a_scoreCategory);

            categoryScore.Set(a_score, a_faceValues);
            return(categoryScore);
        }
コード例 #5
0
 public void CategoryPropertyShouldReturnSetCategory(ScoreCategory a_scoreCategory)
 {
   sut = new CategoryScore(a_scoreCategory);
   ScoreCategory expected = a_scoreCategory;
   ScoreCategory actual = sut.Category;
   Assert.Equal(expected, actual);
 }
コード例 #6
0
        public void GetScoreShouldShouldReturnAScoreCategoryObject()
        {
            /*
             * We realize that we are "testing" another class here that we have not mocked.
             * The reason for this is that we cannot in a clean way mock an internal class being returned.
             * We could mock the sut and change the return type, but then we're no longer testing the sut.
             * We could add a factory creating CategoryScores, but then how do we test that factory?
             * Then the factory itself will need a factory, and that factory will need its own factory, and you see where this is going.
             * We also believe that the class CategoryScore is rather trivial (e.g. it has no methods) which helps justify this approach.
             */

            sut = new Scoresheet(MockedFactory.Object);

            List <int> faceValues = new List <int>()
            {
                1, 1, 1, 1, 1
            };
            CategoryScore expected = BuildCategoryScore(ScoreCategory.Aces, m_defaultScore, faceValues);

            IPlayer player = MockedPlayerFactory.Object;

            sut.RegisterScore(player, ScoreCategory.Aces, faceValues);

            CategoryScore actual = sut.GetScore(player, ScoreCategory.Aces);

            Assert.True(CategoryScoresEqual(expected, actual));
        }
コード例 #7
0
 public async Task DeleteAsync(CategoryScore score)
 {
     using (var conn = connectionFactory.GetEddsPerformanceConnection())
     {
         await conn.ExecuteAsync(Resources.CategoryScore_Delete, score);
     }
 }
コード例 #8
0
        public void GetScoreShouldShouldReturnMultipleScoreCategoryObjects()
        {
            sut = new Scoresheet(MockedFactory.Object);

            List <int> faceValues1 = new List <int>()
            {
                1, 1, 1, 1, 1
            };
            CategoryScore expected1 = BuildCategoryScore(ScoreCategory.Aces, m_defaultScore, faceValues1);

            List <int> faceValues2 = new List <int>()
            {
                2, 2, 2, 2, 2
            };
            CategoryScore expected2 = BuildCategoryScore(ScoreCategory.Twos, m_defaultScore, faceValues2);

            IPlayer player = MockedPlayerFactory.Object;

            sut.RegisterScore(player, ScoreCategory.Aces, faceValues1);
            sut.RegisterScore(player, ScoreCategory.Twos, faceValues2);

            CategoryScore actual1 = sut.GetScore(player, ScoreCategory.Aces);
            CategoryScore actual2 = sut.GetScore(player, ScoreCategory.Twos);

            Assert.True(CategoryScoresEqual(expected1, actual1) && CategoryScoresEqual(expected2, actual2));
        }
コード例 #9
0
        // Helper methods

        private bool CategoryScoresEqual(CategoryScore a_expected, CategoryScore a_actual)
        {
            bool hasSameFaceValues = Enumerable.SequenceEqual(a_expected.FaceValues, a_actual.FaceValues);
            bool hasSameCategory   = a_expected.Category == a_actual.Category;
            bool hasSameScore      = a_expected.Score == a_actual.Score;

            return(hasSameFaceValues && hasSameCategory && hasSameScore);
        }
コード例 #10
0
 public async Task <IList <MetricData> > ReadByCategoryScoreAsync(CategoryScore categoryScore)
 {
     using (var conn = connectionFactory.GetEddsPerformanceConnection())
     {
         return((await conn.QueryAsync <MetricData>(Resources.MetricData_ReadByCategoryScore,
                                                    new { categoryScore.ServerId, categoryScore.CategoryId })).ToList());
     }
 }
コード例 #11
0
 public void SetShouldThrowWhenCalledWithNegativeScoreValue()
 {
   sut = new CategoryScore(ScoreCategory.Aces);
   Assert.Throws<ArgumentOutOfRangeException>(delegate ()
   {
     sut.Set(-2, new List<int>() { 1, 1, 1, 1, 1 });
   });
 }
コード例 #12
0
 public void SetShouldThrowWhenCalledWithAnyInvalidDiceFaceValues()
 {
   sut = new CategoryScore(ScoreCategory.Aces);
   Assert.Throws<InvalidDieException>(delegate ()
   {
     sut.Set(25, new List<int>() { -1, -1, 9, 8, 1 }); // [1..6] is valid
   });
 }
コード例 #13
0
 public void SetShouldThrowWhenCalledWithInvalidNumberOfDiceFaceValues()
 {
   sut = new CategoryScore(ScoreCategory.Aces);
   Assert.Throws<ArgumentOutOfRangeException>(delegate ()
   {
     sut.Set(25, new List<int>() { 1, 1, 1 }); // 5 or 6 dice is valid.
   });
 }
コード例 #14
0
    public void ShouldThrowExceptionIfNoScoreIsSet()
    {
      sut = new CategoryScore(ScoreCategory.Aces);

      Assert.Throws<NullReferenceException>(delegate ()
      {
        int score = sut.Score;
      });
    }
コード例 #15
0
 public void SetUpData()
 {
     // Arrange Data by grabbing the AuditAnalysis (UX) specific metric data
     this.UxMetric = this.Metrics.First(m => m.MetricType == MetricType.AuditAnalysis);
     //var uxMetricData = this.MetricDatas.Where(md => md.MetricId == uxMetric.Id).ToList();
     this.UxMetricData    = this.MetricDatas.First(md => md.MetricId == this.UxMetric.Id);
     this.UxCategory      = this.Categories.First(c => c.CategoryType == CategoryType.UserExperience);
     this.UxCategoryScore = this.CategoryScores.First(cs => cs.CategoryId == this.UxCategory.Id);
 }
コード例 #16
0
        public void getScore_ValidateScoreFromSevens()
        {
            var testInputScoreCategory = CategoryScore.scoreCategory.Sevens;
            var testInputScores        = new int[] { 6, 7, 4, 7, 7 };

            int expectedOutput = 21;

            int actualOutput = CategoryScore.getScore(testInputScoreCategory, testInputScores);

            Assert.AreEqual(expectedOutput, actualOutput);
        }
コード例 #17
0
        public void getScore_ValidateScoreFromLargeStraightWhenZero()
        {
            var testInputScoreCategory = CategoryScore.scoreCategory.LargeStraight;
            var testInputScores        = new int[] { 3, 4, 5, 6, 8 };

            int expectedOutput = 0;

            int actualOutput = CategoryScore.getScore(testInputScoreCategory, testInputScores);

            Assert.AreEqual(expectedOutput, actualOutput);
        }
コード例 #18
0
        public void getScore_ValidateScoreFromThreeOfAKindWhenZero()
        {
            var testInputScoreCategory = CategoryScore.scoreCategory.ThreeOfAKind;
            var testInputScores        = new int[] { 1, 7, 1, 2, 8 };

            int expectedOutput = 0;

            int actualOutput = CategoryScore.getScore(testInputScoreCategory, testInputScores);

            Assert.AreEqual(expectedOutput, actualOutput);
        }
コード例 #19
0
        public void getScore_ValidateScoreFromEights()
        {
            var testInputScoreCategory = CategoryScore.scoreCategory.Eights;
            var testInputScores        = new int[] { 8, 6, 8, 8, 5 };

            int expectedOutput = 24;

            int actualOutput = CategoryScore.getScore(testInputScoreCategory, testInputScores);

            Assert.AreEqual(expectedOutput, actualOutput);
        }
コード例 #20
0
        public void getScore_ValidateScoreFromFullHouseWhenZero()
        {
            var testInputScoreCategory = CategoryScore.scoreCategory.FullHouse;
            var testInputScores        = new int[] { 1, 7, 1, 8, 8 };

            int expectedOutput = 0;

            int actualOutput = CategoryScore.getScore(testInputScoreCategory, testInputScores);

            Assert.AreEqual(expectedOutput, actualOutput);
        }
コード例 #21
0
        public void getScore_ValidateScoreFromFourOfAKind()
        {
            var testInputScoreCategory = CategoryScore.scoreCategory.FourOfAKind;
            var testInputScores        = new int[] { 1, 1, 1, 1, 8 };

            int expectedOutput = 12;

            int actualOutput = CategoryScore.getScore(testInputScoreCategory, testInputScores);

            Assert.AreEqual(expectedOutput, actualOutput);
        }
コード例 #22
0
        public void UptimeScoring_ScoreMetricsAsync_NoMetricDatas()
        {
            // Arrange
            var metricDatas   = new List <MetricData>();
            var categoryScore = new CategoryScore();

            // Act & Assert
            var logic = new UptimeScoringLogic(uptimeRatingsRepository.Object, maintenanceWindowRepository.Object, logger.Object);

            Assert.ThrowsAsync <Exception>(() => logic.ScoreMetrics(categoryScore, metricDatas), "Cannot score empty list of metric data.");
        }
コード例 #23
0
        public void getScore_ValidateScoreFromSmallStraight()
        {
            var testInputScoreCategory = CategoryScore.scoreCategory.SmallStraight;
            var testInputScores        = new int[] { 1, 2, 3, 4, 7 };

            int expectedOutput = 30;

            int actualOutput = CategoryScore.getScore(testInputScoreCategory, testInputScores);

            Assert.AreEqual(expectedOutput, actualOutput);
        }
コード例 #24
0
        public void getScore_ValidateScoreFromFours()
        {
            var testInputScoreCategory = CategoryScore.scoreCategory.Fours;
            var testInputScores        = new int[] { 4, 4, 4, 4, 5 };

            int expectedOutput = 16;

            int actualOutput = CategoryScore.getScore(testInputScoreCategory, testInputScores);

            Assert.AreEqual(expectedOutput, actualOutput);
        }
コード例 #25
0
        public void getScore_ValidateScoreFromSixes()
        {
            var testInputScoreCategory = CategoryScore.scoreCategory.Sixes;
            var testInputScores        = new int[] { 6, 6, 4, 6, 5 };

            int expectedOutput = 18;

            int actualOutput = CategoryScore.getScore(testInputScoreCategory, testInputScores);

            Assert.AreEqual(expectedOutput, actualOutput);
        }
コード例 #26
0
        public void getScore_ValidateScoreFromThrees()
        {
            var testInputScoreCategory = CategoryScore.scoreCategory.Threes;
            var testInputScores        = new int[] { 1, 3, 2, 3, 4 };

            int expectedOutput = 6;

            int actualOutput = CategoryScore.getScore(testInputScoreCategory, testInputScores);

            Assert.AreEqual(expectedOutput, actualOutput);
        }
コード例 #27
0
        public void getScore_ValidateScoreFromAllSameWhenZero()
        {
            var testInputScoreCategory = CategoryScore.scoreCategory.AllSame;
            var testInputScores        = new int[] { 1, 1, 4, 1, 1 };

            int expectedOutput = 0;

            int actualOutput = CategoryScore.getScore(testInputScoreCategory, testInputScores);

            Assert.AreEqual(expectedOutput, actualOutput);
        }
コード例 #28
0
        public void getScore_ValidateScoreFromChance()
        {
            var testInputScoreCategory = CategoryScore.scoreCategory.Chance;
            var testInputScores        = new int[] { 1, 2, 1, 8, 8 };

            int expectedOutput = 20;

            int actualOutput = CategoryScore.getScore(testInputScoreCategory, testInputScores);

            Assert.AreEqual(expectedOutput, actualOutput);
        }
コード例 #29
0
        public void getScore_ValidateScoreFromAllDifferentWhenZero()
        {
            var testInputScoreCategory = CategoryScore.scoreCategory.AllDifferent;
            var testInputScores        = new int[] { 8, 2, 4, 6, 8 };

            int expectedOutput = 0;

            int actualOutput = CategoryScore.getScore(testInputScoreCategory, testInputScores);

            Assert.AreEqual(expectedOutput, actualOutput);
        }
コード例 #30
0
        public void getScore_ValidateScoreFromOnesWhenZero()
        {
            var testInputScoreCategory = CategoryScore.scoreCategory.Ones;
            var testInputScores        = new int[] { 3, 4, 2, 3, 4 };

            int expectedOutput = 0;

            int actualOutput = CategoryScore.getScore(testInputScoreCategory, testInputScores);

            Assert.AreEqual(expectedOutput, actualOutput);
        }