コード例 #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
 public void HashCodeCanBeRetrievedWhenIdIsNull()
 {
     Product product = new Product();
     Assert.IsNotNull(product.GetHashCode(), "Expected a hash code");
 }
コード例 #5
0
 public void TestShowGoesAheadWhenItCan()
 {
     Product product = new Product() { Id = TestId };
     product.Show();
     Assert.Pass();
 }
コード例 #6
0
 public void TestIdPropertyIsRequiredForShow()
 {
     Product product = new Product();
     product.Show();
 }
コード例 #7
0
        /// <summary>
        /// Creates a Product from a JSON Object
        /// </summary>
        /// <param name="item">The item.</param>
        /// <returns>A Product object</returns>
        internal static Product FromJToken(JToken item)
        {
            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));
                }

                genres = list.ToArray();
            }

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

            // 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));
                    }

                    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["moviedirectornames"] != null)
            {
                ParseArray(item, musicDirectorNames, "musicdirectornames");
            }

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

            // 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,
                Category = category,
                Genres = genres,
                TakenFrom = takenFrom,
                Price = price,
                TrackCount = trackCount,
                Tracks = ExtractTracks(item["tracks"]),
                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
            };

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

            return product;
        }