Exemplo n.º 1
0
        public async Task CreateArtistAsyncTest()
        {
            // Arrange
            var artistRepoMock = new Mock <IArtistRepository>();

            artistRepoMock.Setup(mock => mock.CreateArtistAsync(It.Is((NewArtistDataDto dataDto) => (
                                                                          dataDto.UserId == 1 &&
                                                                          dataDto.Name == "Test"
                                                                          ))))
            .ReturnsAsync(new ArtistDataDto
            {
                Id      = 1,
                Name    = "Test",
                Picture = "",
            })
            .Verifiable();

            var artistCollection = new ArtistCollection(artistRepoMock.Object, _dependencyMapper);

            // Act
            var artist = await artistCollection.CreateArtistAsync(1, "Test");

            // Assert
            artistRepoMock.Verify();
            Assert.AreEqual(1, artist.Id);
            Assert.AreEqual("Test", artist.Name);
            Assert.AreEqual("", artist.Picture);
        }
Exemplo n.º 2
0
        public async Task GetArtistByIdAsyncTest_ValidId_CorrectData()
        {
            // Arrange
            var artistRepoMock = new Mock <IArtistRepository>();

            artistRepoMock.Setup(mock => mock.GetArtistByIdAsync(1))
            .ReturnsAsync(new ArtistDataDto
            {
                Id      = 1,
                Name    = "Test",
                Picture = "",
            })
            .Verifiable();

            var artistCollection = new ArtistCollection(artistRepoMock.Object, _dependencyMapper);

            // Act
            var artist = await artistCollection.GetArtistByIdAsync(1);

            // Assert
            artistRepoMock.Verify();
            Assert.AreEqual(1, artist.Id);
            Assert.AreEqual("Test", artist.Name);
            Assert.AreEqual("", artist.Picture);
        }
Exemplo n.º 3
0
 /// <summary>
 /// Delete the specified Artist from the storage and the collections
 /// </summary>
 /// <param name="artistAlbumToDelete"></param>
 /// <returns></returns>
 public static void DeleteArtist(Artist artistToDelete)
 {
     // No need to wait for the Artist to be removed from storage
     DbAccess.DeleteAsync(artistToDelete);
     ArtistCollection.Remove(artistToDelete);
     IdLookup.Remove(artistToDelete.Id);
 }
