예제 #1
0
        public async Task GetStatsForChart_WithMultipleTrackEntries_ReturnsCorrectStats()
        {
            // Arrange
            var lastFmFake = new FakeLastFmService();
            var lastFmStub = lastFmFake.Object;

            // Represents the tracks that will be returned over time
            var tracksList = new List <List <LastFmChartTrack> >
            {
                new List <LastFmChartTrack>
                {
                    new LastFmChartTrack {
                        Title = "Cool", Artist = "Dua Lipa", Rank = 1
                    },
                    new LastFmChartTrack {
                        Title = "Pretty Please", Artist = "Dua Lipa", Rank = 2
                    },
                    new LastFmChartTrack {
                        Title = "Hallucinate", Artist = "Dua Lipa", Rank = 3
                    },
                    new LastFmChartTrack {
                        Title = "WANNABE", Artist = "ITZY", Rank = 4
                    },
                },
                new List <LastFmChartTrack>
                {
                    new LastFmChartTrack {
                        Title = "WANNABE", Artist = "ITZY", Rank = 1
                    },
                    new LastFmChartTrack {
                        Title = "Pretty Please", Artist = "Dua Lipa", Rank = 2
                    },
                    new LastFmChartTrack {
                        Title = "Cool", Artist = "Dua Lipa", Rank = 3
                    },
                },
                new List <LastFmChartTrack>
                {
                    new LastFmChartTrack {
                        Title = "WANNABE", Artist = "ITZY", Rank = 1
                    },
                    new LastFmChartTrack {
                        Title = "Pretty Please", Artist = "Dua Lipa", Rank = 2
                    },
                    new LastFmChartTrack {
                        Title = "Hallucinate", Artist = "Dua Lipa", Rank = 3
                    },
                    new LastFmChartTrack {
                        Title = "Cool", Artist = "Dua Lipa", Rank = 4
                    },
                }
            };

            var context          = FakeThreeChartsContext.BuildInMemoryContext();
            var chartDateService = new ChartDateService(context);
            var repo             = new ChartRepository(context);
            var chartService     = new ChartService(repo, chartDateService, lastFmStub);

            // Act
            var weeks = new List <ChartWeek>();

            for (var i = 0; i < 3; i++)
            {
                var week = new ChartWeek
                {
                    Owner = new User {
                        UserName = "******"
                    }, WeekNumber = i + 1
                };

                // Set LastFm fake to return correct tracks according to index
                lastFmFake.Tracks = tracksList[i];
                lastFmFake.SetupFake(); // Updates fake returns

                var trackChart = await lastFmStub.GetWeeklyTrackChart("", 0, 0);

                var albumChart = await lastFmStub.GetWeeklyAlbumChart("", 0, 0);

                var artistChart = await lastFmStub.GetWeeklyArtistChart("", 0, 0);

                week.ChartEntries = chartService.CreateEntriesForLastFmCharts(
                    trackChart.Value,
                    albumChart.Value,
                    artistChart.Value,
                    week
                    );

                weeks.Add(week);
            }

            var results = weeks
                          .Select(w => w.ChartEntries)
                          .Select(entries =>
                                  entries
                                  .Select(entry => chartService.GetStatsForChartEntry(entry, weeks))
                                  .ToList())
                          .ToList();

            // Assert
            // All stats on the first week should be .New
            results[0].ForEach(r => r.stat.Should().Be(ChartEntryStat.New));

            results[1].Should().BeEquivalentTo(
                new List <(ChartEntryStat stat, string statText)>()
            {
                (ChartEntryStat.Increase, "+3"),
                (ChartEntryStat.NoDiff, "="),
                (ChartEntryStat.Decrease, "-2"),
            }
                );

            results[2].Should().BeEquivalentTo(
                new List <(ChartEntryStat stat, string statText)>()
            {
                (ChartEntryStat.NoDiff, "="),
                (ChartEntryStat.NoDiff, "="),
                (ChartEntryStat.Reentry, null),
                (ChartEntryStat.Decrease, "-1"),
            }
                );
        }