Пример #1
0
        public async Task GetOrderedPageAsync_GivenMultipleAnime_ShouldReturnAll()
        {
            // Given
            var dbContext  = InMemoryDbProvider.GetDbContext();
            var repository = new AnimeRepository(dbContext);
            var anime1     = new AnimeBuilder().WithTitle("Test1").Build();
            var anime2     = new AnimeBuilder().WithTitle("Test2").Build();
            var anime3     = new AnimeBuilder().WithTitle("Test3").Build();

            await dbContext.Animes.AddAsync(anime1);

            await dbContext.Animes.AddAsync(anime2);

            await dbContext.Animes.AddAsync(anime3);

            await dbContext.SaveChangesAsync();

            // When
            var result = await repository.GetOrderedPageByAsync(x => true);

            // Then
            using (new AssertionScope())
            {
                result.TotalCount.Should().Be(3);
                result.Results.Should().HaveCount(3);
            }
        }
Пример #2
0
        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();
        }
Пример #3
0
        public async Task HandleAsync_GivenNotExistingSeiyuuExceptionFromJikan_ShouldSkipAndNotInsert()
        {
            // Given
            var       dbContext           = InMemoryDbProvider.GetDbContext();
            var       jikanServiceBuilder = new JikanServiceBuilder().WithGetPersonThrowing();
            const int startingMalId       = 1;
            var       s3Service           = new S3ServiceStub(startingMalId);

            var anime = new SeiyuuBuilder()
                        .WithMalId(startingMalId)
                        .Build();

            await dbContext.AddAsync(anime);

            await dbContext.SaveChangesAsync();

            var handler = CreateHandler(dbContext, jikanServiceBuilder.Build(), s3Service, 1);

            // When
            var action = handler.Awaiting(x => x.HandleAsync());

            // Then
            using (new AssertionScope())
            {
                await action.Should().ThrowExactlyAsync <JikanRequestException>();

                dbContext.Seiyuus.Should().ContainSingle();
            }
            jikanServiceBuilder.JikanClient.Verify(x => x.GetPersonAsync(startingMalId + 1), Times.Once);
        }
Пример #4
0
        public async Task UpdateAsync_GivenExistingCharacter_ShouldUpdate()
        {
            // Given
            var dbContext  = InMemoryDbProvider.GetDbContext();
            var repository = new CharacterRepository(dbContext);
            var character  = new CharacterBuilder().WithName("Test").Build();

            await dbContext.AnimeCharacters.AddAsync(character);

            await dbContext.SaveChangesAsync();

            character.Name = "Updated";

            // When
            await repository.UpdateAsync(character);

            // Then
            var allCharacters = await dbContext.AnimeCharacters.ToListAsync();

            using (new AssertionScope())
            {
                var updatedCharacter = allCharacters.SingleOrDefault();
                updatedCharacter.Should().NotBeNull();
                updatedCharacter.Name.Should().Be("Updated");
                updatedCharacter.ModificationDate.Should().HaveDay(DateTime.UtcNow.Day);
            }
        }
Пример #5
0
        public async Task GetAllRolesInSeason_GivenSeasonWithSingleAnimeWithMultipleRoles_ShouldReturnMultiple()
        {
            // Given
            var animeId    = Guid.NewGuid();
            var dbContext  = InMemoryDbProvider.GetDbContext();
            var repository = new SeasonRoleRepository(dbContext);

            var japanese = new LanguageBuilder().WithLanguageId(LanguageId.Japanese).Build();
            var anime    = new AnimeBuilder().WithId(animeId).Build();

            anime.Role = new List <AnimeRole>
            {
                new AnimeRoleBuilder().WithLanguage(japanese).Build(),
                new AnimeRoleBuilder().WithLanguage(japanese).Build(),
                new AnimeRoleBuilder().WithLanguage(japanese).Build(),
                new AnimeRoleBuilder().WithLanguage(japanese).Build(),
                new AnimeRoleBuilder().WithLanguage(japanese).Build(),
            };

            await dbContext.AddAsync(anime);

            await dbContext.SaveChangesAsync();

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

            // Then
            result.Should().HaveCount(5);
        }
