예제 #1
0
        public void GetShow()
        {
            // Pull XML tree trough the show builder
            var builder = new Builder(_dataProvider);

            var showId = int.Parse(_data.GetShowData().Keys.First(x => x.XmlValue == "id").XmlValue);
            var result = builder.BuildShow(showId);

            var showData    = _data.GetShowData();
            var episodeData = _data.GetEpisodeData();

            // Assert equality between value conversions for show data
            foreach (var key in showData.Keys)
            {
                var prop = result.GetType().GetProperty(key.ObjValue);
                Assert.IsTrue(prop.GetValue(result).ToString() == showData[key].ObjValue,
                              "!Show object! Property: " + prop.Name + " ;Actual object value: " + prop.GetValue(result) +
                              " ;Expected value: " + showData[key].ObjValue);
            }

            // Assert equality between value conversion for episode data
            for (var i = 0; i < result.Episodes.Count; i++)
            {
                var currentEpisode = result.Episodes[i];
                var dic            = episodeData[i];

                foreach (var key in dic.Keys)
                {
                    var prop = currentEpisode.GetType().GetProperty(key.ObjValue);

                    // Checks whether or not we're dealing with a list
                    // ToString() method on lists will not show the values and are therefore not suited for comparison
                    // That's why we manually check the entries
                    if (new List <string> {
                        "Actors", "Genres", "GuestStars", "Writers"
                    }.Contains(key.ObjValue))
                    {
                        foreach (var entry in dic[key].XmlValue.Split('|'))
                        {
                            Assert.IsTrue(((List <string>)prop.GetValue(currentEpisode)).Contains(entry),
                                          "!List object! Property: " + prop.Name + " ;Actual object value: " +
                                          string.Join(", ", (List <string>)prop.GetValue(currentEpisode)) + ";Expected value: " +
                                          dic[key].XmlValue);
                        }
                    }

                    var value    = prop.GetValue(currentEpisode).ToString();
                    var expected = dic[key].ObjValue;
                    Assert.IsTrue(value == expected,
                                  "!Episode object! Property: " + prop.Name + " ;Actual object value: " +
                                  prop.GetValue(currentEpisode) + " ;Expected value: " + dic[key].ObjValue);
                }
            }
        }
예제 #2
0
        public XDocument GetShow(int showID)
        {
            var showData    = _data.GetShowData();
            var episodeData = _data.GetEpisodeData();
            var show        = new Data {
                TestShow = new TestShow()
            };

            // Dynamically create the show object
            foreach (var key in showData.Keys)
            {
                var prop = show.TestShow.GetType().GetProperty(key.XmlValue);
                prop.SetValue(show.TestShow, showData[key].XmlValue, null);
            }

            // Add episodes to the show object
            show.TestShow.Episodes = new List <TestEpisode>();
            foreach (var ep in episodeData)
            {
                var newEpisode = new TestEpisode();

                foreach (var key in ep.Keys)
                {
                    var prop = newEpisode.GetType().GetProperty(key.XmlValue);
                    prop.SetValue(newEpisode, ep[key].XmlValue, null);
                }

                show.TestShow.Episodes.Add(newEpisode);
            }

            // Pull the created object trough an XML serializer
            var    serializer = new XmlSerializer(show.GetType());
            string xml;

            using (var writer = new StringWriter())
            {
                serializer.Serialize(writer, show);
                xml = writer.ToString();
            }

            return(XDocument.Parse(xml));
        }