public async Task AddAsync_GivenAnime_ShouldAddAnime() { // Given var dbContext = InMemoryDbProvider.GetDbContext(); var repository = new SeasonRepository(dbContext); const string expectedName = "ExpectedName"; const int expectedYear = 2000; var season = new SeasonBuilder() .WithName(expectedName) .WithYear(expectedYear) .Build(); // When await repository.AddAsync(season); // Then var allSeasons = await dbContext.AnimeSeasons.ToListAsync(); var newSeason = await dbContext.AnimeSeasons.FirstOrDefaultAsync(); using (new AssertionScope()) { allSeasons.Should().ContainSingle(); newSeason.Should().NotBeNull(); newSeason.Name.Should().Be(expectedName); newSeason.Year.Should().Be(expectedYear); } }
public async Task AddAsync_GivenDuplicatedKeySeason_ShouldThrowException() { // Given var dbContext = InMemoryDbProvider.GetDbContext(); var repository = new SeasonRepository(dbContext); await repository.AddAsync(new SeasonBuilder().WithId(1).Build()); // When Func <Task> func = repository.Awaiting(x => x.AddAsync(new SeasonBuilder().WithId(1).Build())); // Then func.Should().Throw <Exception>(); }
public async Task AddAsync_GivenEmptySeason_ShouldAddAnime() { // Given var dbContext = InMemoryDbProvider.GetDbContext(); var repository = new SeasonRepository(dbContext); // When await repository.AddAsync(new SeasonBuilder().Build()); // Then var allSeasons = await dbContext.AnimeSeasons.ToListAsync(); allSeasons.Should().ContainSingle(); }