Пример #6
0
        public async Task GetAllSeiyuuRolesAsync_GivenMultipleRoles_ShouldReturnMultiple()
        {
            // Given
            var seiyuuId   = Guid.NewGuid();
            var dbContext  = InMemoryDbProvider.GetDbContext();
            var repository = new SeiyuuRoleRepository(dbContext);

            var japanese = new LanguageBuilder().WithLanguageId(LanguageId.Japanese).Build();
            var seiyuu   = new SeiyuuBuilder().WithId(seiyuuId).Build();

            seiyuu.Role = new List <AnimeRole>
            {
                new AnimeRoleBuilder().WithLanguage(japanese).Build(),
                new AnimeRoleBuilder().WithLanguage(japanese).Build(),
                new AnimeRoleBuilder().WithLanguage(japanese).Build(),
                new AnimeRoleBuilder().WithLanguage(japanese).Build(),
                new AnimeRoleBuilder().WithLanguage(japanese).Build(),
            };

            await dbContext.AddAsync(seiyuu);

            await dbContext.SaveChangesAsync();

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

            // Then
            result.Should().HaveCount(5);
        }
Пример #7
0
        public async Task GetPageAsync_GivenMultipleAnime_ShouldReturnAll()
        {
            // Given
            var dbContext  = InMemoryDbProvider.GetDbContext();
            var repository = new CharacterRepository(dbContext);
            var character1 = new CharacterBuilder().WithName("Test1").Build();
            var character2 = new CharacterBuilder().WithName("Test2").Build();
            var character3 = new CharacterBuilder().WithName("Test3").Build();

            await dbContext.AnimeCharacters.AddAsync(character1);

            await dbContext.AnimeCharacters.AddAsync(character2);

            await dbContext.AnimeCharacters.AddAsync(character3);

            await dbContext.SaveChangesAsync();

            // When
            var result = await repository.GetPageAsync();

            // Then
            using (new AssertionScope())
            {
                result.TotalCount.Should().Be(3);
                result.Results.Should().HaveCount(3);
            }
        }
        public async Task HandleAsync_GivenExceptionFromJikan_ShouldNotAddNewSeason()
        {
            // Given
            var dbContext = InMemoryDbProvider.GetDbContext();

            var returnedLastSeason = new SeasonArchive
            {
                Season = new List <Seasons> {
                    Seasons.Winter
                },
                Year = 2000
            };

            var jikanServiceBuilder = new JikanServiceBuilder().WithGetSeasonArchiveThrowing();
            var handler             = CreateHandler(dbContext, jikanServiceBuilder.Build());

            // When
            var action = handler.Awaiting(x => x.HandleAsync());

            // Then
            using (new AssertionScope())
            {
                await action.Should().ThrowExactlyAsync <JikanRequestException>();

                dbContext.AnimeSeasons.Should().BeEmpty();
            }
        }
        public async Task HandleAsync_GivenAlreadyExistingSeason_ShouldNotAddNewSeason()
        {
            // Given
            var dbContext = InMemoryDbProvider.GetDbContext();

            var returnedLastSeason = new SeasonArchive
            {
                Season = new List <Seasons> {
                    Seasons.Winter
                },
                Year = 2000
            };

            var season = new SeasonBuilder()
                         .WithId(1)
                         .WithYear(2000)
                         .WithName("Winter")
                         .Build();

            await dbContext.AddAsync(season);

            await dbContext.SaveChangesAsync();

            var jikanServiceBuilder = new JikanServiceBuilder().WithLastSeasonArchiveReturned(returnedLastSeason);
            var handler             = CreateHandler(dbContext, jikanServiceBuilder.Build());

            // When
            await handler.HandleAsync();

            // Then
            dbContext.AnimeSeasons.Should().ContainSingle();
        }
        public async Task HandleAsync_GivenMultipleSeasonsInYear_ShouldAddNewer()
        {
            // Given
            var dbContext = InMemoryDbProvider.GetDbContext();

            var returnedLastSeason = new SeasonArchive
            {
                Season = new List <Seasons> {
                    Seasons.Winter, Seasons.Spring
                },
                Year = 2000
            };

            var jikanServiceBuilder = new JikanServiceBuilder().WithLastSeasonArchiveReturned(returnedLastSeason);
            var handler             = CreateHandler(dbContext, jikanServiceBuilder.Build());

            // When
            await handler.HandleAsync();

            // Then
            using (new AssertionScope())
            {
                dbContext.AnimeSeasons.Should().ContainSingle();
                dbContext.AnimeSeasons.Single().Name.Should().Be("Spring");
                dbContext.AnimeSeasons.Single().Year.Should().Be(2000);
            }
        }
        public async Task HandleAsync_GivenMultipleSeasonsInYearAlreadyExisting_ShouldNotAddNewSeason()
        {
            // Given
            var dbContext = InMemoryDbProvider.GetDbContext();

            var returnedLastSeason = new SeasonArchive
            {
                Season = new List <Seasons> {
                    Seasons.Winter, Seasons.Spring, Seasons.Summer, Seasons.Fall
                },
                Year = 2000
            };

            var seasons = new List <Domain.Entities.AnimeSeason>
            {
                new SeasonBuilder().WithId(10).WithYear(2000).WithName("Winter").Build(),
                new SeasonBuilder().WithId(11).WithYear(2000).WithName("Spring").Build(),
                new SeasonBuilder().WithId(13).WithYear(2000).WithName("Summer").Build(),
                new SeasonBuilder().WithId(14).WithYear(2000).WithName("Fall").Build(),
            };

            await dbContext.AddRangeAsync(seasons);

            await dbContext.SaveChangesAsync();

            var jikanServiceBuilder = new JikanServiceBuilder().WithLastSeasonArchiveReturned(returnedLastSeason);
            var handler             = CreateHandler(dbContext, jikanServiceBuilder.Build());

            // When
            await handler.HandleAsync();

            // Then
            dbContext.AnimeSeasons.Should().HaveCount(4);
        }
        public async Task HandleAsync_GivenNullResponseFromJikan_ShouldNotThrowAndCallJikan()
        {
            // Given
            const int malId               = 1;
            var       dbContext           = InMemoryDbProvider.GetDbContext();
            var       jikanServiceBuilder = new JikanServiceBuilder().WithCharacterReturned(null);

            var character = new CharacterBuilder()
                            .WithMalId(malId)
                            .Build();

            await dbContext.AddAsync(character);

            await dbContext.SaveChangesAsync();

            var handler = CreateHandler(dbContext, jikanServiceBuilder.Build());

            var command = new UpdateCharacterMessage
            {
                Id    = Guid.NewGuid(),
                MalId = malId
            };

            // When
            var action = handler.Awaiting(x => x.HandleAsync(command));

            // Then
            using (new AssertionScope())
            {
                await action.Should().NotThrowAsync();

                jikanServiceBuilder.JikanClient.Verify(x => x.GetCharacter(malId), Times.Once);
            }
        }
