public async Task GetAllRolesInSeason_GivenSeasonWithSingleAnimeWithSingleRole_ShouldReturnSingle()
        {
            // Given
            var animeId    = Guid.NewGuid();
            var dbContext  = InMemoryDbProvider.GetDbContext();
            var repository = new SeasonRoleRepository(dbContext);

            var role = new AnimeRoleBuilder()
                       .WithAnime(x => x.WithId(animeId))
                       .WithLanguage(x => x.WithLanguageId(LanguageId.Japanese))
                       .WithRoleType(x => x.WithId(AnimeRoleTypeId.Main))
                       .Build();

            await dbContext.AddAsync(role);

            await dbContext.SaveChangesAsync();

            // When
            var result = await repository.GetAllRolesInSeason(new List <Guid> {
                animeId
            }, false);

            // Then
            result.Should().ContainSingle();
        }
        public async Task GetAllRolesInAnimeAsync_GivenAnimeWithSingleRoleInLanguageOtherThanJapanese_ShouldReturnEmpty()
        {
            // Given
            const int animeMalId = 1;
            var       animeId    = Guid.NewGuid();
            var       dbContext  = InMemoryDbProvider.GetDbContext();
            var       repository = new AnimeRoleRepository(dbContext);

            var role = new AnimeRoleBuilder()
                       .WithAnime(
                x => x.WithMalId(animeMalId).WithId(animeId)
                )
                       .WithLanguage(x => x.WithLanguageId(LanguageId.Korean))
                       .Build();

            await dbContext.AddAsync(role);

            await dbContext.SaveChangesAsync();

            // When
            var result = await repository.GetAllRolesInAnimeAsync(animeId);

            // Then
            result.Should().BeEmpty();
        }
        public async Task AddAsync_GivenAnime_ShouldAddAnime()
        {
            // Given
            var dbContext  = InMemoryDbProvider.GetDbContext();
            var repository = new AnimeRoleRepository(dbContext);

            const string expectedAnimeTitle    = "expectedTitle";
            const string expectedSeiyuuName    = "expectedSeiyuuName";
            const string expectedcharacterName = "expectedCharacterName";
            const string expectedRoleTypeName  = "Main";
            var          expectedLanguage      = LanguageId.Japanese;

            var role = new AnimeRoleBuilder()
                       .WithAnime(x => x.WithTitle(expectedAnimeTitle))
                       .WithSeiyuu(x => x.WithName(expectedSeiyuuName))
                       .WithCharacter(x => x.WithName(expectedcharacterName))
                       .WithRoleType(x => x.WithDescription(expectedRoleTypeName))
                       .WithLanguage(x => x.WithLanguageId(expectedLanguage))
                       .Build();

            // When
            await repository.AddAsync(role);

            // Then
            var allroles = await dbContext.AnimeRoles.ToListAsync();

            var newRole = await dbContext.AnimeRoles
                          .Include(x => x.Anime)
                          .Include(x => x.Character)
                          .Include(x => x.Seiyuu)
                          .Include(x => x.Language)
                          .Include(x => x.RoleType)
                          .FirstOrDefaultAsync();

            using (new AssertionScope())
            {
                allroles.Should().ContainSingle();

                newRole.Should().NotBeNull();
                newRole.Anime.Should().NotBeNull();
                newRole.Anime.Title.Should().Be(expectedAnimeTitle);
                newRole.Character.Should().NotBeNull();
                newRole.Character.Name.Should().Be(expectedcharacterName);
                newRole.Seiyuu.Should().NotBeNull();
                newRole.Seiyuu.Name.Should().Be(expectedSeiyuuName);
                newRole.Language.Should().NotBeNull();
                newRole.Language.Id.Should().Be(expectedLanguage);
                newRole.RoleType.Should().NotBeNull();
                newRole.RoleType.Description.Should().Be(expectedRoleTypeName);
            }
        }
        public async Task AddAsync_GivenExistingRoleWithSameValues_ShouldAdd()
        {
            // Given
            var dbContext  = InMemoryDbProvider.GetDbContext();
            var repository = new AnimeRoleRepository(dbContext);

            var role1 = new AnimeRoleBuilder()
                        .Build();

            var role2 = new AnimeRoleBuilder()
                        .Build();

            await repository.AddAsync(role1);

            // When
            Func <Task> func = repository.Awaiting(x => x.AddAsync(role2));

            // Then
            func.Should().NotThrow <Exception>();
        }
Example #5
0
        public async Task GetAllSeiyuuRolesAsync_GivenAnimeWithSingleRole_ShouldReturnSingle()
        {
            // Given
            var seiyuuId   = Guid.NewGuid();
            var dbContext  = InMemoryDbProvider.GetDbContext();
            var repository = new SeiyuuRoleRepository(dbContext);

            var role = new AnimeRoleBuilder()
                       .WithSeiyuu(x => x.WithId(seiyuuId))
                       .WithLanguage(x => x.WithLanguageId(LanguageId.Japanese))
                       .Build();

            await dbContext.AddAsync(role);

            await dbContext.SaveChangesAsync();

            // When
            var result = await repository.GetAllSeiyuuRolesAsync(seiyuuId, false);

            // Then
            result.Should().ContainSingle();
        }
        public async Task GetAllRolesInSeason_GivenNoRolesInSeason_ShouldReturnEmpty()
        {
            // Given
            var animeId    = Guid.NewGuid();
            var dbContext  = InMemoryDbProvider.GetDbContext();
            var repository = new SeasonRoleRepository(dbContext);

            var anime = new AnimeRoleBuilder()
                        .WithAnime(x => x.WithId(Guid.NewGuid()))
                        .WithLanguage(x => x.WithLanguageId(LanguageId.Japanese))
                        .Build();

            await dbContext.AddAsync(anime);

            await dbContext.SaveChangesAsync();

            // When
            var result = await repository.GetAllRolesInSeason(new List <Guid> {
                animeId
            }, false);

            // Then
            result.Should().BeEmpty();
        }