예제 #1
0
        public void ResultGeneratorRandom_Spin_SetValuesForEachReel()
        {
            Mock <IReel <DayOfWeek> > mockReel1 = new Mock <IReel <DayOfWeek> >();

            mockReel1.Setup(m => m.CheckIfExist(It.IsAny <DayOfWeek>())).Returns(true);
            mockReel1.Setup(m => m.SetNextValue(It.IsAny <DayOfWeek>())).Returns(() => { return(new DayOfWeek[] { DayOfWeek.Monday }); });

            Mock <IReel <DayOfWeek> > mockReel2 = new Mock <IReel <DayOfWeek> >();

            mockReel2.Setup(m => m.CheckIfExist(It.IsAny <DayOfWeek>())).Returns(true);
            mockReel2.Setup(m => m.SetNextValue(It.IsAny <DayOfWeek>())).Returns(() => { return(new DayOfWeek[] { DayOfWeek.Wednesday }); });

            Mock <IResultGenerator <DayOfWeek> > mockResultGenerator = new Mock <IResultGenerator <DayOfWeek> >();

            mockResultGenerator.Setup(m => m.GetNextResult()).Returns(() => { return(new DayOfWeek[] { DayOfWeek.Monday, DayOfWeek.Thursday }); });

            MachineOneLineWin <DayOfWeek> machine = new MachineOneLineWin <DayOfWeek>(10, new IReel <DayOfWeek>[] { mockReel1.Object, mockReel2.Object }, mockResultGenerator.Object, new Dictionary <List <DayOfWeek>, uint>());

            machine.ChangeBid(2);
            machine.Spin();
            mockReel1.Verify(m => m.SetNextValue(DayOfWeek.Monday), Times.Once);
            mockReel2.Verify(m => m.SetNextValue(DayOfWeek.Thursday), Times.Once);
            mockResultGenerator.Verify(m => m.GetNextResult(), Times.Once);
            machine.Credits.Should().Be(8, "Powinno pobrać kredyty");
        }
예제 #2
0
        public void ResultGeneratorRandom_Spin_ActProperForWin()
        {
            Mock <IReel <DayOfWeek> > mockReel1 = new Mock <IReel <DayOfWeek> >();

            mockReel1.Setup(m => m.CheckIfExist(It.IsAny <DayOfWeek>())).Returns(true);
            DayOfWeek[] resultReel1 = new DayOfWeek[] { DayOfWeek.Monday, DayOfWeek.Sunday, DayOfWeek.Monday };
            mockReel1.Setup(m => m.SetNextValue(It.IsAny <DayOfWeek>())).Returns(() => { return(resultReel1); });

            Mock <IReel <DayOfWeek> > mockReel2 = new Mock <IReel <DayOfWeek> >();

            mockReel2.Setup(m => m.CheckIfExist(It.IsAny <DayOfWeek>())).Returns(true);
            DayOfWeek[] resultReel2 = new DayOfWeek[] { DayOfWeek.Wednesday, DayOfWeek.Saturday, DayOfWeek.Thursday };
            mockReel2.Setup(m => m.SetNextValue(It.IsAny <DayOfWeek>())).Returns(() => { return(resultReel2); });

            Mock <IResultGenerator <DayOfWeek> > mockResultGenerator = new Mock <IResultGenerator <DayOfWeek> >();

            mockResultGenerator.Setup(m => m.GetNextResult()).Returns(() => { return(new DayOfWeek[] { DayOfWeek.Monday, DayOfWeek.Thursday }); });

            MachineOneLineWin <DayOfWeek> machine = new MachineOneLineWin <DayOfWeek>(10, new IReel <DayOfWeek>[] { mockReel1.Object, mockReel2.Object }, mockResultGenerator.Object, new Dictionary <List <DayOfWeek>, uint>()
            {
                { new List <DayOfWeek>()
                  {
                      DayOfWeek.Monday, DayOfWeek.Thursday
                  }, 23 }
            });

            machine.ChangeBid(2);
            (IEnumerable <IEnumerable <DayOfWeek> > reelsSpinHistory, uint?nWinValue)spinResult = machine.Spin();
            mockReel1.Verify(m => m.SetNextValue(DayOfWeek.Monday), Times.Once);
            mockReel2.Verify(m => m.SetNextValue(DayOfWeek.Thursday), Times.Once);
            mockResultGenerator.Verify(m => m.GetNextResult(), Times.Once);
            machine.Credits.Should().Be(10 - 2 + 23 * 2, "Powinno pobrać kredyty i dać wygraną");

            spinResult.reelsSpinHistory.Count().Should().Be(2);

            spinResult.reelsSpinHistory.ElementAt(0).Should().BeEquivalentTo(resultReel1, option => option.WithStrictOrdering());
            spinResult.reelsSpinHistory.ElementAt(1).Should().BeEquivalentTo(resultReel2, option => option.WithStrictOrdering());

            spinResult.nWinValue.Should().Be(46);
            machine.Wins.Should().Be(1);
        }
예제 #3
0
        public void ResultGeneratorRandom_ChangeBid_WorksAsExpected()
        {
            MachineOneLineWin <DayOfWeek> machine = new MachineOneLineWin <DayOfWeek>(10, new IReel <DayOfWeek>[] { new Mock <IReel <DayOfWeek> >().Object }, new Mock <IResultGenerator <DayOfWeek> >().Object, new Dictionary <List <DayOfWeek>, uint>());

            //Akceptowalna stawka to tylko 1 i 2,  dla innych wyjątek
            this.Invoking(t => machine.ChangeBid(0)).Should().Throw <ArgumentException>().And.ParamName.Should().BeEquivalentTo("nNewBid");
            this.Invoking(t => machine.ChangeBid(3)).Should().Throw <ArgumentException>().And.ParamName.Should().BeEquivalentTo("nNewBid");
            this.Invoking(t => machine.ChangeBid(4)).Should().Throw <ArgumentException>().And.ParamName.Should().BeEquivalentTo("nNewBid");
            this.Invoking(t => machine.ChangeBid(100)).Should().Throw <ArgumentException>().And.ParamName.Should().BeEquivalentTo("nNewBid");

            machine.ChangeBid(2);
            machine.Bid.Should().Be(2);

            machine.ChangeBid(1);
            machine.Bid.Should().Be(1);

            machine.ChangeBid(2);
            machine.Bid.Should().Be(2);
        }