Пример #1
0
        public void GivenThreeShouldReturnTheExpectedItems()
        {
            var media1 = new WmpMedia("artist1", "album1", "title", "", "", "", "", "", @"C:\Data\sample.file",
                                      "123.456", "320001");
            var media2 = new WmpMedia("artist2", "album2", "title", "0", "4/1/2009 4:17:32 PM", "0",
                                      "4/1/2010 4:17:32 PM", "", @"C:\Data\sample.file", "123.456", "320002");
            var media3 = new WmpMedia("artist3", "album3", "title", "50", "4/1/2009 4:17:32 PM", "42", "", "Genre",
                                      @"C:\Data\sample.file", "123.456", "320003");
            IEnumerable<WmpMedia> media = new[] { media1, media2, media3 };
            var input = new WmpMediaCollection("12.0.7600.16415", media);

            var expected1 = new Item("artist1", "album1", "title", null, null, null, null, null, @"C:\Data\sample.file",
                                     TimeSpan.FromSeconds(123.456), 320001);
            var expected2 = new Item("artist2", "album2", "title", null, new DateTime(2009, 4, 1, 16, 17, 32), 0,
                                     new DateTime(2010, 4, 1, 16, 17, 32), null, @"C:\Data\sample.file",
                                     TimeSpan.FromSeconds(123.456), 320002);
            var expected3 = new Item("artist3", "album3", "title", 0.6, new DateTime(2009, 4, 1, 16, 17, 32), 42, null,
                                     "Genre", @"C:\Data\sample.file", TimeSpan.FromSeconds(123.456), 320003);

            var library = WindowsMediaPlayerImporter.ImportLibrary(input);
            var results = library.Items.ToArray();

            Assert.AreEqual(expected1, results[0]);
            Assert.AreEqual(expected2, results[1]);
            Assert.AreEqual(expected3, results[2]);
        }
        private static Item GetItem(WmpMedia wmpMedia)
        {
            string artist = ImportString(wmpMedia.DisplayArtist);
            string album = ImportString(wmpMedia.Album);
            string title = ImportString(wmpMedia.Title);
            double? rating = ImportRating(wmpMedia.UserRating);
            DateTime? dateAdded = ImportDateTime(wmpMedia.AcquisitionTime);
            int? playCount = ImportNullableInt32(wmpMedia.UserPlayCount);
            DateTime? lastPlayed = ImportDateTime(wmpMedia.UserLastPlayedTime);
            string genre = ImportString(wmpMedia.WmGenre);
            string location = ImportString(wmpMedia.SourceUrl);
            TimeSpan? duration = ImportDuration(wmpMedia.Duration);
            int? bitsPerSecond = ImportNullableInt32(wmpMedia.Bitrate);

            return new Item(artist, album, title, rating, dateAdded, playCount, lastPlayed, genre, location, duration,
                            bitsPerSecond);
        }