Esempio n. 1
0
        public async Task WhenUserBuysTicketsShouldNotCrashAsync()
        {
            await using (var context = NewContext())
            {
                var userService        = new UserService(context, CacheClient);
                var transactionService = new TransactionService(userService);
                var schedulerService   = new SchedulerService(
                    new Mock <MikiApp>().Object, CacheClient, null);
                var discordClient  = new Mock <IDiscordClient>();
                var lotteryService = new LotteryService(
                    CacheClient, schedulerService, transactionService, new LotteryEventHandler());

                await lotteryService.PurchaseEntriesAsync(2L, 1);
            }

            await using (var context = NewContext())
            {
                var userService        = new UserService(context, CacheClient);
                var transactionService = new TransactionService(userService);
                var schedulerService   = new SchedulerService(
                    new Mock <MikiApp>().Object, CacheClient, null);
                var lotteryService = new LotteryService(
                    CacheClient, schedulerService, transactionService, new LotteryEventHandler());

                var user = await userService.GetUserAsync(2L);

                var userEntries = await lotteryService.GetEntriesForUserAsync(2L);

                Assert.True(userEntries.IsValid);
                Assert.Equal(0, user.Currency);
                Assert.Equal(1, userEntries.Unwrap().TicketCount);
            }
        }
        public void Should_Return_200_OK_When_Valid_BallCounts_Are_Given(int ballCount)
        {
            //Arrange
            var LotteryService = new LotteryService();
            var controller     = new LotteryController(LotteryService);

            //Act
            var result = controller.GenerateLotteryNumbers(ballCount);

            //Assert
            ((ObjectResult)result).StatusCode.Should().Be((int)HttpStatusCode.OK);
        }
        public void Should_Return_400_BadRequest_When_BallCount_Is_Zero()
        {
            //Arrange
            int ballCount      = 0;
            var LotteryService = new LotteryService();
            var controller     = new LotteryController(LotteryService);

            //Act
            var result = controller.GenerateLotteryNumbers(ballCount);

            //Assert
            ((ObjectResult)result).StatusCode.Should().Be((int)HttpStatusCode.BadRequest);
        }
        //Additional things to add later:
        //Unit tests for lottery number generation
        //option for user to choose with/without bonus ball (functionality for bonus ball already exists)

        static void Main(string[] args)
        {
            Console.WriteLine("Welcome to the lottery number generator. Press any key to generate lottery numbers.");
            Console.ReadLine();
            var lotteryService = new LotteryService();
            var numbers        = lotteryService.GenerateLotteryNumbers(false);

            Console.WriteLine("Your numbers");
            foreach (var number in numbers)
            {
                PresentNumber(number);
            }

            Console.WriteLine("Press any key to exit");
            Console.ReadLine();
            Environment.Exit(0);
        }
        public void CreateLotery_WithCorrectArgs_CreatesLottery()
        {
            var optBuilder = new DbContextOptionsBuilder();

            optBuilder.UseSqlServer("Server=192.168.1.106,1433;Database=CoworkersTotalizator_test;User Id=sa;Password=password1;");

            var context = new CoworkersTotalizatorContext(optBuilder.Options);

            context.Database.EnsureDeleted();
            context.Database.Migrate();

            var ls = new LotteryService(context, null, new CoworkerBidCoeficientSerice());

            context.Users.Add(new User
            {
                Name    = "Alex",
                IsAdmin = true
            });

            context.Coworkers.Add(new Coworker
            {
                Name = "coworker1",
                PresenceCoeficient = 0.9,
            });

            context.SaveChanges();

            ls.Create(new LotteryDto
            {
                Name        = "Lottery1",
                Date        = DateTime.Now,
                CoworkerIds = new[] { 1 }
            });

            Assert.Equal(1, context.Users.First().UserBids.First().CoworkerId);
        }
