Ejemplo n.º 1
0
        public async Task GetOrderedPageByPopularityAsync_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.GetOrderedPageByPopularityAsync(x => true);

            // Then
            using (new AssertionScope())
            {
                result.TotalCount.Should().Be(3);
                result.Results.Should().HaveCount(3);
            }
        }
Ejemplo n.º 2
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);
            }
        }
Ejemplo n.º 3
0
        public async Task GetOrderedPageByPopularityAsync_GivenMultipleWithPredicate_ShouldReturnEmpty()
        {
            // Given
            const int pageSize   = 2;
            const int pageNumber = 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.GetOrderedPageByPopularityAsync(x => x.Title.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);
            }
        }
Ejemplo n.º 4
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);
            }
        }
Ejemplo n.º 5
0
        public async Task GetAsync_GivenMultipleExistingAnimeOneOfWhichWithId_ShouldReturnResult()
        {
            // Given
            var dbContext  = InMemoryDbProvider.GetDbContext();
            var repository = new AnimeRepository(dbContext);
            var anime1     = new AnimeBuilder().WithMalId(1).Build();
            var anime2     = new AnimeBuilder().WithMalId(2).Build();
            var anime3     = new AnimeBuilder().WithMalId(3).Build();
            var anime4     = new AnimeBuilder().WithMalId(4).Build();
            var anime5     = new AnimeBuilder().WithMalId(5).Build();

            await dbContext.Animes.AddAsync(anime1);

            await dbContext.Animes.AddAsync(anime2);

            await dbContext.Animes.AddAsync(anime3);

            await dbContext.Animes.AddAsync(anime4);

            await dbContext.Animes.AddAsync(anime5);

            await dbContext.SaveChangesAsync();

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

            // Then
            result.Should().NotBeNull();
            result.MalId.Should().Be(3);
        }
Ejemplo n.º 6
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);
        }
Ejemplo n.º 7
0
        public async Task UpdateAsync_GivenExistingAnime_ShouldUpdate()
        {
            // Given
            var dbContext  = InMemoryDbProvider.GetDbContext();
            var repository = new AnimeRepository(dbContext);
            var anime      = new AnimeBuilder().WithTitle("Test").Build();

            await dbContext.Animes.AddAsync(anime);

            await dbContext.SaveChangesAsync();

            anime.Title = "Updated";

            // When
            await repository.UpdateAsync(anime);

            // Then
            var allAnimes = await dbContext.Animes.ToListAsync();

            using (new AssertionScope())
            {
                var updateAnime = allAnimes.SingleOrDefault();
                updateAnime.Should().NotBeNull();
                updateAnime.Title.Should().Be("Updated");
                updateAnime.ModificationDate.Should().HaveDay(DateTime.UtcNow.Day);
            }
        }
Ejemplo n.º 8
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();
        }
Ejemplo n.º 9
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);
        }
