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(); }
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(); }
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(); }