コード例 #1
0
        public async Task FavoriteBookShouldReturnCorrectData()
        {
            this.InitializeMapper();
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options;
            var dbContext = new ApplicationDbContext(options);

            var repository = new EfDeletableEntityRepository <Favorite>(dbContext);
            var service    = new FavoriteService(repository);
            var userId     = "UserId";
            await service.AddToFavoriteAsync(userId, 1);

            await service.AddToFavoriteAsync(userId, 2);

            await service.AddToFavoriteAsync("UserIdDiffrent", 1);

            var actualResult   = service.FavoriteBook <FavoriteModel>(userId).ToList();
            var expectedResult = repository.All()
                                 .Where(x => x.UserId == userId)
                                 .ToList();

            for (int i = 0; i < actualResult.Count; i++)
            {
                Assert.Equal(expectedResult[i].UserId, actualResult[i].UserId);
            }
        }
コード例 #2
0
        public async Task AddShouldReturnCorrectCount()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options;
            var dbContext = new ApplicationDbContext(options);

            var repository   = new EfDeletableEntityRepository <Favorite>(dbContext);
            var service      = new FavoriteService(repository);
            var favoriteBook = repository.All().FirstOrDefault();

            await service.AddToFavoriteAsync("UserId", 1);

            Assert.Equal(1, repository.All().Count());
        }
コード例 #3
0
        public async Task AddShouldSaveCorrectData()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options;
            var dbContext = new ApplicationDbContext(options);

            var repository   = new EfDeletableEntityRepository <Favorite>(dbContext);
            var service      = new FavoriteService(repository);
            var favoriteBook = repository.All().FirstOrDefault();
            var userId       = "UserId";
            var bookId       = 1;
            await service.AddToFavoriteAsync(userId, bookId);

            var actualResult = repository.All().FirstOrDefault();

            Assert.Equal(userId, actualResult.UserId);
            Assert.Equal(bookId, actualResult.BookId);
        }