Пример #13
0
        public async Task GetOrderedPageByPopularityAsync_GivenMultipleWithDifferentPopularityWithPagesize_ShouldReturnOnlyOnePageByPopularity()
        {
            // Given
            const int pageSize = 2;

            var dbContext  = InMemoryDbProvider.GetDbContext();
            var repository = new AnimeRepository(dbContext);
            var anime1     = new AnimeBuilder().WithTitle("Test1").WithPopularity(10).Build();
            var anime2     = new AnimeBuilder().WithTitle("Test2").WithPopularity(50).Build();
            var anime3     = new AnimeBuilder().WithTitle("Test3").WithPopularity(30).Build();

            await dbContext.Animes.AddAsync(anime1);

            await dbContext.Animes.AddAsync(anime2);

            await dbContext.Animes.AddAsync(anime3);

            await dbContext.SaveChangesAsync();

            // When
            var result = await repository.GetOrderedPageByPopularityAsync(x => true, 0, pageSize);

            // Then// Then
            using (new AssertionScope())
            {
                result.TotalCount.Should().Be(3);
                result.Results.Should().HaveCount(2);
                result.PageSize.Should().Be(pageSize);

                result.Results.First().Title.Should().Be("Test2");
                result.Results.First().Popularity.Should().Be(50);
                result.Results.Last().Title.Should().Be("Test3");
                result.Results.Last().Popularity.Should().Be(30);
            }
        }
