Esempio n. 1
0
        public void ScoreManager_GivenUpperSectionScore_AddsScoreToUpperScoreManager()
        {
            Mock <IUpperScoreManager> mockUpperScoreManager = new Mock <IUpperScoreManager>();
            Mock <ILowerScoreManager> mockLowerScoreManager = new Mock <ILowerScoreManager>();
            Mock <IScoreCategoryCalculatorResolver> mockCaluclatorResolver = new Mock <IScoreCategoryCalculatorResolver>();

            mockCaluclatorResolver.Setup(r => r.Resolve(It.IsAny <ScoreCategories>()))
            .Returns <IScoreCategoryCalculator>(_ =>
            {
                var mockCaluclator = new Mock <IScoreCategoryCalculator>();
                mockCaluclator.Setup(c => c.Calculate(It.IsAny <DiceSet>()))
                .Returns(30);
                return(mockCaluclator.Object);
            });
            IScoreManager manager = new ScoreManager.ScoreManager(
                mockUpperScoreManager.Object,
                mockLowerScoreManager.Object,
                mockCaluclatorResolver.Object);

            var scoreSection = new ScoreCategoryMetadata {
                Type = ScoreCategories.Aces, Section = ScoreSections.Upper
            };
            var diceSet = DiceSet.Create(new int[] { 1, 2, 3, 4, 5 });

            manager.AddScoring(new AddScoringRequest {
                CategoryMetadata = scoreSection, diceSet = diceSet
            });

            mockUpperScoreManager.Verify(m => m.AddToScore(30), Times.Once);
        }
Esempio n. 2
0
        public void AcesCalculator_GivenDiceSetWithNoAces_ReturnsZero()
        {
            IScoreCategoryCalculator calculator = new AcesScoreCalculator();
            DiceSet diceSet  = DiceSet.Create(new int[] { 6, 3, 2, 3, 4 });
            var     expected = 0;

            var result = calculator.Calculate(diceSet);

            Assert.Equal(expected, result);
        }
Esempio n. 3
0
        public void AcesCalculator_GivenDiceSetWithAces_CalculatsCorrectScore()
        {
            IScoreCategoryCalculator calculator = new AcesScoreCalculator();
            DiceSet diceSet  = DiceSet.Create(new int[] { 1, 1, 2, 3, 4 });
            var     expected = 2;

            var result = calculator.Calculate(diceSet);

            Assert.Equal(expected, result);
        }
        public void FullHouseScoreCalculator_NotGivenFullHouse_ReturnsZero()
        {
            var diceSet  = DiceSet.Create(new int[] { 5, 1, 3, 3, 3 });
            var expected = 0;

            var calculator = new FullHouseScoreCalculator();
            var result     = calculator.Calculate(diceSet);

            Assert.Equal(expected, result);
        }
        public void FullHouseScoreCalculator_GivenFullHouse_ReturnsCorrectScore()
        {
            var diceSet  = DiceSet.Create(new int[] { 2, 2, 3, 3, 3 });
            var expected = 13;


            var calculator = new FullHouseScoreCalculator();
            var result     = calculator.Calculate(diceSet);

            Assert.Equal(expected, result);
        }
Esempio n. 6
0
        public void DiceState_InitializingWithCorrectNumberOfDice_DoesNotThrowException()
        {
            var exception = Record.Exception(() => DiceSet.Create(new int[] { 1, 2, 3, 4, 5 }));

            Assert.Null(exception);
        }
Esempio n. 7
0
 public void DiceState_InitializingWithWrongNumberOfDice_ThrowsException(int[] dieValues)
 {
     Assert.Throws <NumberOfDiceException>(() => DiceSet.Create(dieValues));
 }
Esempio n. 8
0
        public DiceSet RollAllButKeep(IEnumerable <int> valuesToKeep)
        {
            var newValues = GenerateNewDiceValues(5 - valuesToKeep.Count());

            return(DiceSet.Create(valuesToKeep.Concat(newValues).ToArray()));
        }
Esempio n. 9
0
 public DiceSet RollAll()
 {
     return(DiceSet.Create(GenerateNewDiceValues(5)));
 }