示例#1
0
        public static string AiringStatusToString(AiringStatus airingStatus)
        {
            switch (airingStatus)
            {
            case AiringStatus.Unknown:              return("Unknown");

            case AiringStatus.NotYetAired:          return("Not Yet Aired");

            case AiringStatus.CurrentlyAiring:      return("Currently Airing");

            case AiringStatus.FinishedAiring:       return("Finished Airing");

            default:                                return("");
            }
        }
        public void SetAiringAnimeModelData_GivenValidInput_SetsDataCorrectly(AiringStatus airingStatus, string broadcast)
        {
            // Arrange
            var      sut           = new MiruAnimeModel();
            DateTime airedFromDate = new DateTime(2022, 3, 14);
            var      animeInfo     = new Anime()
            {
                MalId     = MAL_ID,
                Broadcast = broadcast,
                Title     = TITLE,
                ImageURL  = IMAGE_URL,
                Type      = TYPE,
                Aired     = new TimePeriod()
                {
                    From = airedFromDate
                }
            };
            var animeListEntry = new AnimeListEntry()
            {
                TotalEpisodes   = TOTAL_EPISODES,
                URL             = URL,
                WatchedEpisodes = WATCHED_EPISODES,
                AiringStatus    = airingStatus
            };

            // Act
            sut.SetAiringAnimeModelData(animeInfo, animeListEntry);

            // Assert
            Assert.Equal(MAL_ID, sut.MalId);
            Assert.Equal(TITLE, sut.Title);
            Assert.Equal(IMAGE_URL, sut.ImageURL);
            Assert.Equal(TOTAL_EPISODES, sut.TotalEpisodes);
            Assert.Equal(URL, sut.URL);
            Assert.Equal(WATCHED_EPISODES, sut.WatchedEpisodes);
            Assert.Equal(TYPE, sut.Type);
            Assert.True(sut.IsOnWatchingList);
            Assert.Equal(Path.Combine(Constants.ImageCacheFolderPath, $"{ MAL_ID }.jpg"), sut.LocalImagePath);
            Assert.Equal(airingStatus == AiringStatus.Airing, sut.CurrentlyAiring);
            Assert.Equal(broadcast ?? airedFromDate.ToString(), sut.Broadcast);
        }
示例#3
0
        public void GetDetailedUserAnimeList_GivenNotNullUserAnimeListEntries_ReturnsDetailedList(
            // 1st entry updated exisiting
            int expectedUpdatedWatchedEpisodesValue,
            int expectedUpdatedTotalEpisodesValue,
            AiringStatus updatedAiringStatus,
            // 2nd entry -- new one
            long expectedMalIdOfNewEntry,
            AiringStatus expectedAiringStatusOfNewEntry,
            string titleOfNewEntry,
            int watchedEpisodesOfNewEntry,
            int totalEpisodesOfNewEntry,
            string typeOfNewEntry,
            string urlOfNewEntry)
        {
            using (var mock = AutoMock.GetLoose())
            {
                // Arrange
                var mockContext = new Mock <IMiruDbContext>();
                var date        = new DateTime(2020, 01, 26, 10, 0, 0);
                var testModel   = new MiruAnimeModel {
                    Title            = "initial title", Type = "TV", MalId = 1L, Broadcast = "Sundays at 10:00 (JST)", JSTBroadcastTime = date,
                    IsOnWatchingList = false, WatchedEpisodes = 0, TotalEpisodes = 20, CurrentlyAiring = false, ImageURL = "stays the same", URL = "same", LocalImagePath = "\\same"
                };
                var data = new List <MiruAnimeModel>
                {
                    testModel,
                }.AsQueryable();

                var animeEntryList = new List <AnimeListEntry>()
                {
                    new AnimeListEntry()
                    {
                        MalId         = 1L, AiringStatus = updatedAiringStatus, WatchedEpisodes = expectedUpdatedWatchedEpisodesValue,
                        TotalEpisodes = expectedUpdatedTotalEpisodesValue, Type = "TV", Title = "changed"
                    },

                    new AnimeListEntry()
                    {
                        MalId           = expectedMalIdOfNewEntry, AiringStatus = expectedAiringStatusOfNewEntry,
                        WatchedEpisodes = watchedEpisodesOfNewEntry, TotalEpisodes = totalEpisodesOfNewEntry, Type = typeOfNewEntry, Title = titleOfNewEntry, URL = urlOfNewEntry
                    }
                };

                var cls = SetupMiruDbServiceMock(mockContext, mock, miruDbContext: out IMiruDbContext db, currentUserAnimeEntryList: animeEntryList, miruAnimeModelDbSetData: data);

                // Act
                var result             = cls.GetDetailedUserAnimeList(db, cls.CurrentUserAnimeList.UserAnimeListData.Anime, It.IsAny <bool>()).Result;
                var resultUpdatedEntry = result.First(x => x == testModel);
                var resultNewEntry     = result.First(x => x != testModel);

                // Assert
                Assert.Equal(2, result.Count());
                // check updated anime entry - only 4 values should change
                Assert.True(resultUpdatedEntry.IsOnWatchingList);                                             // should change to true
                Assert.Equal(updatedAiringStatus == AiringStatus.Airing, resultUpdatedEntry.CurrentlyAiring); // should change depending on airing status
                Assert.Equal(expectedUpdatedWatchedEpisodesValue, resultUpdatedEntry.WatchedEpisodes);        // should change to new value
                Assert.Equal(expectedUpdatedTotalEpisodesValue, resultUpdatedEntry.TotalEpisodes);            // should change to new value
                // check if rest of the values for updated entry stay the same
                Assert.Equal(1L, resultUpdatedEntry.MalId);
                Assert.Equal("Sundays at 10:00 (JST)", resultUpdatedEntry.Broadcast);
                Assert.Equal("initial title", resultUpdatedEntry.Title);
                Assert.Equal("stays the same", resultUpdatedEntry.ImageURL);
                Assert.Equal("\\same", resultUpdatedEntry.LocalImagePath);
                Assert.Equal("same", resultUpdatedEntry.URL);
                Assert.Equal("TV", resultUpdatedEntry.Type);

                // check new entry
                Assert.Equal(expectedMalIdOfNewEntry, resultNewEntry.MalId);
                Assert.Equal("Sundays at 10:00 (JST)", resultNewEntry.Broadcast); // it is set in webServiceMock
                Assert.Equal(titleOfNewEntry, resultNewEntry.Title);
                Assert.Equal("\\dydo", resultNewEntry.ImageURL);                  // it is set in webServiceMock
                Assert.Equal(Path.Combine(Constants.ImageCacheFolderPath, $"{ expectedMalIdOfNewEntry }.jpg"), resultNewEntry.LocalImagePath);
                Assert.Equal(totalEpisodesOfNewEntry, resultNewEntry.TotalEpisodes);
                Assert.Equal(urlOfNewEntry, resultNewEntry.URL);
                Assert.Equal(watchedEpisodesOfNewEntry, resultNewEntry.WatchedEpisodes);
                Assert.True(resultNewEntry.IsOnWatchingList);
                Assert.Equal(expectedAiringStatusOfNewEntry == AiringStatus.Airing, resultNewEntry.CurrentlyAiring);
                Assert.Equal(typeOfNewEntry, resultNewEntry.Type);
            }
        }