Пример #14
0
        public async Task GetOrderedPageAsync_GivenMultipleWithPredicate_ShouldReturnOnlyOnePage()
        {
            // Given
            const int pageSize = 2;

            var dbContext  = InMemoryDbProvider.GetDbContext();
            var repository = new AnimeRepository(dbContext);
            var anime1     = new AnimeBuilder().WithTitle("Test1").Build();
            var anime2     = new AnimeBuilder().WithTitle("Test2").Build();
            var anime3     = new AnimeBuilder().WithTitle("Test3").Build();

            await dbContext.Animes.AddAsync(anime1);

            await dbContext.Animes.AddAsync(anime2);

            await dbContext.Animes.AddAsync(anime3);

            await dbContext.SaveChangesAsync();

            // When
            var result = await repository.GetOrderedPageByAsync(x => x.Title.EndsWith("1"), 0, pageSize);

            // Then// Then
            using (new AssertionScope())
            {
                result.TotalCount.Should().Be(1);
                result.Results.Should().HaveCount(1);
                result.PageSize.Should().Be(pageSize);
            }
        }
        public async Task AddAsync_GivenBlacklistedId_ShouldAdd()
        {
            // Given
            var dbContext  = InMemoryDbProvider.GetDbContext();
            var repository = new BlacklistedIdRepository(dbContext);

            const string expectedEntityType = "ExpectedEntityType";
            const string expectedReason     = "ExpectedReason";
            const long   expectedMalId      = 1;

            var blacklistedId = new BlacklistedIdBuilder()
                                .WithEntityType(expectedEntityType)
                                .WithReason(expectedReason)
                                .WithMalId(expectedMalId)
                                .Build();

            // When
            await repository.AddAsync(blacklistedId);

            // Then
            var allBlacklists = await dbContext.Blacklists.ToListAsync();

            var newBlacklistedId = await dbContext.Blacklists.FirstOrDefaultAsync();

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

                newBlacklistedId.Should().NotBeNull();
                newBlacklistedId.Reason.Should().Be(expectedReason);
                newBlacklistedId.EntityType.Should().Be(expectedEntityType);
                newBlacklistedId.MalId.Should().Be(expectedMalId);
            }
        }
Пример #16
0
        public async Task HandleAsync_GivenEmptyDatabase_ShouldNotThrowAndNotCallJikan()
        {
            // Given
            var dbContext           = InMemoryDbProvider.GetDbContext();
            var jikanServiceBuilder = new JikanServiceBuilder();

            var handler = CreateHandler(dbContext, jikanServiceBuilder.Build());

            var command = new UpdateAnimeMessage
            {
                Id    = Guid.NewGuid(),
                MalId = 1
            };

            // When
            var action = handler.Awaiting(x => x.HandleAsync(command));

            // Then
            using (new AssertionScope())
            {
                await action.Should().NotThrowAsync();

                jikanServiceBuilder.JikanClient.Verify(x => x.GetAnimeAsync(It.IsAny <long>()), Times.Never);
            }
        }
Пример #17
0
        public async Task GetAllSeiyuuRolesByMalIdAsync_GivenSeiyuuWithMultipleRolesAndMainRolesOnly_ShouldReturnPartial()
        {
            // Given
            const int seiyuuMalId = 1;
            var       dbContext   = InMemoryDbProvider.GetDbContext();
            var       repository  = new SeiyuuRoleRepository(dbContext);

            var japanese       = new LanguageBuilder().WithLanguageId(LanguageId.Japanese).Build();
            var seiyuu         = new SeiyuuBuilder().WithMalId(seiyuuMalId).Build();
            var mainRole       = new AnimeRoleTypeBuilder().WithId(AnimeRoleTypeId.Main).Build();
            var supportingRole = new AnimeRoleTypeBuilder().WithId(AnimeRoleTypeId.Supporting).Build();

            seiyuu.Role = new List <AnimeRole>
            {
                new AnimeRoleBuilder().WithLanguage(japanese).WithRoleType(mainRole).Build(),
                new AnimeRoleBuilder().WithLanguage(japanese).WithRoleType(supportingRole).Build(),
                new AnimeRoleBuilder().WithLanguage(japanese).WithRoleType(supportingRole).Build(),
                new AnimeRoleBuilder().WithLanguage(japanese).WithRoleType(supportingRole).Build(),
                new AnimeRoleBuilder().WithLanguage(japanese).WithRoleType(mainRole).Build()
            };

            await dbContext.AddAsync(seiyuu);

            await dbContext.SaveChangesAsync();

            // When
            var result = await repository.GetAllSeiyuuRolesByMalIdAsync(seiyuuMalId, true);

            // Then
            result.Should().HaveCount(2);
        }
