Пример #1
0
        public void TestPiterTicketLucky(int ticketNumber, bool isLucky)
        {
            bool          result;
            Ticket        ticket        = new Ticket(ticketNumber);
            TicketCounter ticketCounter = new PiterTicketCounter(TicketGenerator.Build(0, 1));

            result = ticketCounter.IsLucky(ticket);

            Assert.Equal(result, isLucky);
        }
Пример #2
0
        public void TestPiterTicketLuckyCountCorrect()
        {
            int             minRange        = 0;
            int             maxRange        = 999999;
            TicketGenerator ticketGenerator = TicketGenerator.Build(minRange, maxRange);
            TicketCounter   ticketCounter   = new PiterTicketCounter(ticketGenerator);
            int             expectedAmount  = 55252;

            int amount = ticketCounter.CountLuckyTickets();

            Assert.Equal(expectedAmount, amount);
        }
        public void GeneratorMakesTheCorrectAmountOfTickets(int minRange, int maxRange, int ticketsAmount)
        {
            TicketGenerator ticketGenerator = TicketGenerator.Build(minRange, maxRange);
            int             count           = 0;

            foreach (var item in ticketGenerator)
            {
                count++;
            }

            Assert.Equal(ticketsAmount, count);
        }
        public void Run()
        {
            string message = string.Empty;

            try
            {
                TicketGeneratorDTO generatorDTO    = _ticketView.GetTicketGenerator();
                TicketGenerator    ticketGenerator = TicketGenerator.Build(generatorDTO);
                TicketCounterMode  mode            = GetTicketCounterMode();
                TicketCounter      ticketCounter   = TicketCounterFactory.Build(mode, ticketGenerator);
                int luckyTickets = ticketCounter.CountLuckyTickets();

                message = string.Format("Lucky tickets count: {0}", luckyTickets);
                Log.Information("LuckyTickets count: {luckyTickets}", luckyTickets);
            }
            catch (FormatException ex)
            {
                _ticketView.DisplayInstruction();
                Log.Error(ex, "Exception thrown");
            }
            catch (ArgumentOutOfRangeException ex)
            {
                _ticketView.DisplayInstruction();
                Log.Error(ex, "Exception thrown");
            }
            catch (OverflowException ex)
            {
                _ticketView.DisplayInstruction();
                Log.Error(ex, "Exception thrown");
            }
            catch (FileNotFoundException ex)
            {
                _ticketView.DisplayInstruction();
                Log.Error(ex, "Exception thrown");
            }

            _ticketView.Display(message);
        }
 public void BuildGeneratorWithWrongRangeThrowsException(int minRange, int maxRange)
 {
     Assert.Throws <ArgumentOutOfRangeException>(
         () => TicketGenerator.Build(minRange, maxRange));
 }