示例#1
0
        public async void GetPotentialWinnersAsyncTest()
        {
            // Setup
            var options = new DbContextOptionsBuilder <LuckyDrawContext>()
                          .UseInMemoryDatabase(databaseName: "GetPotentialWinnersAsyncTest")
                          .Options;

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

                await context.Employees.AddRangeAsync(Employees);

                await context.SaveChangesAsync();
            }

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

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

                Assert.Equal(5, potentialWinners.Count);
                Assert.DoesNotContain("Employee1", potentialWinners.Select(s => s.WWID));
            }
        }
示例#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());
            }
        }