Пример #18
0
        public async Task HandleAsync_GivenExceptionFromJikan_ShouldThrowAndCallJikan()
        {
            // Given
            const int malId               = 1;
            var       dbContext           = InMemoryDbProvider.GetDbContext();
            var       jikanServiceBuilder = new JikanServiceBuilder().WithGetAnimeThrowing();

            var anime = new AnimeBuilder()
                        .WithMalId(malId)
                        .Build();

            await dbContext.AddAsync(anime);

            await dbContext.SaveChangesAsync();

            var handler = CreateHandler(dbContext, jikanServiceBuilder.Build());

            var command = new UpdateAnimeMessage
            {
                Id    = Guid.NewGuid(),
                MalId = malId
            };

            // When
            var action = handler.Awaiting(x => x.HandleAsync(command));

            // Then
            using (new AssertionScope())
            {
                await action.Should().ThrowExactlyAsync <JikanRequestException>();

                jikanServiceBuilder.JikanClient.Verify(x => x.GetAnimeAsync(malId), Times.Once);
            }
        }
Пример #19
0
        public async Task GetAsync_GivenMultipleExistingAnimeOneOfWhichWithId_ShouldReturnResult()
        {
            // Given
            var dbContext  = InMemoryDbProvider.GetDbContext();
            var repository = new CharacterRepository(dbContext);
            var character1 = new CharacterBuilder().WithMalId(1).Build();
            var character2 = new CharacterBuilder().WithMalId(2).Build();
            var character3 = new CharacterBuilder().WithMalId(3).Build();
            var character4 = new CharacterBuilder().WithMalId(4).Build();
            var character5 = new CharacterBuilder().WithMalId(5).Build();

            await dbContext.AnimeCharacters.AddAsync(character1);

            await dbContext.AnimeCharacters.AddAsync(character2);

            await dbContext.AnimeCharacters.AddAsync(character3);

            await dbContext.AnimeCharacters.AddAsync(character4);

            await dbContext.AnimeCharacters.AddAsync(character5);

            await dbContext.SaveChangesAsync();

            // When
            var result = await repository.GetAsync(3);

            // Then
            result.Should().NotBeNull();
            result.MalId.Should().Be(3);
        }
Пример #20
0
        public async Task UpdateAsync_GivenExistingSeiyuu_ShouldUpdate()
        {
            // Given
            var dbContext  = InMemoryDbProvider.GetDbContext();
            var repository = new SeiyuuRepository(dbContext);
            var seiyuu     = new SeiyuuBuilder().WithName("Test").Build();

            await dbContext.Seiyuus.AddAsync(seiyuu);

            await dbContext.SaveChangesAsync();

            seiyuu.Name = "Updated";

            // When
            await repository.UpdateAsync(seiyuu);

            // Then
            var allSeiyuu = await dbContext.Seiyuus.ToListAsync();

            using (new AssertionScope())
            {
                var updatedSeiyuu = allSeiyuu.SingleOrDefault();
                updatedSeiyuu.Should().NotBeNull();
                updatedSeiyuu.Name.Should().Be("Updated");
                updatedSeiyuu.ModificationDate.Should().HaveDay(DateTime.UtcNow.Day);
            }
        }
Пример #21
0
        public async Task GetPageAsync_GivenMultipleWithPagesizeAndPage_ShouldReturnOnlyOnePage()
        {
            // Given
            const int pageSize   = 2;
            const int pageNumber = 1;

            var dbContext  = InMemoryDbProvider.GetDbContext();
            var repository = new CharacterRepository(dbContext);
            var character1 = new CharacterBuilder().WithName("Test1").Build();
            var character2 = new CharacterBuilder().WithName("Test2").Build();
            var character3 = new CharacterBuilder().WithName("Test3").Build();

            await dbContext.AnimeCharacters.AddAsync(character1);

            await dbContext.AnimeCharacters.AddAsync(character2);

            await dbContext.AnimeCharacters.AddAsync(character3);

            await dbContext.SaveChangesAsync();

            // When
            var result = await repository.GetPageAsync(pageNumber, pageSize);

            // Then// Then
            using (new AssertionScope())
            {
                result.TotalCount.Should().Be(3);
                result.Results.Should().HaveCount(1);
                result.PageSize.Should().Be(pageSize);
                result.Page.Should().Be(pageNumber);
            }
        }