Esempio n. 6
0
 public LotteryServiceTest()
 {
     content = @"<html>
             <head>
             <title>Resultado da Mega-sena</title>
             <STYLE>
             TD {
             FONT-FAMILY: Arial;
             FONT-SIZE: 10pt;
             HEIGHT: 15pt;
             TEXT-ALIGN: center
             }
             </STYLE>
             </head>
             <body>
             <p><strong><big><big><font face=""Arial"" color=""#004080"">Resultado da Mega-sena</font></big></big></strong></p>
             <p><img src=""t2.gif"">
             </p>
             <table border=""0"" cellspacing=""1"" cellpadding=""0"" width=""1810"">
             <tr>
             <th width=""50""  height=""20"" bgcolor=""#7BA8D9""><small><font face=""Arial"" color=""#FFFFFF"">Concurso</font></small></th>
             <th width=""100"" height=""20"" bgcolor=""#7BA8D9""><small><font face=""Arial"" color=""#FFFFFF"">Data Sorteio</font></small></th>
             <th width=""80""  height=""20"" bgcolor=""#7BA8D9""><small><font face=""Arial"" color=""#FFFFFF"">1ª Dezena</font></small></th>
             <th width=""80""  height=""20"" bgcolor=""#7BA8D9""><small><font face=""Arial"" color=""#FFFFFF"">2ª Dezena</font></small></th>
             <th width=""80""  height=""20"" bgcolor=""#7BA8D9""><small><font face=""Arial"" color=""#FFFFFF"">3ª Dezena</font></small></th>
             <th width=""80""  height=""20"" bgcolor=""#7BA8D9""><small><font face=""Arial"" color=""#FFFFFF"">4ª Dezena</font></small></th>
             <th width=""80""  height=""20"" bgcolor=""#7BA8D9""><small><font face=""Arial"" color=""#FFFFFF"">5ª Dezena</font></small></th>
             <th width=""80""  height=""20"" bgcolor=""#7BA8D9""><small><font face=""Arial"" color=""#FFFFFF"">6ª Dezena</font></small></th>
             <th width=""120""  height=""20"" bgcolor=""#7BA8D9""><small><font face=""Arial"" color=""#FFFFFF"">Arrecadacao_Total</font></small></th>
             <th width=""95"" height=""20"" bgcolor=""#7BA8D9""><small><font face=""Arial"" color=""#FFFFFF"">Ganhadores_Sena</font></small></th>
             <th width=""95"" height=""20"" bgcolor=""#7BA8D9""><small><font face=""Arial"" color=""#FFFFFF"">Cidade</font></small></th>
             <th width=""95"" height=""20"" bgcolor=""#7BA8D9""><small><font face=""Arial"" color=""#FFFFFF"">UF</font></small></th>
             <th width=""120""  height=""20"" bgcolor=""#7BA8D9""><small><font face=""Arial"" color=""#FFFFFF"">Rateio_Sena</font></small></th>
             <th width=""131"" height=""20"" bgcolor=""#7BA8D9""><small><font face=""Arial"" color=""#FFFFFF"">Ganhadores_Quina</font></small></th>
             <th width=""120""  height=""20"" bgcolor=""#7BA8D9""><small><font face=""Arial"" color=""#FFFFFF"">Rateio_Quina</font></small></th>
             <th width=""131""  height=""20"" bgcolor=""#7BA8D9""><small><font face=""Arial"" color=""#FFFFFF"">Ganhadores_Quadra</font></small></th>
             <th width=""120""  height=""20"" bgcolor=""#7BA8D9""><small><font face=""Arial"" color=""#FFFFFF"">Rateio_Quadra</font></small></th>
             <th width=""70""  height=""20"" bgcolor=""#7BA8D9""><small><font face=""Arial"" color=""#FFFFFF"">Acumulado</font></small></th>
             <th width=""120""  height=""20"" bgcolor=""#7BA8D9""><small><font face=""Arial"" color=""#FFFFFF"">Valor_Acumulado</font></small></th>
             <th width=""120""  height=""20"" bgcolor=""#7BA8D9""><small><font face=""Arial"" color=""#FFFFFF"">Estimativa_Prêmio</font></small></th>
             <th width=""120""  height=""20"" bgcolor=""#7BA8D9""><small><font face=""Arial"" color=""#FFFFFF"">Acumulado_Mega_da_Virada</font></small></th>
             </tr>
             <tr>
             <td rowspan=""1"">1</td>
             <td rowspan=""1"">11/03/1996</td>
             <td rowspan=""1"">41</td>
             <td rowspan=""1"">05</td>
             <td rowspan=""1"">04</td>
             <td rowspan=""1"">52</td>
             <td rowspan=""1"">30</td>
             <td rowspan=""1"">33</td>
             <td rowspan=""1"">0,00</td>
             <td rowspan=""1"">0</td>
             <td rowspan=""1"">&nbsp</td><td rowspan=""1"">&nbsp</td>
             <td rowspan=""1"">0,00</td>
             <td rowspan=""1"">17</td>
             <td rowspan=""1"">39.158,92</td>
             <td rowspan=""1"">2016</td>
             <td rowspan=""1"">330,21</td>
             <td rowspan=""1"">SIM</td>
             <td rowspan=""1"">1.714.650,23</td>
             <td rowspan=""1"">0,00</td>
             <td rowspan=""1"">0,00</td>
             </tr>
             </table>
             </body>
             </html>";
     returnListOfListOfStrings = new List <List <string> >
     {
         new List <string>
         {
             "2146",
             "27/04/2019",
             "39",
             "42",
             "16",
             "18",
             "44",
             "31",
             "150.176.040,00",
             "0",
             "&nbsp",
             "&nbsp",
             "0,00",
             "283",
             "30.594,81",
             "15338",
             "806,43",
             "SIM",
             "107.627.872,22",
             "125.000.000,00",
             "26.248.210,83"
         }
     };
     appSettings = new AppSettings
     {
         TempFilePath = @"/../../../",
         Database     = new Database
         {
             Name = string.Empty,
             Url  = string.Empty
         },
         Lotteries = new List <LotterySetting>
         {
             new LotterySetting
             {
                 Columns      = 21,
                 HtmlFileName = "anyFile.htm",
                 Name         = "MegaSena",
                 WebService   = string.Empty,
                 ZipFileName  = "MegaSena.zip"
             },
             new LotterySetting
             {
                 Columns      = 0,
                 HtmlFileName = "error.txt",
                 Name         = "DuplaSena",
                 WebService   = string.Empty,
                 ZipFileName  = string.Empty
             }
         }
     };
     _mockLogger      = new Mock <ILogger <ILotteryService> >();
     _mockHtmlService = new Mock <IHtmlHandlerService>();
     _lotteryService  = new LotteryService(_mockHtmlService.Object, appSettings, _mockLogger.Object);
 }