Exemplo n.º 4
0
        public SearchResult Find(string query, int maxResults, int page)
        {
            // Find songs
            DataSet      tracksResult = MakeDataSet("SELECT * FROM track,artist, release WHERE artist.id = track.artist AND track.album = release.id AND (track.title LIKE '%" + query + "%' OR track.title LIKE '%%') AND (release.title LIKE '%" + query + "%' OR release.title LIKE '%%') AND (artist.title LIKE '%" + query + "%' OR artist.title = '%%')");
            SearchResult sr           = new SearchResult(this);

            sr.Tracks = new TrackCollection(this, sr, new List <Track>());
            foreach (DataRow dr in tracksResult.Tables[0].Rows)
            {
                sr.Tracks.Add(TrackFromDataRow(dr));
            }

            // Find artists
            DataSet          artistsResult = MakeDataSet("SELECT * FROM artist WHERE title LIKE '%" + query + "%'");
            ArtistCollection ac            = new ArtistCollection(this, new List <Artist>());

            foreach (DataRow dr in artistsResult.Tables[0].Rows)
            {
                ac.Add(ArtistFromDataSet(dr));
            }
            sr.Artists = ac;

            // Find albums
            DataSet           albumsResult = MakeDataSet("SELECT * FROM release, artist WHERE artist.id = release.artist AND release.title LIKE '%" + query + "%'");
            ReleaseCollection rc           = new ReleaseCollection(this, new List <Release>());

            foreach (DataRow dr in albumsResult.Tables[0].Rows)
            {
                rc.Add(ReleaseFromDataRow(dr));
            }
            sr.Albums = rc;
            return(sr);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Gets the artists by genre.
        /// </summary>
        /// <param name="genreId">The genre id.</param>
        /// <param name="musicSearchBy">The music search by.</param>
        /// <param name="marker">The next/previous marker to get next/previous items</param>
        /// <param name="locale">The locale.</param>
        /// <returns></returns>
        /// <exception cref="System.NullReferenceException">Genre Id cannot be null or empty</exception>
        public async Task <ArtistCollection> GetArtistsByGenreAsync(string genreId, MusicSearchBy musicSearchBy = MusicSearchBy.SalesRank, string marker = "afterMarker=CgAAAA%3d%3d", string locale = null)
        {
            if (string.IsNullOrEmpty(genreId))
            {
                throw new NullReferenceException("Genre Id cannot be null or empty");
            }

            locale = string.IsNullOrEmpty(locale) ? Locale : locale;

            var url = string.Format(Constants.ItemsByGenreUrlFormat, locale, genreId, "artists", musicSearchBy.ToString(), marker);

            var xml = await HttpClient.GetStringAsync(url);

            var result = ParseXml <ZuneArtistSearch.feed>(xml);

            if (result.entry == null)
            {
                return(new ArtistCollection(new List <Artist>()));
            }

            var resultList = new ArtistCollection(result.entry.Select(x => new Artist(x)).ToList());

            resultList.ProcessLinks(result.link);

            return(resultList);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Add a new artist to the storage and the local collections
        /// </summary>
        /// <param name="artistToAdd"></param>
        public static async Task AddArtistAsync(Artist artistToAdd)
        {
            // Need to wait for the Artist to be added so that its Id is available
            await DbAccess.InsertAsync(artistToAdd);

            ArtistCollection.Add(artistToAdd);
            IdLookup[artistToAdd.Id] = artistToAdd;
        }
Exemplo n.º 7
0
        public Library()
        {
            _artists = new ArtistCollection();
            _albums = new AlbumCollection();
            _tracks = new TrackCollection();

            _trackDict = new Dictionary<string, Track>();
        }
Exemplo n.º 8
0
        public Library()
        {
            _artists = new ArtistCollection();
            _albums  = new AlbumCollection();
            _tracks  = new TrackCollection();

            _trackDict = new Dictionary <string, Track>();
        }
Exemplo n.º 9
0
    /// <summary>
    /// Set the data source and bind it to the repeater.
    /// No need to error check odc since the worst case scenario
    /// is that nothing is displayed.
    /// </summary>
    private void SetUpRepeater()
    {
        ArtistCollection ac = new ArtistCollection(false);

        ac.FetchTopSellingArtists(HowMany);
        repeaterArtists.DataSource = ac;
        repeaterArtists.DataBind();
    }
Exemplo n.º 10
0
    /// <summary>
    /// Makes an artist collection using the ArrayList of artist IDs
    /// </summary>
    /// <param name="asc">True for ascending</param>
    /// <returns></returns>
    private ArtistCollection GetArtistCollection(bool asc)
    {
        ArtistCollection ac = new ArtistCollection(false);

        ac.CreateFromArrayList(SessionHandler.GetUsersSession(SessionHandler.Artist));
        ac.SortByName(asc);
        return(ac);
    }
Exemplo n.º 11
0
        /// <summary>
        /// Get the Artists collection from storage
        /// </summary>
        /// <returns></returns>
        public static async Task GetDataAsync()
        {
            if (ArtistCollection == null)
            {
                // Get the current set of artists and form the lookup tables
                ArtistCollection = await DbAccess.LoadAsync <Artist>();

                IdLookup = ArtistCollection.ToDictionary(art => art.Id);
            }
        }
Exemplo n.º 12
0
        /// <summary>
        /// Delete the specified Artists from the storage and the collections
        /// </summary>
        /// <param name="artistsToDelete"></param>
        public static void DeleteArtists(IEnumerable <Artist> artistsToDelete)
        {
            DbAccess.DeleteItemsAsync(artistsToDelete);

            foreach (Artist artistToDelete in artistsToDelete)
            {
                ArtistCollection.Remove(artistToDelete);
                IdLookup.Remove(artistToDelete.Id);
            }
        }
Exemplo n.º 13
0
    /// <summary>
    /// Search Artist(s) with ArtistName
    /// </summary>
    /// <param name="artist">ArtistName string, first name, last name or combined</param>
    private void SearchForArtist(string artist)
    {
        ArtistCollection ac = new ArtistCollection(false);

        ac.FetchForName(artist);
        if (ac.Count > 0)
        {
            rptArtist.DataSource = ac;
            rptArtist.DataBind();
        }
    }
Exemplo n.º 14
0
 /// <summary>
 /// Set the data source and bind it to the repeater
 /// </summary>
 /// <param name="ac">The data source</param>
 private void SetUpRepeaterArtist(ArtistCollection ac)
 {
     if (ac == null || ac.Count <= 0)
     {
         DataError();
     }
     else
     {
         repeaterArtist.DataSource = ac;
         repeaterArtist.DataBind();
     }
 }
Exemplo n.º 15
0
 /// <summary>
 /// Set the data source and bind it to the repeater
 /// </summary>
 /// <param name="r">The repeater to bind to</param>
 /// <param name="ac">The data source</param>
 private void PairRepeaterSimilarArtist(Repeater r, ArtistCollection ac)
 {
     if (ac == null || ac.Count <= 0)
     {
         //do something
     }
     else
     {
         r.DataSource = ac;
         r.DataBind();
     }
 }
Exemplo n.º 16
0
    public static ArtistCollection GetSample()
    {
        //ArtistCollection collection = new ArtistCollection() { new Artist { ArtistId = 1, Name = "aa" } };

        ArtistCollection collection = new ArtistCollection();

        collection.Add(new Artist(1, "aaa"));
        collection.Add(new Artist(2, "bbb"));
        collection.Add(new Artist(3, "cccc"));

        return(collection);
    }
Exemplo n.º 17
0
        internal void RemoveArtistIfNeeded(ArtistViewModel artistViewModel)
        {
            if (artistViewModel.Songs.Count == 0 && artistViewModel.Albums.Count == 0)
            {
                ArtistCollection.Remove(artistViewModel, artistViewModel.SortName);
                ArtistLookupMap.Remove(artistViewModel.ArtistId);

                artistViewModel.IsBeingDeleted = true;

                LibraryModel.Current.DeleteArtist(artistViewModel.ArtistId);
            }
        }
Exemplo n.º 18
0
 /// <summary>
 /// Set the data source and bind it to the repeater
 /// </summary>
 /// <param name="ac">The data source</param>
 private void SetUpArtistList(ArtistCollection ac)
 {
     if (ac == null || ac.Count <= 0)
     {
         //DataError();
     }
     else
     {
         listArtists.DataSource = ac;
         listArtists.DataBind();
     }
 }
Exemplo n.º 19
0
        private void Configuration_ConfigChanged(object sender, ConfigEventArgs e)
        {
            if (e.Config != ConfigEventArgs.Configs.LibraryPath)
            {
                return;
            }

            SongCollector.Stop();
            ArtistCollection.GetMainCollection().Clear();
            AlbumCollection.GetMainCollection().Clear();
            SongCollection.GetMainCollection().Clear();
            SongCollector.Start();
        }
Exemplo n.º 20
0
    /// <summary>
    /// Set up Top Ten Artists repeater (top based on sales)
    /// </summary>
    protected void SetTopTenArtistNav()
    {
        int topTen = 10;
        ArtistCollection artistsTopTen = new ArtistCollection(false);

        artistsTopTen.FetchTopSellingArtists(topTen);

        if (artistsTopTen.Count > 0)
        {
            PopArtistsTopTen.DataSource = artistsTopTen;
            PopArtistsTopTen.DataBind();
        }
    }
Exemplo n.º 21
0
    /// <summary>
    /// Gets an ArtistCollection containing a single artist
    /// </summary>
    /// <param name="id">The artist ID</param>
    /// <returns>The resulting ArtistCollection</returns>
    private ArtistCollection FetchArtistData(int id)
    {
        ArtistCollection ac = null;

        if (id <= 0)
        {
            DataError();
        }
        else
        {
            ac = new ArtistCollection(false);
            ac.FetchForId(id);
        }
        return(ac);
    }
Exemplo n.º 22
0
        public Form1()
        {
            InitializeComponent();

            songlist.Source   = SongCollection.GetMainCollection();
            albumGrid.Source  = AlbumCollection.GetMainCollection();
            artistGrid.Source = ArtistCollection.GetMainCollection();

            Configuration.ConfigChanged += Configuration_ConfigChanged;
            InitSearch();
            Playlist.InitPlaylist();

            //Fetch all the songs
            SongCollector.Start();
        }
Exemplo n.º 23
0
    private ArtistCollection FetchSimilarArtists(string nation)
    {
        ArtistCollection ac = null;

        if (nation == null)
        {
            //do soemthing
        }
        else
        {
            ac = new ArtistCollection(false);
            ac.FetchForNationality(nation);
        }
        return(ac);
    }
Exemplo n.º 24
0
        public async Task GetLikedSongIdsByUserIdAsync_UserIdNoLikedArtists_EmptyArray()
        {
            // Arrange
            var artistRepoMock = new Mock <IArtistRepository>();

            artistRepoMock.Setup(mock => mock.GetLikedArtistIdsByUserIdAsync(1))
            .ReturnsAsync(new int[] { })
            .Verifiable();

            var artistCollection = new ArtistCollection(artistRepoMock.Object, _dependencyMapper);

            // Act
            var likedArtists = (await artistCollection.GetLikedArtistIdsByUserIdAsync(1)).ToArray();

            // Assert
            artistRepoMock.Verify();
            Assert.AreEqual(0, likedArtists.Length);
        }
Exemplo n.º 25
0
        public async Task GetAllAlbumsAsyncTest_NoAlbums_EmptyArray()
        {
            // Arrange
            var artistRepoMock = new Mock <IArtistRepository>();

            artistRepoMock.Setup(mock => mock.GetAllArtistsAsync(0, 4))
            .ReturnsAsync(new ArtistDataDto[] { })
            .Verifiable();

            var albumCollection = new ArtistCollection(artistRepoMock.Object, _dependencyMapper);

            // Act
            var albums = (await albumCollection.GetAllArtistsAsync(0, 4)).ToArray();

            // Assert
            artistRepoMock.Verify();
            Assert.AreEqual(0, albums.Length);
        }
Exemplo n.º 26
0
        public async Task GetArtistByIdAsyncTest_InvalidId_Null()
        {
            // Arrange
            var artistRepoMock = new Mock <IArtistRepository>();

            artistRepoMock.Setup(mock => mock.GetArtistByIdAsync(1))
            .ReturnsAsync(null as ArtistDataDto)
            .Verifiable();

            var artistCollection = new ArtistCollection(artistRepoMock.Object, _dependencyMapper);

            // Act
            var artist = await artistCollection.GetArtistByIdAsync(1);

            // Assert
            artistRepoMock.Verify();
            Assert.AreEqual(null, artist);
        }
Exemplo n.º 27
0
        private async void AllMusic_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
        {
            switch (e.Action)
            {
            case NotifyCollectionChangedAction.Add:
                MusicCollection.AddRange(e.NewItems.Cast <LocalMusic>());
                // ArtistCollection.AddRange(e.NewItems.Cast<LocalMusic>());
                AlbumCollection.AddRange(e.NewItems.Cast <LocalMusic>());
                break;

            case NotifyCollectionChangedAction.Remove:
                foreach (LocalMusic item in e.OldItems)
                {
                    MusicCollection.Remove(item);
                    //  ArtistCollection.Remove(item);
                    AlbumCollection.Remove(item);
                }
                await ArtistCollection.AddRangeAsync(AllMusic.GroupBy(x => x.ArtistsName?.FirstOrDefault() ?? "未知艺术家").ToDictionary(x => x.Key, x => x.ToArray())
                                                     .Select(x =>
                                                             new LocalArtist
                {
                    Name        = x.Key,
                    PicPath     = x.Value.First().Id3Pic,
                    LocalMusics = x.Value
                }));

                break;

            case NotifyCollectionChangedAction.Replace:
                break;

            case NotifyCollectionChangedAction.Move:
                break;

            case NotifyCollectionChangedAction.Reset:
                MusicCollection.Clear();
                ArtistCollection.Clear();
                AlbumCollection.Clear();
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Exemplo n.º 28
0
        private ArtistViewModel LookupArtist(ArtistModel artist)
        {
            if (artist == null)
            {
                return(null);
            }

            if (ArtistLookupMap.ContainsKey(artist.ArtistId))
            {
                return(ArtistLookupMap[artist.ArtistId]);
            }
            else
            {
                ArtistViewModel newArtistViewModel = new ArtistViewModel(artist);

                ArtistLookupMap.Add(newArtistViewModel.ArtistId, newArtistViewModel);
                ArtistCollection.Add(newArtistViewModel, newArtistViewModel.SortName);

                return(newArtistViewModel);
            }
        }
Exemplo n.º 29
0
        public async Task GetAllAlbumsAsyncTest_MoreThanCount_MultipleSections()
        {
            // Arrange
            ArtistDataDto[] result =
            {
                new ArtistDataDto
                {
                    Id      = 1,
                    Name    = "Test",
                    Picture = "",
                },
                new ArtistDataDto
                {
                    Id      = 2,
                    Name    = "Test 2",
                    Picture = "test2.mp3",
                },
            };
            var artistRepoMock = new Mock <IArtistRepository>();

            artistRepoMock.Setup(mock => mock.GetAllArtistsAsync(0, 1))
            .ReturnsAsync(new[] { result[0] })
            .Verifiable();
            artistRepoMock.Setup(mock => mock.GetAllArtistsAsync(1, 1))
            .ReturnsAsync(new[] { result[1] })
            .Verifiable();

            var albumCollection = new ArtistCollection(artistRepoMock.Object, _dependencyMapper);

            // Act
            var section1 = (await albumCollection.GetAllArtistsAsync(0, 1)).ToArray();
            var section2 = (await albumCollection.GetAllArtistsAsync(1, 1)).ToArray();

            // Assert
            artistRepoMock.Verify();
            Assert.AreEqual(1, section1.Length);
            Assert.AreEqual(1, section2.Length);
            Assert.AreEqual(1, section1[0].Id);
            Assert.AreEqual(2, section2[0].Id);
        }
Exemplo n.º 30
0
        public async Task GetAllAlbumsAsyncTest_LessThanCount_AllAvailableData()
        {
            // Arrange
            ArtistDataDto[] result =
            {
                new ArtistDataDto
                {
                    Id      = 1,
                    Name    = "Test",
                    Picture = "",
                },
                new ArtistDataDto
                {
                    Id      = 2,
                    Name    = "Test 2",
                    Picture = "test2.mp3",
                },
            };
            var artitRepoMock = new Mock <IArtistRepository>();

            artitRepoMock.Setup(mock => mock.GetAllArtistsAsync(0, 4))
            .ReturnsAsync(result)
            .Verifiable();

            var albumCollection = new ArtistCollection(artitRepoMock.Object, _dependencyMapper);

            // Act
            var artists = (await albumCollection.GetAllArtistsAsync(0, 4)).ToArray();

            // Assert
            artitRepoMock.Verify();
            Assert.AreEqual(2, artists.Length);
            for (int i = 0; i < 2; ++i)
            {
                Assert.AreEqual(result[i].Id, artists[i].Id);
                Assert.AreEqual(result[i].Name, artists[i].Name);
                Assert.AreEqual(result[i].Picture, artists[i].Picture);
            }
        }
        private ArtistCollection GetArtistCollectionRow(string row)
        {
            try
            {
                var replace = row.Replace("\u0002", "");
                var strings = replace.Split('\x01');

                var artistCollection = new ArtistCollection
                {
                    ExportDate      = strings.ElementAtOrDefault(0) != null ? strings[0] : string.Empty,
                    ArtistId        = long.Parse(strings[1]),
                    CollectionId    = long.Parse(strings[2]),
                    IsPrimaryArtist = strings.ElementAtOrDefault(3) != null ? strings[3] : string.Empty,
                    RoleId          = strings.ElementAtOrDefault(4) != null ? strings[4] : string.Empty,
                };

                return(artistCollection);
            }
            catch (IndexOutOfRangeException)
            {
                return(null);
            }
        }
Exemplo n.º 32
0
 public InitLls(SongCollection sc01, AlbumCollection alc01, ArtistCollection arc01)
 {
     this.sc01 = sc01;
     this.alc01 = alc01;
     this.arc01 = arc01;
 }
Exemplo n.º 33
0
        public SearchResult Find(string query, int maxResults, int page)
        {
            // Find songs
            DataSet tracksResult = MakeDataSet("SELECT * FROM track,artist, release WHERE artist.id = track.artist AND track.album = release.id AND (track.title LIKE '%" + query + "%' OR track.title LIKE '%%') AND (release.title LIKE '%" + query + "%' OR release.title LIKE '%%') AND (artist.title LIKE '%" + query + "%' OR artist.title = '%%')");
            SearchResult sr = new SearchResult(this);
            sr.Tracks = new TrackCollection(this, sr, new List<Track>());
            foreach (DataRow dr in tracksResult.Tables[0].Rows)
            {

                sr.Tracks.Add(TrackFromDataRow(dr));
            }

            // Find artists
            DataSet artistsResult = MakeDataSet("SELECT * FROM artist WHERE title LIKE '%" + query + "%'");
            ArtistCollection ac = new ArtistCollection(this, new List<Artist>());
            foreach (DataRow dr in artistsResult.Tables[0].Rows)
            {
                ac.Add(ArtistFromDataSet(dr));
            }
            sr.Artists = ac;

            // Find albums
            DataSet albumsResult = MakeDataSet("SELECT * FROM release, artist WHERE artist.id = release.artist AND release.title LIKE '%" + query + "%'");
            ReleaseCollection rc = new ReleaseCollection(this, new List<Release>());
            foreach (DataRow dr in albumsResult.Tables[0].Rows)
            {
                rc.Add(ReleaseFromDataRow(dr));
            }
            sr.Albums = rc;
            return sr;
        }