Пример #22
0
        public async Task GetAsync_GivenMultipleExistingSeiyuuOneOfWhichWithId_ShouldReturnResult()
        {
            // Given
            var dbContext  = InMemoryDbProvider.GetDbContext();
            var repository = new SeiyuuRepository(dbContext);
            var seiyuu1    = new SeiyuuBuilder().WithMalId(1).Build();
            var seiyuu2    = new SeiyuuBuilder().WithMalId(2).Build();
            var seiyuu3    = new SeiyuuBuilder().WithMalId(3).Build();
            var seiyuu4    = new SeiyuuBuilder().WithMalId(4).Build();
            var seiyuu5    = new SeiyuuBuilder().WithMalId(5).Build();

            await dbContext.Seiyuus.AddAsync(seiyuu1);

            await dbContext.Seiyuus.AddAsync(seiyuu2);

            await dbContext.Seiyuus.AddAsync(seiyuu3);

            await dbContext.Seiyuus.AddAsync(seiyuu4);

            await dbContext.Seiyuus.AddAsync(seiyuu5);

            await dbContext.SaveChangesAsync();

            // When
            var result = await repository.GetAsync(3);

            // Then
            result.Should().NotBeNull();
            result.MalId.Should().Be(3);
        }
        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();
        }
Пример #24
0
        public async Task GetOrderedPageByPopularityAsync_GivenMultipleSeiyuu_ShouldReturnAll()
        {
            // Given
            var dbContext  = InMemoryDbProvider.GetDbContext();
            var repository = new SeiyuuRepository(dbContext);
            var seiyuu1    = new SeiyuuBuilder().WithName("Test1").Build();
            var seiyuu2    = new SeiyuuBuilder().WithName("Test2").Build();
            var seiyuu3    = new SeiyuuBuilder().WithName("Test3").Build();

            await dbContext.Seiyuus.AddAsync(seiyuu1);

            await dbContext.Seiyuus.AddAsync(seiyuu2);

            await dbContext.Seiyuus.AddAsync(seiyuu3);

            await dbContext.SaveChangesAsync();

            // When
            var result = await repository.GetOrderedPageByPopularityAsync(x => true);

            // Then
            using (new AssertionScope())
            {
                result.TotalCount.Should().Be(3);
                result.Results.Should().HaveCount(3);
            }
        }
Пример #25
0
        public async Task GetAllRolesInSeason_GivenSeasonWithSingleAnimeWithMultipleRolesAndMainRolesOnly_ShouldReturnPartial()
        {
            // Given
            var animeId    = Guid.NewGuid();
            var dbContext  = InMemoryDbProvider.GetDbContext();
            var repository = new SeasonRoleRepository(dbContext);

            var japanese       = new LanguageBuilder().WithLanguageId(LanguageId.Japanese).Build();
            var anime          = new AnimeBuilder().WithId(animeId).Build();
            var mainRole       = new AnimeRoleTypeBuilder().WithId(AnimeRoleTypeId.Main).Build();
            var supportingRole = new AnimeRoleTypeBuilder().WithId(AnimeRoleTypeId.Supporting).Build();

            anime.Role = new List <AnimeRole>
            {
                new AnimeRoleBuilder().WithLanguage(japanese).WithRoleType(mainRole).Build(),
                new AnimeRoleBuilder().WithLanguage(japanese).WithRoleType(supportingRole).Build(),
                new AnimeRoleBuilder().WithLanguage(japanese).WithRoleType(supportingRole).Build(),
                new AnimeRoleBuilder().WithLanguage(japanese).WithRoleType(supportingRole).Build(),
                new AnimeRoleBuilder().WithLanguage(japanese).WithRoleType(mainRole).Build()
            };

            await dbContext.AddAsync(anime);

            await dbContext.SaveChangesAsync();

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

            // Then
            result.Should().HaveCount(2);
        }
