Exemplo n.º 1
0
        public async Task SellBallotAsync_PicksRandomBallotRegistersAsSold()
        {
            // Arrange
            int expectedRandomNumber  = 2;
            var expectedRandomNumbers = new List <int> {
                expectedRandomNumber
            };
            int      expectedBallotNumber = 123456789;
            DateTime expectedSellDate     = new DateTime(2017, 12, 25);

            SystemTime.SetDateTime(expectedSellDate);

            var expectedBallots = new List <Ballot>
            {
                new Ballot(),
                new Ballot(),
                new Ballot()
                {
                    Number = expectedBallotNumber
                }
            };

            int?lastNumber = null;

            var expectedDraw = new Draw
            {
                SellUntilDate = new DateTime(2018, 1, 1),
                Ballots       = expectedBallots
            };

            GenerationSettings actualGenerationSettings = null;

            RandomGeneratorMock
            .Setup(mock => mock.GenerateRandomNumbersAsync(It.IsAny <GenerationSettings>()))
            .Callback((GenerationSettings generationSettings) =>
            {
                actualGenerationSettings = generationSettings;
            })
            .ReturnsAsync(expectedRandomNumbers);

            // Act
            Ballot result = await Lottery.SellBallotAsync(expectedDraw, lastNumber);

            // Assert
            result.Should().NotBeNull();
            result.Number.Should().Be(expectedBallotNumber);
            result.SellDate.Should().Be(expectedSellDate);

            actualGenerationSettings.Should().NotBeNull();
            actualGenerationSettings.NumberOfIntegers.Should().Be(1);
            actualGenerationSettings.MinimalIntValue.Should().Be(0);
            actualGenerationSettings.MaximumIntValue.Should().Be(2);

            RandomGeneratorMock.VerifyAll();
        }
Exemplo n.º 2
0
        public async Task GenerateDrawAsync_ReturnsCorrectDrawAsync()
        {
            // Arrange
            int expectedSeed            = 1;
            int expectedNumberOfBallots = 1;
            var expectedRandomNumbers   = new List <int> {
                expectedSeed
            };
            var expectedBallotNumber = 12345;

            GenerationSettings actualGenerationSettings = null;

            RandomGeneratorMock
            .Setup(mock => mock.GenerateRandomNumbersAsync(It.IsAny <GenerationSettings>()))
            .Callback((GenerationSettings generationSettings) =>
            {
                actualGenerationSettings = generationSettings;
            })
            .ReturnsAsync(expectedRandomNumbers);

            RandomWrapperMock
            .Setup(mock => mock.Seed(expectedSeed));

            RandomWrapperMock
            .Setup(mock => mock.Next(1000000, 10000000))
            .Returns(expectedBallotNumber);

            // Act
            IEnumerable <Ballot> result = await Lottery.GenerateBallotsAsync(expectedNumberOfBallots);

            // Assert
            result.Should().NotBeNull();
            result.Should().NotBeNull();
            result.Should().HaveCount(expectedNumberOfBallots);

            Ballot firstBallot = result.First();

            firstBallot.Number.Should().Be(expectedBallotNumber);
            firstBallot.SellDate.Should().BeNull();

            actualGenerationSettings.Should().NotBeNull();
            actualGenerationSettings.NumberOfIntegers.Should().Be(1);
            actualGenerationSettings.MinimalIntValue.Should().Be(1000000);
            actualGenerationSettings.MaximumIntValue.Should().Be(10000000);

            RandomGeneratorMock.VerifyAll();
            RandomWrapperMock.VerifyAll();
        }