Ejemplo n.º 10
0
        public async Task HandleAsync_GivenCorrectSeason_ShouldUpdateSeasonId()
        {
            // Given
            const int malId = 1;

            var returnedAnime = new Anime
            {
                Season = Season.Winter,
                Year   = 2000
            };

            var jikanServiceBuilder = new JikanServiceBuilder().WithAnimeReturned(returnedAnime);

            var dbContext = InMemoryDbProvider.GetDbContext();
            var anime     = new AnimeBuilder()
                            .WithMalId(malId)
                            .WithTitle("PreUpdateTitle")
                            .WithAbout("PreUpdateAbout")
                            .WithEnglishTitle("PreUpdateEnglish")
                            .WithJapaneseTitle("PreUpdateJapaneses")
                            .WithImageUrl("PreUpdateImage")
                            .WithAnimeStatus(x => x.WithName("Airing"))
                            .WithAnimeType(x => x.WithId(Domain.Entities.AnimeTypeId.TV))
                            .WithPopularity(0)
                            .Build();

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

            await dbContext.AddAsync(anime);

            await dbContext.AddAsync(season);

            await dbContext.SaveChangesAsync();

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

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

            // When
            await handler.HandleAsync(command);

            // Then
            var updatedAnime = await dbContext.Animes.FirstAsync(x => x.MalId == malId);

            using (new AssertionScope())
            {
                updatedAnime.SeasonId.Should().Be(10);

                jikanServiceBuilder.JikanClient.Verify(x => x.GetAnimeAsync(malId), Times.Once);
            }
        }
        public async Task HandleAsync_GivenMultipleCommonSeiyuu_ShouldReturnMultipleResults()
        {
            // Given
            var query = new CompareAnimeQuery {
                AnimeMalIds = new List <long> {
                    1, 2
                }
            };
            var dbContext = InMemoryDbProvider.GetDbContext();

            var miyukiSawashiro     = new SeiyuuBuilder().WithId(Guid.NewGuid()).WithMalId(1).WithName("Miyuki Sawashiro").Build();
            var chiwaSaito          = new SeiyuuBuilder().WithId(Guid.NewGuid()).WithMalId(2).WithName("Chiwa Saito").Build();
            var onePieceAnime       = new AnimeBuilder().WithId(Guid.NewGuid()).WithMalId(1).WithTitle("One Piece").Build();
            var bakemonogatariAnime = new AnimeBuilder().WithId(Guid.NewGuid()).WithMalId(2).WithTitle("Bakemonogatari").Build();
            var japanese            = new LanguageBuilder().WithLanguageId(LanguageId.Japanese).Build();
            var animeRoles          = new List <AnimeRole>
            {
                new AnimeRoleBuilder()
                .WithAnime(onePieceAnime)
                .WithSeiyuu(miyukiSawashiro)
                .WithCharacter(x => x.WithId(Guid.NewGuid()).WithMalId(1).WithName("Charlotte Pudding").Build())
                .WithLanguage(japanese)
                .Build(),
                new AnimeRoleBuilder()
                .WithAnime(bakemonogatariAnime)
                .WithSeiyuu(miyukiSawashiro)
                .WithCharacter(x => x.WithId(Guid.NewGuid()).WithMalId(2).WithName("Kanbaru Suruga").Build())
                .WithLanguage(japanese)
                .Build(),
                new AnimeRoleBuilder()
                .WithAnime(onePieceAnime)
                .WithSeiyuu(chiwaSaito)
                .WithCharacter(x => x.WithId(Guid.NewGuid()).WithMalId(1).WithName("Chimney").Build())
                .WithLanguage(japanese)
                .Build(),
                new AnimeRoleBuilder()
                .WithAnime(bakemonogatariAnime)
                .WithSeiyuu(chiwaSaito)
                .WithCharacter(x => x.WithId(Guid.NewGuid()).WithMalId(2).WithName("Hitagi Senjougahara").Build())
                .WithLanguage(japanese)
                .Build()
            };

            await dbContext.AddRangeAsync(animeRoles);

            await dbContext.SaveChangesAsync();

            var handler = CreateHandler(dbContext);

            // When
            var result = await handler.HandleAsync(query);

            // Then
            result.Should().HaveCount(2);
        }
Ejemplo n.º 12
0
        public async Task HandleAsync_GivenPlaceholderOrEmptyImageUrl_ShouldUpdateWithEmpty(string imageUrl)
        {
            // Given
            const int malId = 1;

            var returnedAnime = new Anime
            {
                Images = new ImagesSet
                {
                    JPG = new Image {
                        ImageUrl = imageUrl
                    }
                }
            };

            var jikanServiceBuilder = new JikanServiceBuilder().WithAnimeReturned(returnedAnime);

            var dbContext = InMemoryDbProvider.GetDbContext();
            var anime     = new AnimeBuilder()
                            .WithMalId(malId)
                            .WithTitle("PreUpdateTitle")
                            .WithAbout("PreUpdateAbout")
                            .WithEnglishTitle("PreUpdateEnglish")
                            .WithJapaneseTitle("PreUpdateJapaneses")
                            .WithImageUrl("PreUpdateImage")
                            .WithPopularity(0)
                            .Build();

            await dbContext.AddAsync(anime);

            await dbContext.SaveChangesAsync();

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

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

            // When
            await handler.HandleAsync(command);

            // Then
            var updatedAnime = await dbContext.Animes.FirstAsync(x => x.MalId == malId);

            using (new AssertionScope())
            {
                updatedAnime.ImageUrl.Should().BeEmpty();

                jikanServiceBuilder.JikanClient.Verify(x => x.GetAnimeAsync(malId), Times.Once);
            }
        }
