public void DrawFreeTicketForUser(User user)
        {
            var random = new Random(); // should be injected as service to make class testable
            IWinChanceCalculator calculator = _calculatorFactory.GetCalculatorForUser(user);
            WinChance chance = calculator.CalculateWinChance(user);
            Draw draw = new Draw(random.Next(100));

            if (chance.IsSatisfiedBy(draw))
            {
                user.FreeTicketsCount++;
                DomainEventBus.Current.Raise(new FreeTicketGranted(user.Id, user.FreeTicketsCount));
            }
        }
示例#2
0
 internal bool IsSatisfiedBy(Draw draw)
 {
     return draw.Value < PercentageOfWin;
 }