Exemplo n.º 3
0
        public async Task DrawWinsAsync_WithLastDigitPrice_GivesCorrectBallotsThePrice()
        {
            // Arrange
            int expectedRandomNumber  = 1;
            var expectedRandomNumbers = new List <int> {
                expectedRandomNumber
            };
            DateTime expectedDrawDate = new DateTime(2018, 01, 01);

            SystemTime.SetDateTime(expectedDrawDate);

            var expectedBallots = new List <Ballot>
            {
                new Ballot {
                    Number   = 123765439,
                    SellDate = new DateTime(2017, 12, 30)
                },
                new Ballot
                {
                    Number   = 199456789,
                    SellDate = new DateTime(2017, 12, 30)
                },
                new Ballot {
                    Number   = 123456782,
                    SellDate = new DateTime(2017, 12, 30)
                },
                new Ballot {
                    Number = 876543219,
                },
            };

            var expectedFinalDigitPrice = new Price
            {
                PriceType = PriceType.FinalDigit,
                Amount    = 5
            };

            var expectedMainPrice = new Price
            {
                PriceType = PriceType.Main,
                Amount    = 1000
            };

            var prices = new List <Price>
            {
                expectedFinalDigitPrice,
                expectedMainPrice
            };

            var expectedDraw = new Draw
            {
                SellUntilDate = new DateTime(2018, 1, 1),
                Ballots       = expectedBallots,
                Prices        = prices
            };

            RandomGeneratorMock
            .Setup(mock => mock.GenerateRandomNumbersAsync(It.IsAny <GenerationSettings>()))
            .ReturnsAsync(expectedRandomNumbers);

            // Act
            Draw result = await Lottery.DrawWinsAsync(expectedDraw);

            // Assert
            result.Should().NotBeNull();
            result.Should().Be(expectedDraw);

            // Sold and same final digit
            var firstBallot = expectedBallots.ElementAt(0);

            firstBallot.WonPrice.Should().Be(expectedFinalDigitPrice);

            // Winning ballot
            var secondBallot = expectedBallots.ElementAt(1);

            secondBallot.WonPrice.Should().Be(expectedMainPrice);

            // Diferrent final digit
            var thirdBallot = expectedBallots.ElementAt(2);

            thirdBallot.WonPrice.Should().BeNull();

            // Unsold and same final digit
            var fourthBalot = expectedBallots.ElementAt(3);

            fourthBalot.WonPrice.Should().BeNull();

            expectedDraw.DrawDate.Should().Be(expectedDrawDate);

            RandomGeneratorMock.VerifyAll();
        }
Exemplo n.º 4
0
        public async Task DrawWinsAsync_PicksRandomBallotRegistersAsMainWinner()
        {
            // Arrange
            int expectedRandomNumber  = 1;
            var expectedRandomNumbers = new List <int> {
                expectedRandomNumber
            };
            DateTime expectedDrawDate = new DateTime(2018, 01, 01);

            SystemTime.SetDateTime(expectedDrawDate);

            var winningBallot = new Ballot
            {
                Number   = 123456789,
                SellDate = new DateTime(2017, 12, 30)
            };

            var expectedBallots = new List <Ballot>
            {
                new Ballot {
                    Number   = 123456781,
                    SellDate = new DateTime(2017, 12, 30)
                },
                winningBallot,
                new Ballot {
                    Number   = 123456782,
                    SellDate = new DateTime(2017, 12, 30)
                },
            };

            var expectedMainPrice = new Price
            {
                PriceType = PriceType.Main,
                Amount    = 10000
            };

            var prices = new List <Price>
            {
                expectedMainPrice,
                new Price
                {
                    PriceType = PriceType.FinalDigit,
                    Amount    = 5
                }
            };

            var expectedDraw = new Draw
            {
                SellUntilDate = new DateTime(2018, 1, 1),
                Ballots       = expectedBallots,
                Prices        = prices
            };

            GenerationSettings actualGenerationSettings = null;

            RandomGeneratorMock
            .Setup(mock => mock.GenerateRandomNumbersAsync(It.IsAny <GenerationSettings>()))
            .Callback((GenerationSettings generationSettings) =>
            {
                actualGenerationSettings = generationSettings;
            })
            .ReturnsAsync(expectedRandomNumbers);

            // Act
            Draw result = await Lottery.DrawWinsAsync(expectedDraw);

            // Assert
            result.Should().NotBeNull();
            result.Should().Be(expectedDraw);

            winningBallot.Number.Should().Be(winningBallot.Number);
            winningBallot.SellDate.Should().Be(winningBallot.SellDate);
            winningBallot.WonPrice.Should().Be(expectedMainPrice);

            expectedDraw.DrawDate.Should().Be(expectedDrawDate);

            actualGenerationSettings.Should().NotBeNull();
            actualGenerationSettings.NumberOfIntegers.Should().Be(1);
            actualGenerationSettings.MinimalIntValue.Should().Be(0);
            actualGenerationSettings.MaximumIntValue.Should().Be(2);

            RandomGeneratorMock.VerifyAll();
        }