Ejemplo n.º 13
0
        public async Task HandleAsync_GivenUnknownStatusAndType_ShouldNotUpdateStatusAndType()
        {
            // Given
            const int malId = 1;

            var returnedAnime = new Anime
            {
                Type   = "test type",
                Status = "test status"
            };

            var jikanServiceBuilder = new JikanServiceBuilder().WithAnimeReturned(returnedAnime);

            var dbContext = InMemoryDbProvider.GetDbContext();
            var anime     = new AnimeBuilder()
                            .WithMalId(malId)
                            .WithTitle("PreUpdateTitle")
                            .WithAbout("PreUpdateAbout")
                            .WithEnglishTitle("PreUpdateEnglish")
                            .WithJapaneseTitle("PreUpdateJapaneses")
                            .WithImageUrl("PreUpdateImage")
                            .WithAnimeStatus(x => x.WithId(Domain.Entities.AnimeStatusId.CurrentlyAiring))
                            .WithAnimeType(x => x.WithId(Domain.Entities.AnimeTypeId.TV))
                            .WithPopularity(0)
                            .Build();

            await dbContext.AddAsync(anime);

            await dbContext.SaveChangesAsync();

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

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

            // When
            await handler.HandleAsync(command);

            // Then
            var updatedAnime = await dbContext.Animes.FirstAsync(x => x.MalId == malId);

            using (new AssertionScope())
            {
                updatedAnime.TypeId.Should().Be(Domain.Entities.AnimeTypeId.TV);
                updatedAnime.StatusId.Should().Be(Domain.Entities.AnimeStatusId.CurrentlyAiring);

                jikanServiceBuilder.JikanClient.Verify(x => x.GetAnimeAsync(malId), Times.Once);
            }
        }
Ejemplo n.º 14
0
        public async Task HandleAsync_GivenManyTitleSynonyms_ShouldUpdateWithJoinedString()
        {
            // Given
            const int malId = 1;

            var returnedSynonyms = new List <string> {
                "Synonym 1", "Synonym 2", "Synonym 3"
            };

            var returnedAnime = new Anime
            {
                TitleSynonyms = returnedSynonyms
            };

            var jikanServiceBuilder = new JikanServiceBuilder().WithAnimeReturned(returnedAnime);

            var dbContext = InMemoryDbProvider.GetDbContext();
            var anime     = new AnimeBuilder()
                            .WithMalId(malId)
                            .WithTitle("PreUpdateTitle")
                            .WithAbout("PreUpdateAbout")
                            .WithEnglishTitle("PreUpdateEnglish")
                            .WithJapaneseTitle("PreUpdateJapaneses")
                            .WithImageUrl("PreUpdateImage")
                            .WithPopularity(0)
                            .Build();

            await dbContext.AddAsync(anime);

            await dbContext.SaveChangesAsync();

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

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

            // When
            await handler.HandleAsync(command);

            // Then
            var updatedAnime = await dbContext.Animes.FirstAsync(x => x.MalId == malId);

            using (new AssertionScope())
            {
                updatedAnime.TitleSynonyms.Should().Be("Synonym 1;Synonym 2;Synonym 3");

                jikanServiceBuilder.JikanClient.Verify(x => x.GetAnimeAsync(malId), Times.Once);
            }
        }
Ejemplo n.º 15
0
        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);
            }
        }
