Exemplo n.º 1
0
        /// <summary>
        /// 汎用登録リポジトリ
        /// </summary>
        /// <param name="entity">登録する汎用Entity</param>
        /// <typeparam name="T">エンティティ</typeparam>
        /// <returns>処理件数</returns>
        public virtual async Task <int> Add <T>(T entity)
            where T : ModelBase
        {
            DbSet <T> dbSet = _context.Set <T>();

            // インスタンスの値を取得
            dbSet.Add(entity);

            return(await _context.SaveChangesAsync());
        }
Exemplo n.º 2
0
        public async Task AddWebPageToDbAsync()
        {
            // Arrange
            var options = new DbContextOptionsBuilder <WorkDbContext>()
                          .UseInMemoryDatabase(databaseName: "AddItemsToDb")
                          .Options;

            // Act
            using (var context = new WorkDbContext(options))
            {
                var sut = new WebPageService(context);
                await sut.AddWebPageAsync(new WebPage("Sample", "Sample", "Sample", "Sample", "Sample"));

                await context.SaveChangesAsync();
            }

            using (var context = new WorkDbContext(options))
            {
                Assert.AreEqual(1, context.WebPages.Count());
                Assert.AreEqual("Sample", context.WebPages.Single().Title);
            }
        }
Exemplo n.º 3
0
 public async Task <bool> SaveAsync()
 {
     return(await _context.SaveChangesAsync() >= 0);
 }