Пример #26
0
        public async Task GetOrderedPageByPopularityAsync_GivenMultipleWithPredicate_ShouldReturnEmpty()
        {
            // Given
            const int pageSize   = 2;
            const int pageNumber = 2;

            var dbContext  = InMemoryDbProvider.GetDbContext();
            var repository = new SeiyuuRepository(dbContext);
            var seiyuu1    = new SeiyuuBuilder().WithName("Test1").Build();
            var seiyuu2    = new SeiyuuBuilder().WithName("Test2").Build();
            var seiyuu3    = new SeiyuuBuilder().WithName("Test3").Build();

            await dbContext.Seiyuus.AddAsync(seiyuu1);

            await dbContext.Seiyuus.AddAsync(seiyuu2);

            await dbContext.Seiyuus.AddAsync(seiyuu3);

            await dbContext.SaveChangesAsync();

            // When
            var result = await repository.GetOrderedPageByPopularityAsync(x => x.Name.EndsWith("1"), pageNumber, pageSize);

            // Then// Then
            using (new AssertionScope())
            {
                result.TotalCount.Should().Be(1);
                result.Results.Should().BeEmpty();
                result.Page.Should().Be(pageNumber);
                result.PageSize.Should().Be(pageSize);
            }
        }
Пример #27
0
        public async Task HandleAsync_GivenExistingSeiyuu_ShouldSkipAndNotCallJikan()
        {
            // Given
            var       dbContext           = InMemoryDbProvider.GetDbContext();
            var       jikanServiceBuilder = new JikanServiceBuilder();
            const int startingMalId       = 1;
            var       s3Service           = new S3ServiceStub(startingMalId);

            var anime = new SeiyuuBuilder()
                        .WithMalId(startingMalId + 1)
                        .Build();

            await dbContext.AddAsync(anime);

            await dbContext.SaveChangesAsync();

            var handler = CreateHandler(dbContext, jikanServiceBuilder.Build(), s3Service, 5);

            // When
            await handler.HandleAsync();

            // Then
            jikanServiceBuilder.JikanClient.Verify(x => x.GetPersonAsync(It.IsAny <int>()), Times.Never);
            dbContext.Seiyuus.Should().ContainSingle();
        }
Пример #28
0
        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);
            }
        }
Пример #29
0
        public async Task HandleAsync_GivenNotExistingSeiyuuNullFromJikan_ShouldSkipAndNotInsert()
        {
            // Given
            var       dbContext           = InMemoryDbProvider.GetDbContext();
            var       jikanServiceBuilder = new JikanServiceBuilder().WithPersonReturned(null, null);
            const int startingMalId       = 1;
            var       s3Service           = new S3ServiceStub(startingMalId);

            var anime = new SeiyuuBuilder()
                        .WithMalId(startingMalId)
                        .Build();

            await dbContext.AddAsync(anime);

            await dbContext.SaveChangesAsync();

            var handler = CreateHandler(dbContext, jikanServiceBuilder.Build(), s3Service, 1);

            // When
            await handler.HandleAsync();

            // Then
            jikanServiceBuilder.JikanClient.Verify(x => x.GetPersonAsync(startingMalId + 1), Times.Once);
            dbContext.Seiyuus.Should().ContainSingle();
        }
Пример #30
0
        public async Task GetAllBySeasonAndTypeAsync_GivenMultipleAnimeOnlyOneInSeasonWithType_ShouldReturnSingle()
        {
            // Given
            var               dbContext   = InMemoryDbProvider.GetDbContext();
            var               repository  = new AnimeRepository(dbContext);
            const int         seasonId1   = 100;
            const int         seasonId2   = 101;
            const AnimeTypeId animeTypeId = AnimeTypeId.TV;
            var               animeType   = new AnimeTypeBuilder().WithId(animeTypeId).Build();
            var               season1     = new SeasonBuilder().WithId(seasonId1).WithName("Winter").WithYear(2000).Build();
            var               season2     = new SeasonBuilder().WithId(seasonId2).WithName("Spring").WithYear(2000).Build();
            var               anime1      = new AnimeBuilder().WithTitle("Test1").WithSeason(season1).WithAnimeType(animeType).Build();
            var               anime2      = new AnimeBuilder().WithTitle("Test2").WithSeason(season1).WithAnimeType(animeType).Build();
            var               anime3      = new AnimeBuilder().WithTitle("Test3").WithSeason(season2).WithAnimeType(animeType).Build();

            await dbContext.Animes.AddAsync(anime1);

            await dbContext.Animes.AddAsync(anime2);

            await dbContext.Animes.AddAsync(anime3);

            await dbContext.SaveChangesAsync();

            // When
            var result = await repository.GetAllBySeasonAndTypeAsync(seasonId2, animeTypeId);

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