Exemple #1
0
        public void SecondSourcersDataOnly()
        {
            var lovedTracksRootReturn = new LovedTracksRootObject
            {
                LovedTracksPage = new LovedTracksPage
                {
                    LovedTracks = new LovedTrack[]
                    {
                        new LovedTrack
                        {
                            Name = "onesong", Artist = new Item {
                                Name = "one"
                            },
                            Date = new LastFmDate {
                                Text = "some date", Uts = 1539280493
                            }
                        },
                        new LovedTrack
                        {
                            Name = "twosong", Artist = new Item {
                                Name = "one"
                            },
                            Date = new LastFmDate {
                                Text = "some date", Uts = 1539280493
                            }
                        }
                    }
                }
            };
            var topartistsContentProviderMock = new Mock <IContentProvider <TopArtistsRootObject> >();

            topartistsContentProviderMock.Setup((m) => m.GetContent("user.gettopartists", "scentmaster", 1, "period=7day"))
            .Returns(new TopArtistsRootObject());
            var lovedTracksContentProviderMock = new Mock <IContentProvider <LovedTracksRootObject> >();

            lovedTracksContentProviderMock.Setup((m) => m.GetContent("user.getlovedtracks", "scentmaster", 1, ""))
            .Returns(lovedTracksRootReturn);
            serviceProvider = ConfigureServices(serviceCollection, topartistsContentProviderMock.Object,
                                                lovedTracksContentProviderMock.Object);

            ITopItemsAggregator topItemsSourcer = serviceProvider.GetService <ITopItemsAggregator>();

            topItemsSourcer.RegisterProvider(serviceProvider.GetService <LastFmTopArtistsProvider>());
            topItemsSourcer.RegisterProvider(serviceProvider.GetService <LastFmLovedProvider>());
            var topItems = topItemsSourcer.GetItems("scentmaster");

            Assert.IsNotNull(topItems);
            Assert.IsTrue(topItems.Any());
            Assert.IsFalse(topItems.Any(t => t.Hits > 0));
            Assert.IsTrue(topItems.Any(t => t.Hits == 0 && t.Name == "one" && t.Loved == 2));
            Assert.AreEqual(1, topItems.Count);
        }
Exemple #2
0
        public void NoSourcersData()
        {
            var topartistsContentProviderMock = new Mock <IContentProvider <TopArtistsRootObject> >();

            topartistsContentProviderMock.Setup((m) => m.GetContent("user.gettopartists", "scentmaster", 1, "period=7day"))
            .Returns(new TopArtistsRootObject());
            var lovedTracksContentProviderMock = new Mock <IContentProvider <LovedTracksRootObject> >();

            lovedTracksContentProviderMock.Setup((m) => m.GetContent("user.getlovedtracks", "scentmaster", 1, ""))
            .Returns(new LovedTracksRootObject());
            serviceProvider = ConfigureServices(serviceCollection, topartistsContentProviderMock.Object,
                                                lovedTracksContentProviderMock.Object);

            ITopItemsAggregator topItemsSourcer = serviceProvider.GetService <ITopItemsAggregator>();

            topItemsSourcer.RegisterProvider(serviceProvider.GetService <LastFmTopArtistsProvider>());
            topItemsSourcer.RegisterProvider(serviceProvider.GetService <LastFmLovedProvider>());
            var topItems = topItemsSourcer.GetItems("scentmaster");

            Assert.IsNotNull(topItems);
            Assert.IsFalse(topItems.Any());
        }
Exemple #3
0
        public void FirstSourcersDataOnly()
        {
            var topArtistsReturn = new TopArtistsRootObject
            {
                TopArtistsPage = new TopArtistsPage
                {
                    TopArtists = new TopArtist[]
                    { new TopArtist {
                          Name = "one", PlayCount = 2
                      }, new TopArtist {
                          Name = "two", PlayCount = 2
                      } }
                }
            };
            var topartistsContentProviderMock = new Mock <IContentProvider <TopArtistsRootObject> >();

            topartistsContentProviderMock.Setup((m) => m.GetContent("user.gettopartists", "scentmaster", 1, "period=7day"))
            .Returns(topArtistsReturn);
            var lovedTracksContentProviderMock = new Mock <IContentProvider <LovedTracksRootObject> >();

            lovedTracksContentProviderMock.Setup((m) => m.GetContent("user.getlovedtracks", "scentmaster", 1, ""))
            .Returns(new LovedTracksRootObject());
            serviceProvider = ConfigureServices(serviceCollection, topartistsContentProviderMock.Object,
                                                lovedTracksContentProviderMock.Object);

            ITopItemsAggregator topItemsSourcer = serviceProvider.GetService <ITopItemsAggregator>();

            topItemsSourcer.RegisterProvider(serviceProvider.GetService <LastFmTopArtistsProvider>());
            topItemsSourcer.RegisterProvider(serviceProvider.GetService <LastFmLovedProvider>());
            var topItems = topItemsSourcer.GetItems("scentmaster");

            Assert.IsNotNull(topItems);
            Assert.IsTrue(topItems.Any());
            Assert.IsTrue(topItems.Any(t => t.Hits == 2 && t.Name == "one" && t.Loved == 0));
            Assert.IsTrue(topItems.Any(t => t.Hits == 2 && t.Name == "two" && t.Loved == 0));
            Assert.AreEqual(2, topItems.Count);
        }