public async Task AddAsync_GivenEmptyAnime_ShouldAddAnime() { // Given var dbContext = InMemoryDbProvider.GetDbContext(); var repository = new AnimeRepository(dbContext); // When await repository.AddAsync(new AnimeBuilder().Build()); // Then var allAnime = await dbContext.Animes.ToListAsync(); allAnime.Should().ContainSingle(); }
public async Task AddAsync_GivenAnime_ShouldAddAnime() { // Given var dbContext = InMemoryDbProvider.GetDbContext(); var repository = new AnimeRepository(dbContext); const string expectedTitle = "ExpectedTitle"; const string expectedImageUrl = "ExpectedImageUrl"; const string expectedJapaneseTitle = "期待される日本語タイトル"; const string expectedTitleSynonyms = "expectedTitleSynonyms"; const string expectedAbout = "ExpectedAbout"; const string expectedStatus = "ExpectedStatus"; var expectedType = AnimeTypeId.TV; const long expectedMalId = 1; var anime = new AnimeBuilder() .WithTitle(expectedTitle) .WithImageUrl(expectedImageUrl) .WithMalId(expectedMalId) .WithJapaneseTitle(expectedJapaneseTitle) .WithTitleSynonyms(expectedTitleSynonyms) .WithAbout(expectedAbout) .WithAnimeType(at => at.WithId(expectedType)) .WithAnimeStatus(at => at.WithName(expectedStatus)) .Build(); // When await repository.AddAsync(anime); // Then var allAnime = await dbContext.Animes.ToListAsync(); var newAnime = await dbContext.Animes.FirstOrDefaultAsync(); using (new AssertionScope()) { allAnime.Should().ContainSingle(); newAnime.Should().NotBeNull(); newAnime.Title.Should().Be(expectedTitle); newAnime.ImageUrl.Should().Be(expectedImageUrl); newAnime.MalId.Should().Be(expectedMalId); newAnime.KanjiTitle.Should().Be(expectedJapaneseTitle); newAnime.TitleSynonyms.Should().Be(expectedTitleSynonyms); newAnime.About.Should().Be(expectedAbout); newAnime.Type.Id.Should().Be(expectedType); newAnime.Status.Description.Should().Be(expectedStatus); } }
public async Task AddAsync_GivenDuplicatedKeyAnime_ShouldThrowException() { // Given var id = Guid.NewGuid(); var dbContext = InMemoryDbProvider.GetDbContext(); var repository = new AnimeRepository(dbContext); await repository.AddAsync(new AnimeBuilder().WithId(id).Build()); // When Func <Task> func = repository.Awaiting(x => x.AddAsync(new AnimeBuilder().WithId(id).Build())); // Then func.Should().Throw <Exception>(); }