Esempio n. 7
0
        public ApiResult <IndexLotteryInfoResDto> GetLotteryInfo(int lType)
        {
            var lotteryService = new LotteryService();

            return(lotteryService.GetLotteryInfoByNewsLType(lType));
        }
Esempio n. 8
0
        public LotterySystemViewModel(IDispatcherService dispatcherService, string functionTag,
                                      IDialogService dialogService, ScoreInfoService scoreInfoService, LotteryService lotteryService) : base(dispatcherService, functionTag)
        {
            _dialogService    = dialogService;
            _scoreInfoService = scoreInfoService;
            _lotteryService   = lotteryService;

            Timer1 = new Timer()
            {
                AutoReset = true, Interval = LotteryInterval * 1000
            };
            Timer1.Elapsed += OnStartLottery;

            _currentViewModelObserver = new PropertyObserver <LotterySystemViewModel>(this);
            _currentViewModelObserver.RegisterHandler(currentViewModel => currentViewModel.LotteryInterval,
                                                      (vm) =>
            {
                if (LotteryInterval > 0)
                {
                    Timer1.Interval = LotteryInterval * 1000;
                    Timer1.Enabled  = true;
                }
            });

            DataGridItemChanged = new RelayCommand <DataGridItemChangedEventArgs>(OnDataGridItemChanged);

            RefreshList = new RelayCommand(PrivateRefreshList);

            RemoveItem = new RelayCommand(() =>
            {
                if (_dialogService.ShowOKCancel("确定删除选中数据吗?"))
                {
                    _ = _lotteryService.RemoveAsync(SelectedItem);
                    LotteryItems.Remove(SelectedItem);
                }
            }, () => { return(SelectedItem != null); });

            RemoveAll = new RelayCommand(() =>
            {
                if (_dialogService.ShowOKCancel("确定删除所有数据吗?"))
                {
                    _            = _lotteryService.RemoveAllAsync();
                    LotteryItems = null;
                }
            }, () => { return(LotteryItems != null); });

            AddData = new RelayCommand(() =>
            {
                var dto = new LotteryDto()
                {
                    LotteryName = LotteryName,
                    Content     = Content,
                    Amount      = Amount,
                    Quality     = Quality,
                    LotteryType = LotteryType
                };
                _ = _lotteryService.AddAsync(dto);
                LotteryItems.Add(dto);
            });

            AddAvailableVariables();

            PrivateRefreshList();
        }
Esempio n. 9
0
 public LotteryController(LotteryService service)
 {
     _service = service;
 }
 public LotteryController(
     LotteryService lotteryService)
 {
     this._lotteryService = lotteryService;
 }