Пример #1
0
        public void GetFilteredUserAnimeList_AllFilters_WorkCorrectly(string title,
                                                                      int expectedFilteredListSize, AnimeType broadcastType)
        {
            using (var mock = AutoMock.GetLoose())
            {
                // Arrange
                var mockContext = new Mock <IMiruDbContext>();
                var data        = new List <MiruAnimeModel>
                {
                    new MiruAnimeModel {
                        JSTBroadcastTime = null, Title = "tako", Type = "TV"
                    },
                    new MiruAnimeModel {
                        JSTBroadcastTime = null, Title = "takodachi", Type = "TV"
                    },
                    new MiruAnimeModel {
                        JSTBroadcastTime = null, Title = "gura", Type = "ONA"
                    },
                    new MiruAnimeModel {
                        JSTBroadcastTime = null, Title = "gura", Type = "TV"
                    },
                    new MiruAnimeModel {
                        JSTBroadcastTime = null, Title = "guraxxx", Type = "TV"
                    },
                    new MiruAnimeModel {
                        JSTBroadcastTime = null, Title = "gura123", Type = "ONA"
                    },
                    new MiruAnimeModel {
                        JSTBroadcastTime = null, Title = "tako", Type = "ONA"
                    },
                }.AsQueryable();
                var cls       = SetupMiruDbServiceMock(mockContext, mock, miruAnimeModelDbSetData: data, miruDbContext: out IMiruDbContext db);
                var converter = new EnumDescriptionTypeConverter(typeof(AnimeType));
                var animeBroadcastTypeDescription = converter.ConvertToString(broadcastType);

                // Act
                var result = cls.GetFilteredUserAnimeList(db, broadcastType, title, It.IsAny <TimeZoneInfo>());

                // Assert
                Assert.All(result, x => Assert.Contains(title, x.Title));
                Assert.All(result, x => Assert.Contains(x.Type, animeBroadcastTypeDescription));
                Assert.All(result, x => Assert.Equal(DateTime.Today, x.LocalBroadcastTime));
                Assert.Equal(expectedFilteredListSize, result.Count);
            }
        }
        public void FilterByBroadcastType_GivenBroadcastType_ShouldFilterAnimeList(AnimeType broadcastType, int expectedListCount)
        {
            using (var mock = AutoMock.GetLoose())
            {
                // Arrange
                var animeList = new List <MiruAnimeModel>
                {
                    new MiruAnimeModel()
                    {
                        Type = "TV"
                    },
                    new MiruAnimeModel()
                    {
                        Type = "ONA"
                    },
                    new MiruAnimeModel()
                    {
                        Type = "ONA"
                    },
                    new MiruAnimeModel()
                    {
                        Type = string.Empty
                    },
                };

                var converter = new EnumDescriptionTypeConverter(typeof(AnimeType));
                var animeBroadcastTypeDescription = converter.ConvertToString(broadcastType);

                // Act
                animeList.FilterByBroadcastType(broadcastType);

                // Assert
                Assert.All(animeList, x => Assert.Contains(x.Type, animeBroadcastTypeDescription));
                Assert.Equal(expectedListCount, animeList.Count());
            }
        }