Exemple #1
0
        public async Task AddVisitsToUserShouldWorkCorrectly()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString()).Options;
            var db         = new ApplicationDbContext(options);
            var repository = new EfDeletableEntityRepository <Card>(db);
            var user       = new ApplicationUser();
            await repository.AddAsync(new Card()
            {
                User   = user,
                UserId = user.Id,
            });

            await repository.SaveChangesAsync();

            var service = new CardsService(repository, this.qrcodeService.Object, this.notificationsService.Object);

            var result = await service.AddVisitsToUser(user.Id, 12);

            var result2 = await service.AddVisitsToUser(user.Id, 12);

            Assert.Equal(12, result.Visits);
            Assert.Equal(12, result2.Visits);
        }
Exemple #2
0
        public async Task AddVisitsToUserShouldThrow(string userId)
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString()).Options;
            var db         = new ApplicationDbContext(options);
            var repository = new EfDeletableEntityRepository <Card>(db);
            var user       = new ApplicationUser();
            await repository.AddAsync(new Card()
            {
                User   = user,
                UserId = user.Id,
            });

            await repository.SaveChangesAsync();

            var service = new CardsService(repository, this.qrcodeService.Object, this.notificationsService.Object);

            await Assert.ThrowsAnyAsync <NullReferenceException>(async() => await service.AddVisitsToUser(userId, 12));
        }