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); }
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)); }
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); }
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); }
public void CategoryPropertyShouldReturnSetCategory(ScoreCategory a_scoreCategory) { sut = new CategoryScore(a_scoreCategory); ScoreCategory expected = a_scoreCategory; ScoreCategory actual = sut.Category; Assert.Equal(expected, actual); }
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)); }
public async Task DeleteAsync(CategoryScore score) { using (var conn = connectionFactory.GetEddsPerformanceConnection()) { await conn.ExecuteAsync(Resources.CategoryScore_Delete, score); } }
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)); }
// 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); }
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()); } }
public void SetShouldThrowWhenCalledWithNegativeScoreValue() { sut = new CategoryScore(ScoreCategory.Aces); Assert.Throws<ArgumentOutOfRangeException>(delegate () { sut.Set(-2, new List<int>() { 1, 1, 1, 1, 1 }); }); }
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 }); }
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. }); }
public void ShouldThrowExceptionIfNoScoreIsSet() { sut = new CategoryScore(ScoreCategory.Aces); Assert.Throws<NullReferenceException>(delegate () { int score = sut.Score; }); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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."); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }