private static async Task InitTableAsync(MonsterDbContext context) { var monsterCategories = new[] { new MonsterCategory { Type = MonsterCategoryType.Slime, Name = "スライム系", }, new MonsterCategory { Type = MonsterCategoryType.Animal, Name = "けもの系", }, new MonsterCategory { Type = MonsterCategoryType.Fly, Name = "鳥系", }, }; var monsters = new[] { new Monster { Id = 1, Name = "スライム", CategoryType = MonsterCategoryType.Slime, }, new Monster { Id = 2, Name = "ドラキー", CategoryType = MonsterCategoryType.Fly, }, }; context.MonsterCategories.AddRange(monsterCategories); context.Monsters.AddRange(monsters); await context.SaveChangesAsync(); }
public async Task モンスターカテゴリを追加して取得できる() { // Arrange await InitAsync(); var expected = _monsterCategories.Values.OrderBy(category => category.Id); // Act // Assert // カテゴリを追加(追加した件数が正しい) _context.MonsterCategories.AddRange(expected); var rows = await _context.SaveChangesAsync(); Assert.Equal(expected.Count(), rows); // 追加したカテゴリを取得できる var actual = await _context.MonsterCategories .OrderBy(category => category.Id) .ToListAsync(); Assert.Equal(expected, actual, _monsterCategoryComparer); }