Ejemplo n.º 16
0
        public void ToAnimeSearchEntryDto_GivenEmptyAnime_ShouldReturnEmptyAnimeSearchEntryDto()
        {
            // Given
            var anime = new AnimeBuilder().Build();

            // When
            var dto = anime.ToAnimeSearchEntryDto();

            // Then
            using (new AssertionScope())
            {
                dto.Should().NotBeNull();
                dto.ImageUrl.Should().BeEmpty();
                dto.Title.Should().BeEmpty();
                dto.MalId.Should().Be(default);
Ejemplo n.º 17
0
        public async Task HandleAsync_GivenExistingAnime_ShouldReturnAnimeCardDto()
        {
            // Given
            const string expectedTitle         = "ExpectedTitle";
            const string expectedImageUrl      = "ExpectedImageUrl";
            const string expectedJapaneseTitle = "期待される日本語タイトル";
            const string expectedTitleSynonyms = "expectedTitleSynonyms";
            const string expectedAbout         = "ExpectedAbout";
            const string expectedStatus        = "ExpectedStatus";
            const long   expectedMalId         = 1;
            var          expectedType          = AnimeTypeId.TV;
            var          dbContext             = InMemoryDbProvider.GetDbContext();

            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();

            await dbContext.AddAsync(anime);

            await dbContext.SaveChangesAsync();

            var handler = CreateHandler(dbContext);

            // When
            var result = await handler.HandleAsync(new GetAnimeCardInfoQuery(expectedMalId));

            // Then
            using (new AssertionScope())
            {
                result.Should().NotBeNull();
                result.Title.Should().Be(expectedTitle);
                result.ImageUrl.Should().Be(expectedImageUrl);
                result.MalId.Should().Be(expectedMalId);
                result.JapaneseTitle.Should().Be(expectedJapaneseTitle);
                result.TitleSynonyms.Should().Be(expectedTitleSynonyms);
                result.About.Should().Be(expectedAbout);
                result.Type.Should().Be(expectedType.ToString());
                result.Status.Should().Be(expectedStatus);
            }
        }
Ejemplo n.º 18
0
        public async Task CountAsync_GivenSingleAnime_ShouldReturnOne()
        {
            // Given
            var dbContext  = InMemoryDbProvider.GetDbContext();
            var repository = new AnimeRepository(dbContext);
            var anime1     = new AnimeBuilder().WithTitle("Test1").Build();

            await dbContext.Animes.AddAsync(anime1);

            await dbContext.SaveChangesAsync();

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

            // Then
            result.Should().Be(1);
        }
Ejemplo n.º 19
0
        public async Task GetAllAsync_GivenSingleAnime_ShouldReturnSingle()
        {
            // Given
            var dbContext  = InMemoryDbProvider.GetDbContext();
            var repository = new AnimeRepository(dbContext);
            var anime      = new AnimeBuilder().WithTitle("Test").Build();

            await dbContext.Animes.AddAsync(anime);

            await dbContext.SaveChangesAsync();

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

            // Then
            result.Should().ContainSingle().Which.Title.Should().Be("Test");
        }
Ejemplo n.º 20
0
        public async Task GetAsync_GivenExistingAnimeWithId_ShouldReturnResult()
        {
            // Given
            var dbContext  = InMemoryDbProvider.GetDbContext();
            var repository = new AnimeRepository(dbContext);
            var anime1     = new AnimeBuilder().WithMalId(1).Build();

            await dbContext.Animes.AddAsync(anime1);

            await dbContext.SaveChangesAsync();

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

            // Then
            result.Should().NotBeNull();
        }
Ejemplo n.º 21
0
        public async Task GetAllRolesInAnimeAsync_GivenNoRolesForAnime_ShouldReturnEmpty()
        {
            // Given
            var animeId    = Guid.NewGuid();
            var dbContext  = InMemoryDbProvider.GetDbContext();
            var repository = new AnimeRoleRepository(dbContext);

            var anime = new AnimeBuilder().WithMalId(2).WithId(animeId).Build();

            await dbContext.AddAsync(anime);

            await dbContext.SaveChangesAsync();

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

            // Then
            result.Should().BeEmpty();
        }
Ejemplo n.º 22
0
        public async Task HandleAsync_GivenExistingAnimeWithOtherMalId_ShouldReturnNotFoundResponse()
        {
            // Given
            const long expectedMalId = 1;
            var        dbContext     = InMemoryDbProvider.GetDbContext();

            var anime = new AnimeBuilder()
                        .WithMalId(expectedMalId + 1)
                        .Build();

            await dbContext.AddAsync(anime);

            await dbContext.SaveChangesAsync();

            var handler = CreateHandler(dbContext);

            // When
            var result = await handler.HandleAsync(new GetAnimeCardInfoQuery(expectedMalId));

            // Then
            result.Should().BeNull();
        }
Ejemplo n.º 23
0
        public async Task GetAllAsync_GivenMultipleAnime_ShouldReturnMultiple()
        {
            // 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.GetAllAsync();

            // Then
            result.Should().HaveCount(3);
        }
        public async Task HandleAsync_GivenSingleAnimeIdQueryDatabase_ShouldReturnEmptyResults()
        {
            // Given
            var query = new CompareAnimeQuery {
                AnimeMalIds = new List <long> {
                    1
                }
            };
            var dbContext = InMemoryDbProvider.GetDbContext();

            var onePieceAnime = new AnimeBuilder().WithId(Guid.NewGuid()).WithMalId(3).WithTitle("One Piece").Build();
            var animeRoles    = new List <AnimeRole>
            {
                new AnimeRoleBuilder()
                .WithAnime(onePieceAnime)
                .WithSeiyuu(x => x.WithId(Guid.NewGuid()).WithMalId(1).WithName("Miyuki Sawashiro").Build())
                .WithCharacter(x => x.WithId(Guid.NewGuid()).WithMalId(1).WithName("Charlotte Pudding").Build())
                .Build(),
                new AnimeRoleBuilder()
                .WithAnime(onePieceAnime)
                .WithSeiyuu(x => x.WithId(Guid.NewGuid()).WithMalId(2).WithName("Chiwa Saito").Build())
                .WithCharacter(x => x.WithId(Guid.NewGuid()).WithMalId(1).WithName("Chimney").Build())
                .Build(),
            };

            await dbContext.AddRangeAsync(animeRoles);

            await dbContext.SaveChangesAsync();

            var handler = CreateHandler(dbContext);

            // When
            var result = await handler.HandleAsync(query);

            // Then
            result.Should().BeEmpty();
        }
Ejemplo n.º 25
0
        public async Task GetAllAsync_GivenSingleAnimeWithSubEntities_ShouldReturnSingleAnimeWithSubentities()
        {
            // Given
            var dbContext  = InMemoryDbProvider.GetDbContext();
            var repository = new AnimeRepository(dbContext);
            var anime      = new AnimeBuilder()
                             .WithTitle("Test")
                             .WithAnimeStatus(x => x.WithName("Airing"))
                             .WithAnimeType(x => x.WithId(AnimeTypeId.TV))
                             .WithSeason(x => x.WithName("Spring").WithYear(2020).Build())
                             .Build();

            await dbContext.Animes.AddAsync(anime);

            await dbContext.SaveChangesAsync();

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

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

            var addedAnime = result.FirstOrDefault();

            using (new AssertionScope())
            {
                addedAnime.Should().NotBeNull();
                addedAnime.Type.Should().NotBeNull();
                addedAnime.Type.Id.Should().Be(AnimeTypeId.TV);
                addedAnime.Status.Should().NotBeNull();
                addedAnime.Status.Description.Should().Be("Airing");
                addedAnime.Season.Should().NotBeNull();
                addedAnime.Season.Name.Should().Be("Spring");
                addedAnime.Season.Year.Should().Be(2020);
            }
        }
Ejemplo n.º 26
0
        public async Task GetAsync_GivenExistingAnimeWithId_ShouldReturnResultWithEntities()
        {
            // Given
            var dbContext  = InMemoryDbProvider.GetDbContext();
            var repository = new AnimeRepository(dbContext);
            var anime      = new AnimeBuilder()
                             .WithTitle("Test")
                             .WithAnimeStatus(x => x.WithName("Airing"))
                             .WithAnimeType(x => x.WithId(AnimeTypeId.TV))
                             .WithTitle("ExpectedTitle")
                             .WithImageUrl("ExpectedImageUrl")
                             .WithAbout("ExpectedAbout")
                             .WithMalId(1)
                             .Build();

            await dbContext.Animes.AddAsync(anime);

            await dbContext.SaveChangesAsync();

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

            // Then
            using (new AssertionScope())
            {
                result.Should().NotBeNull();
                result.MalId.Should().Be(1);
                result.Title.Should().Be("ExpectedTitle");
                result.ImageUrl.Should().Be("ExpectedImageUrl");
                result.About.Should().Be("ExpectedAbout");
                result.Type.Should().NotBeNull();
                result.Type.Id.Should().Be(AnimeTypeId.TV);
                result.Status.Should().NotBeNull();
                result.Status.Description.Should().Be("Airing");
            }
        }
 public AnimeComparisonSubEntryBuilder WithAnime(Action <AnimeBuilder> builderAction)
 {
     _animeBuilder = new AnimeBuilder();
     builderAction(_animeBuilder);
     return(this);
 }
Ejemplo n.º 28
0
        public async Task HandleAsync_GivenBothOnlyAiringDateWithMatchingSeasonInDB_ShouldUpdateSeasonId(DateTime fromAiringDate, long expectedSeasonId)
        {
            // Given
            const int malId = 1;

            var returnedAnime = new Anime
            {
                Season = null,
                Aired  = new TimePeriod
                {
                    From = fromAiringDate
                }
            };

            var jikanServiceBuilder = new JikanServiceBuilder().WithAnimeReturned(returnedAnime);

            var dbContext = InMemoryDbProvider.GetDbContext();
            var anime     = new AnimeBuilder()
                            .WithMalId(malId)
                            .WithTitle("PreUpdateTitle")
                            .WithAbout("PreUpdateAbout")
                            .WithEnglishTitle("PreUpdateEnglish")
                            .WithJapaneseTitle("PreUpdateJapaneses")
                            .WithImageUrl("PreUpdateImage")
                            .WithAnimeStatus(x => x.WithName("Airing"))
                            .WithAnimeType(x => x.WithId(Domain.Entities.AnimeTypeId.TV))
                            .WithPopularity(0)
                            .Build();

            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(12).WithYear(2000).WithName("Summer").Build(),
                new SeasonBuilder().WithId(13).WithYear(2000).WithName("Fall").Build(),
                new SeasonBuilder().WithId(14).WithYear(2001).WithName("Winter").Build(),
            };

            await dbContext.AddAsync(anime);

            await dbContext.AddRangeAsync(seasons);

            await dbContext.SaveChangesAsync();

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

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

            // When
            await handler.HandleAsync(command);

            // Then
            var updatedAnime = await dbContext.Animes.FirstAsync(x => x.MalId == malId);

            using (new AssertionScope())
            {
                updatedAnime.SeasonId.Should().Be(expectedSeasonId);

                jikanServiceBuilder.JikanClient.Verify(x => x.GetAnimeAsync(malId), Times.Once);
            }
        }
 public SeasonSummaryEntryBuilder WithAnime(Action <AnimeBuilder> builderAction)
 {
     _animeBuilder = new AnimeBuilder();
     builderAction(_animeBuilder);
     return(this);
 }
Ejemplo n.º 30
0
        public async Task HandleAsync_GivenCorrectResponse_ShouldUpdateBasicProperties()
        {
            // Given
            const int malId = 1;

            const string returnedTitle         = "PostUpdateTitle";
            const string returnedAbout         = "PostUpdateAbout";
            const string returnedEnglishTitle  = "PostUpdateEnglish";
            const string returnedJapaneseTitle = "PostUpdateJapanese";
            const string returnedImageUrl      = "PostUpdateImageUrl";
            const int    returnedPopularity    = 1;

            var returnedAnime = new Anime
            {
                Title         = returnedTitle,
                Synopsis      = returnedAbout,
                TitleEnglish  = returnedEnglishTitle,
                TitleJapanese = returnedJapaneseTitle,
                Images        = new ImagesSet
                {
                    JPG = new Image {
                        ImageUrl = returnedImageUrl
                    }
                },
                TitleSynonyms = new List <string>(),
                Members       = returnedPopularity
            };

            var jikanServiceBuilder = new JikanServiceBuilder().WithAnimeReturned(returnedAnime);

            var dbContext = InMemoryDbProvider.GetDbContext();
            var anime     = new AnimeBuilder()
                            .WithMalId(malId)
                            .WithTitle("PreUpdateTitle")
                            .WithAbout("PreUpdateAbout")
                            .WithEnglishTitle("PreUpdateEnglish")
                            .WithJapaneseTitle("PreUpdateJapaneses")
                            .WithImageUrl("PreUpdateImage")
                            .WithPopularity(0)
                            .Build();

            await dbContext.AddAsync(anime);

            await dbContext.SaveChangesAsync();

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

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

            // When
            await handler.HandleAsync(command);

            // Then
            var updatedAnime = await dbContext.Animes.FirstAsync(x => x.MalId == malId);

            using (new AssertionScope())
            {
                updatedAnime.Title.Should().Be(returnedTitle);
                updatedAnime.About.Should().Be(returnedAbout);
                updatedAnime.EnglishTitle.Should().Be(returnedEnglishTitle);
                updatedAnime.KanjiTitle.Should().Be(returnedJapaneseTitle);
                updatedAnime.ImageUrl.Should().Be(returnedImageUrl);
                updatedAnime.Popularity.Should().Be(returnedPopularity);

                jikanServiceBuilder.JikanClient.Verify(x => x.GetAnimeAsync(malId), Times.Once);
            }
        }