Exemple #1
0
        public async Task <LuckyDrawResult> StartSingleLuckyDrawResult()
        {
            LuckyDrawResult result = await LuckyDrawService.GetNextLuckyDrawAsync();

            await JSRuntime.InvokeVoidAsync("setSingleWinner", "winnerWwid", "winnerName", result.Winner.WWID, result.Winner.Name);

            return(result);
        }
Exemple #2
0
        public async void GetNextLuckyDrawAsync()
        {
            // Setup
            var options = new DbContextOptionsBuilder <LuckyDrawContext>()
                          .UseInMemoryDatabase(databaseName: "GetNextPrizeAsyncTest")
                          .Options;

            LuckyDrawResult LuckyDrawResult = new LuckyDrawResult();

            // Arrange
            using (var context = new LuckyDrawContext(options))
            {
                await context.Prizes.AddRangeAsync(Prizes);

                await context.Employees.AddRangeAsync(Employees);

                await context.SaveChangesAsync();

                var service = new LuckyDrawService(context);
                LuckyDrawResult = await service.GetNextLuckyDrawAsync(10);
            }

            // Assert
            using (var context = new LuckyDrawContext(options))
            {
                var service         = new LuckyDrawService(context);
                var existingWinners = await service.GetExistingWinnerAsync();

                var potentialWinners = await service.GetPotentialWinnersAsync(existingWinners, 10);

                Assert.DoesNotContain(LuckyDrawResult.Winner.WWID, potentialWinners.Select(s => s.WWID));
                Assert.Equal(8, potentialWinners.Count);
                Assert.Equal(LuckyDrawResult.Winner.WWID, context.Prizes.First(f => f.PrizeID == LuckyDrawResult.Prize.PrizeID).WWID);
                Assert.Equal(3, context.Prizes.Where(w => w.WWID == null).Count());
            }
        }