예제 #1
0
 public void TestOverrides()
 {
     Product product = new Product() { Id = TestId, Name = TestName };
     Assert.IsNotNull(product.GetHashCode(), "Expected a hash code");
     Assert.IsTrue(product.Equals(new Product() { Id = TestId }), "Expected equality");
     Assert.IsFalse(product.Equals(TestId), "Expected inequality");
 }
예제 #2
0
        public void TestProperties()
        {
            Product product = new Product() { Id = TestId, Name = TestName };

            Assert.AreEqual(TestId, product.Id, "Expected the property to persist");
            Assert.AreEqual(TestName, product.Name, "Expected the property to persist");
        }
예제 #3
0
        public void TestLinkingProperties()
        {
            var item = new Product() { Id = TestId };
            var itemWithNullId = new Product();

            Assert.IsNotNull(item.AppToAppUri, "Expected App to App URI to be calculated");
            Assert.IsNull(itemWithNullId.AppToAppUri, "Expected App to App URI not to be calculated");

            Assert.IsNotNull(item.WebUri, "Expected Web URI to be calculated");
            Assert.IsNull(itemWithNullId.WebUri, "Expected Web URI not to be calculated");
        }
예제 #4
0
 /// <summary>
 /// Shows the Product Page in MixRadio
 /// </summary>
 /// <returns>An async task to await</returns>
 public async Task Show()
 {
     if (!string.IsNullOrEmpty(this.ProductId))
     {
         var product = new Product { Id = this.ProductId };
         await this.Launch(product.AppToAppUri, product.WebUri).ConfigureAwait(false);
     }
     else
     {
         throw new InvalidOperationException("Please set a product ID before calling Show()");
     }
 }
예제 #5
0
        /// <summary>
        /// Creates a Product from a JSON Object
        /// </summary>
        /// <param name="item">The item.</param>
        /// <param name="settings">The settings.</param>
        /// <returns>
        /// A Product object
        /// </returns>
        internal static Product FromJToken(JToken item, IMusicClientSettings settings)
        {
            if (item == null)
            {
                return null;
            }

            // Extract category...
            Category category = Category.Unknown;
            JToken jsonCategory = item["category"];
            if (jsonCategory != null)
            {
                category = ParseHelper.ParseEnumOrDefault<Category>(jsonCategory.Value<string>("id"));
            }

            // Extract genres...
            Genre[] genres = null;
            JArray jsonGenres = item.Value<JArray>("genres");
            if (jsonGenres != null)
            {
                List<Genre> list = new List<Genre>();
                foreach (JToken jsonGenre in jsonGenres)
                {
                    list.Add((Genre)Genre.FromJToken(jsonGenre, settings));
                }

                genres = list.ToArray();
            }

            // Extract takenfrom... 
            Product takenFrom = null;
            JToken jsonTakenFrom = item["takenfrom"];
            if (jsonTakenFrom != null)
            {
                takenFrom = (Product)FromJToken(jsonTakenFrom, settings);
            }

            // Extract price...
            Price price = null;
            JToken jsonPrices = item["prices"];
            if (jsonPrices != null)
            {
                JToken jsonPermDownload = jsonPrices["permanentdownload"];
                if (jsonPermDownload != null)
                {
                    price = Price.FromJToken(jsonPermDownload);
                }
            }

            // Extract Artists...
            Artist[] performers = null;

            if (item["creators"] != null)
            {
                JArray jsonArtists = item["creators"].Value<JArray>("performers")
                                     ?? item["creators"].Value<JArray>("composers");

                if (jsonArtists != null)
                {
                    List<Artist> list = new List<Artist>();
                    foreach (JToken jsonArtist in jsonArtists)
                    {
                        list.Add((Artist)Artist.FromJToken(jsonArtist, settings));
                    }

                    performers = list.ToArray();
                }
            }

            // Extract trackcount... 
            int? trackCount = null;
            JToken jsonTrackCount = item["trackcount"];
            if (jsonTrackCount != null)
            {
                trackCount = item.Value<int>("trackcount");
            }

            // Extract thumbnails...
            Uri square50 = null;
            Uri square100 = null;
            Uri square200 = null;
            Uri square320 = null;

            MusicItem.ExtractThumbs(item["thumbnails"], out square50, out square100, out square200, out square320);

            // Extract Bollywood information
            var actorNames = new List<string>();

            if (item["actornames"] != null)
            {
                ParseArray(item, actorNames, "actornames");
            }

            var lyricistNames = new List<string>();
            if (item["lyricistnames"] != null)
            {
                ParseArray(item, lyricistNames, "lyricistnames");
            }

            var singerNames = new List<string>();
            if (item["singernames"] != null)
            {
                ParseArray(item, singerNames, "singernames");
            }

            var movieDirectorNames = new List<string>();
            if (item["moviedirectornames"] != null)
            {
                ParseArray(item, movieDirectorNames, "moviedirectornames");
            }

            var movieProducerNames = new List<string>();
            if (item["movieproducernames"] != null)
            {
                ParseArray(item, movieProducerNames, "movieproducernames");
            }

            var musicDirectorNames = new List<string>();
            if (item["musicdirectornames"] != null)
            {
                ParseArray(item, musicDirectorNames, "musicdirectornames");
            }

            var parentalAdvisory = item.Value<bool>("parentaladvisory");

            // Extract bpm... 
            int bpm = 0;
            if (item["bpm"] != null)
            {
                bpm = item.Value<int>("bpm");
            }

            // Derive 640 thumb
            Uri square640 = null;
            if (square320 != null)
            {
                square640 = new Uri(square320.ToString().Replace("w=320", "w=640"));
            }

            // Create the resulting Product object...
            var product = new Product()
            {
                Id = item.Value<string>("id"),
                Name = item.Value<string>("name"),
                Thumb50Uri = square50,
                Thumb100Uri = square100,
                Thumb200Uri = square200,
                Thumb320Uri = square320,
                Thumb640Uri = square640,
                Category = category,
                Genres = genres,
                TakenFrom = takenFrom,
                Price = price,
                TrackCount = trackCount,
                Tracks = ExtractTracks(item["tracks"], settings),
                Performers = performers,
                Duration = item.Value<int?>("duration"),
                VariousArtists = item.Value<bool>("variousartists"),
                StreetReleaseDate = item.Value<DateTime>("streetreleasedate"),
                SellerStatement = item.Value<string>("sellerstatement"),
                Label = item.Value<string>("label"),
                ActorNames = actorNames,
                LyricistsNames = lyricistNames,
                SingerNames = singerNames,
                MovieDirectorNames = movieDirectorNames,
                MovieProducerNames = movieProducerNames,
                MusicDirectorNames = musicDirectorNames,
                ParentalAdvisory = parentalAdvisory,
                Bpm = bpm
            };

            var sequence = item.Value<int>("sequence");
            if (sequence >= 1)
            {
                product.Sequence = sequence;
            }

            return product;
        }
예제 #6
0
 public void HashCodeCanBeRetrievedWhenIdIsNull()
 {
     Product product = new Product();
     Assert.IsNotNull(product.GetHashCode(), "Expected a hash code");
 }