Esempio n. 1
0
		public CompleteResponse Complete(Lang lang, string q, int limit = 1)
		{
			RestRequest request = new RestRequest("complete");
			request.AddParameter("key", _key);
			request.AddParameter("lang", lang.ToString().ToLowerInvariant());
			request.AddParameter("q", q);
			request.AddParameter("limit", limit);

			RestResponse response = (RestResponse)_client.Execute(request);
			XmlAttributeDeserializer deserializer = new XmlAttributeDeserializer();
			if (response.StatusCode == System.Net.HttpStatusCode.OK)
			{
				var completeResponse = deserializer.Deserialize<CompleteResponse>(response);
				return completeResponse;
			}
			else
			{
				if (response.StatusCode != 0)
				{
					var error = deserializer.Deserialize<YandexError>(response);
					throw new YandexLinguisticsException(error);
				}
				else
				{
					throw new YandexLinguisticsException(0, response.ErrorMessage);
				}
			}
		}
        public void Can_Deserialize_To_Standalone_List_Without_Matching_Class_Case()
        {
            string xmlpath = this.PathFor("InlineListSample.xml");
            XDocument doc = XDocument.Load(xmlpath);
            XmlAttributeDeserializer xml = new XmlAttributeDeserializer();
            List<Image> output = xml.Deserialize<List<Image>>(new RestResponse { Content = doc.ToString() });

            Assert.IsNotEmpty(output);
            Assert.AreEqual(4, output.Count);
        }
        public void Can_Deserialize_To_Standalone_List_With_Matching_Class_Case()
        {
            var xmlpath = PathFor("InlineListSample.xml");
            var doc = XDocument.Load(xmlpath);
            var xml = new XmlAttributeDeserializer();
            var output = xml.Deserialize<List<image>>(new RestResponse { Content = doc.ToString() });

            Assert.NotEmpty(output);
            Assert.Equal(4, output.Count);
        }
        public void Can_Deserialize_To_List_Inheritor_From_Custom_Root_With_Attributes()
        {
            string xmlpath = this.PathFor("ListWithAttributes.xml");
            XDocument doc = XDocument.Load(xmlpath);
            XmlAttributeDeserializer xml = new XmlAttributeDeserializer { RootElement = "Calls" };
            TwilioCallList output = xml.Deserialize<TwilioCallList>(new RestResponse { Content = doc.ToString() });

            Assert.AreEqual(3, output.NumPages);
            Assert.IsNotEmpty(output);
            Assert.AreEqual(2, output.Count);
        }
Esempio n. 5
0
        public void Can_Deserialize_artistGetPastEvents()
        {
            var xmlpath = Environment.CurrentDirectory + @"\..\..\..\Lastfm.Tests\Responses\Artist\artistGetPastEvents.xml";
            var doc = XDocument.Load(xmlpath);
            var response = new RestResponse { Content = doc.ToString() };

            var d = new XmlAttributeDeserializer();
            var output = d.Deserialize<LastfmResponse<EventsList>>(response);

            Assert.AreEqual("Blur", output.Value.Events[2].Headliner);
        }
        public void Can_Deserialize_Boolean_From_Number()
        {
            var xmlpath = PathFor("boolean_from_number.xml");
                var doc = XDocument.Load(xmlpath);
                var response = new RestResponse { Content = doc.ToString() };

                var d = new XmlAttributeDeserializer();
                var output = d.Deserialize<SampleClasses.BooleanTest>(response);

                Assert.True(output.Value);
        }
        public void Can_Deserialize_POI()
        {
            var xmlpath = Environment.CurrentDirectory + @"\..\..\..\LonelySharp.Tests\Responses\POI_Details.xml";
            var doc = XDocument.Load(xmlpath);
            var response = new RestResponse { Content = doc.ToString() };

            var d = new XmlAttributeDeserializer();
            var output = d.Deserialize<POI>(response);

            Assert.AreEqual(output.Name, "Alhambra Lounge");
            Assert.AreEqual(output.Urls[0].Value, "www.alhambralounge.com");
        }
        public void Can_Deserialize_Place_Listing()
        {
            var xmlpath = Environment.CurrentDirectory + @"\..\..\..\LonelySharp.Tests\Responses\Places_List.xml";
            var doc = XDocument.Load(xmlpath);
            var response = new RestResponse { Content = doc.ToString() };

            var d = new XmlAttributeDeserializer();
            var output = d.Deserialize<PlaceCollection>(response);

            Assert.AreEqual(output[0].Fullname, "Australia & Pacific -> Australia -> Queensland -> Brisbane");
            Assert.AreEqual(output[0].Northlatitude, -27.434999);
        }
        public void Can_Deserialize_Lists_of_Simple_Types()
        {
            var xmlpath = PathFor("xmllists.xml");
            var doc = XDocument.Load(xmlpath);
            var xml = new XmlAttributeDeserializer();
            var output = xml.Deserialize<SimpleTypesListSample>(new RestResponse() { Content = doc.ToString() });

            Assert.NotEmpty(output.Names);
            Assert.NotEmpty(output.Numbers);
            Assert.False(output.Names[0].Length == 0);
            Assert.False(output.Numbers.Sum() == 0);
        }
Esempio n. 10
0
        public void Can_Deserialize_artistGetImages()
        {
            var xmlpath = Environment.CurrentDirectory + @"\..\..\..\Lastfm.Tests\Responses\Artist\artistGetImages.xml";
            var doc = XDocument.Load(xmlpath);
            var response = new RestResponse { Content = doc.ToString() };

            var d = new XmlAttributeDeserializer();
            var output = d.Deserialize<LastfmResponse<ImageList>>(response);

            Assert.AreEqual(50, output.Value.images.Count);

            Assert.AreEqual("VanderWaals", output.Value.images[1].owner.name);
            Assert.AreEqual(6, output.Value.images[1].sizes.Count);
        }
Esempio n. 11
0
        public void Can_Deserialize_artistGetInfo()
        {
            var xmlpath = Environment.CurrentDirectory + @"\..\..\..\Lastfm.Tests\Responses\Artist\artistGetInfo.xml";
            var doc = XDocument.Load(xmlpath);
            var response = new RestResponse { Content = doc.ToString() };

            var d = new XmlAttributeDeserializer();
            var output = d.Deserialize<LastfmResponse<Artist>>(response);

            Assert.AreEqual("Blur", output.Value.Name);
            Assert.AreEqual(5, output.Value.similar.Count);
            Assert.AreEqual("http://www.last.fm/music/Blur", output.Value.Url);
            Assert.AreEqual("ba853904-ae25-4ebb-89d6-c44cfbd71bd2", output.Value.MusicBrainzID);
        }
Esempio n. 12
0
		public Lang[] GetLangs()
		{
			RestRequest request = new RestRequest("getLangs");
			request.AddParameter("key", _key);

			RestResponse response = (RestResponse)_client.Execute(request);
			XmlAttributeDeserializer deserializer = new XmlAttributeDeserializer();
			if (response.StatusCode == System.Net.HttpStatusCode.OK)
			{
				var strs = deserializer.Deserialize<List<string>>(response);
				var allLangs = (Lang[])Enum.GetValues(typeof(Lang));
				Lang[] result = allLangs.Where(lang => strs.Contains(lang.ToString().ToLowerInvariant())).ToArray();
				return result;
			}
			else
			{
				var error = deserializer.Deserialize<YandexError>(response);
				throw new YandexLinguisticsException(error);
			}
		}
        public void Can_Deserialize_Attributes_On_Default_Root()
        {
            var doc = CreateAttributesXml();
            var response = new RestResponse { Content = doc };

            var d = new XmlAttributeDeserializer();
            var p = d.Deserialize<PersonForXml>(response);

            Assert.Equal("John Sheehan", p.Name);
            Assert.Equal(new DateTime(2009, 9, 25, 0, 6, 1), p.StartDate);
            Assert.Equal(28, p.Age);
            Assert.Equal(long.MaxValue, p.BigNumber);
            Assert.Equal(99.9999m, p.Percent);
            Assert.Equal(false, p.IsCool);
            Assert.Equal(new Guid(GuidString), p.UniqueId);
            Assert.Equal(new Uri("http://example.com", UriKind.RelativeOrAbsolute), p.Url);
            Assert.Equal(new Uri("/foo/bar", UriKind.RelativeOrAbsolute), p.UrlPath);

            Assert.NotNull(p.BestFriend);
            Assert.Equal("The Fonz", p.BestFriend.Name);
            Assert.Equal(1952, p.BestFriend.Since);
        }
        public void Can_Deserialize_TimeSpan()
        {
            var culture = CultureInfo.InvariantCulture;
            var doc = new XDocument(culture);

            TimeSpan? nullTimespan = null;
            TimeSpan? nullValueTimeSpan = new TimeSpan(21, 30, 7);

            var root = new XElement("Person");
            root.Add(new XElement("Tick", new TimeSpan(468006)));
            root.Add(new XElement("Millisecond", new TimeSpan(0, 0, 0, 0, 125)));
            root.Add(new XElement("Second", new TimeSpan(0, 0, 8)));
            root.Add(new XElement("Minute", new TimeSpan(0, 55, 2)));
            root.Add(new XElement("Hour", new TimeSpan(21, 30, 7)));
            root.Add(new XElement("NullableWithoutValue", nullTimespan));
            root.Add(new XElement("NullableWithValue", nullValueTimeSpan));

            doc.Add(root);

            var response = new RestResponse { Content = doc.ToString() };

            var d = new XmlAttributeDeserializer()
            {
                Culture = culture,
            };
            var payload = d.Deserialize<TimeSpanTestStructure>(response);
            Assert.Equal(new TimeSpan(468006), payload.Tick);
            Assert.Equal(new TimeSpan(0, 0, 0, 0, 125), payload.Millisecond);
            Assert.Equal(new TimeSpan(0, 0, 8), payload.Second);
            Assert.Equal(new TimeSpan(0, 55, 2), payload.Minute);
            Assert.Equal(new TimeSpan(21, 30, 7), payload.Hour);
            Assert.Null(payload.NullableWithoutValue);
            Assert.NotNull(payload.NullableWithValue);
            Assert.Equal(new TimeSpan(21, 30, 7), payload.NullableWithValue.Value);
        }
        public void Can_Deserialize_Root_Elements_Without_Matching_Case_And_Dashes()
        {
            var doc = CreateLowerCasedRootElementWithDashesXml();
            var response = new RestResponse { Content = doc };

            var d = new XmlAttributeDeserializer();
            var p = d.Deserialize<List<IncomingInvoice>>(response);

            Assert.NotNull(p);
            Assert.Equal(1, p.Count);
            Assert.Equal(45, p[0].ConceptId);
        }
        public void Can_Deserialize_Nested_List_Without_Elements_To_Empty_List()
        {
            var doc = CreateXmlWithEmptyNestedList();

            var xml = new XmlAttributeDeserializer();
            var output = xml.Deserialize<EmptyListSample>(new RestResponse { Content = doc });

            Assert.NotNull(output.images);
            Assert.NotNull(output.Images);
            Assert.Empty(output.images);
            Assert.Empty(output.Images);
        }
        public void Can_Deserialize_Mixture_Of_Empty_Elements_With_Attributes_And_Populated_Elements()
        {
            var doc = CreateXmlWithAttributesAndNullValuesAndPopulatedValues();

            var xml = new XmlAttributeDeserializer();
            var output = xml.Deserialize<NullableValues>(new RestResponse {Content = doc});

            Assert.Null(output.Id);
            Assert.Null(output.StartDate);
            Assert.Equal(new Guid(GuidString), output.UniqueId);
        }
        public void Can_Deserialize_Lastfm_Xml()
        {
            var xmlpath = PathFor("Lastfm.xml");
            var doc = XDocument.Load(xmlpath);
            var response = new RestResponse { Content = doc.ToString() };

            var d = new XmlAttributeDeserializer();
            var output = d.Deserialize<SampleClasses.Lastfm.Event>(response);

            //Assert.NotEmpty(output.artists);
            Assert.Equal("http://www.last.fm/event/328799+Philip+Glass+at+Barbican+Centre+on+12+June+2008", output.url);
            Assert.Equal("http://www.last.fm/venue/8777860+Barbican+Centre", output.venue.url);
        }
        public void Can_Deserialize_POI_List()
        {
            var xmlpath = Environment.CurrentDirectory + @"\..\..\..\LonelySharp.Tests\Responses\POI_List.xml";
            var doc = XDocument.Load(xmlpath);
            var response = new RestResponse { Content = doc.ToString() };

            var d = new XmlAttributeDeserializer();
            var output = d.Deserialize<POICollection>(response);

            Assert.AreEqual(output[0].ID, 1077533);
            Assert.AreEqual(output[0].POIType.ToString(), "Eat");
            Assert.AreEqual(output.Count, 222);
        }
        public void Can_Deserialize_Google_Weather_Xml()
        {
            var xmlpath = PathFor("GoogleWeather.xml");
            var doc = XDocument.Load(xmlpath);
            var response = new RestResponse { Content = doc.ToString() };

            var d = new XmlAttributeDeserializer();
            var output = d.Deserialize<SampleClasses.xml_api_reply>(response);

            Assert.NotEmpty(output.weather);
            Assert.Equal(4, output.weather.Count);
            Assert.Equal("Sunny", output.weather[0].condition.data);
        }
        public void Can_Deserialize_Eventful_Xml()
        {
            var xmlpath = PathFor("eventful.xml");
            var doc = XDocument.Load(xmlpath);
            var response = new RestResponse { Content = doc.ToString() };

            var d = new XmlAttributeDeserializer();
            var output = d.Deserialize<SampleClasses.VenueSearch>(response);

            Assert.NotEmpty(output.venues);
            Assert.Equal(3, output.venues.Count);
            Assert.Equal("Tivoli", output.venues[0].name);
            Assert.Equal("http://eventful.com/brisbane/venues/tivoli-/V0-001-002169294-8", output.venues[1].url);
            Assert.Equal("V0-001-000266914-3", output.venues[2].id);
        }
        public void Can_Deserialize_Empty_Elements_With_Attributes_to_Nullable_Values()
        {
            var doc = CreateXmlWithAttributesAndNullValues();

            var xml = new XmlAttributeDeserializer();
            var output = xml.Deserialize<NullableValues>(new RestResponse {Content = doc});

            Assert.Null(output.Id);
            Assert.Null(output.StartDate);
            Assert.Null(output.UniqueId);
        }
        public void Can_Deserialize_Custom_Formatted_Date()
        {
            var culture = CultureInfo.InvariantCulture;
            var format = "dd yyyy MMM, hh:mm ss tt zzz";
            var date = new DateTime(2010, 2, 8, 11, 11, 11);

            var doc = new XDocument();

            var root = new XElement("Person");
            root.Add(new XElement("StartDate", date.ToString(format, culture)));

            doc.Add(root);

            var xml = new XmlAttributeDeserializer
            {
                DateFormat = format,
                Culture = culture
            };

            var response = new RestResponse { Content = doc.ToString() };
            var output = xml.Deserialize<PersonForXml>(response);

            Assert.Equal(date, output.StartDate);
        }
        public void Can_Deserialize_DateTimeOffset()
        {
            var culture = CultureInfo.InvariantCulture;
            var doc = new XDocument(culture);

            DateTimeOffset DateTimeOffset = new DateTimeOffset(2013, 02, 08, 9, 18, 22, TimeSpan.FromHours(10));
            DateTimeOffset? NullableDateTimeOffsetWithValue = new DateTimeOffset(2013, 02, 08, 9, 18, 23, TimeSpan.FromHours(10));

            var root = new XElement("Dates");
            root.Add(new XElement("DateTimeOffset", DateTimeOffset));
            root.Add(new XElement("NullableDateTimeOffsetWithNull", string.Empty));
            root.Add(new XElement("NullableDateTimeOffsetWithValue", NullableDateTimeOffsetWithValue));

            doc.Add(root);

            var xml = new XmlAttributeDeserializer
            {
                Culture = culture,
            };

            var response = new RestResponse { Content = doc.ToString() };

            var d = new XmlAttributeDeserializer()
            {
                Culture = culture,
            };
            var payload = d.Deserialize<DateTimeTestStructure>(response);
            Assert.Equal(DateTimeOffset, payload.DateTimeOffset);
            Assert.Null(payload.NullableDateTimeOffsetWithNull);

            Assert.True(payload.NullableDateTimeOffsetWithValue.HasValue);
            Assert.Equal(NullableDateTimeOffsetWithValue, payload.NullableDateTimeOffsetWithValue);
        }
        public void Ignore_ReadOnly_Property_That_Exists_In_Data()
        {
            var doc = CreateElementsXml();
            var response = new RestResponse { Content = doc };

            var d = new XmlAttributeDeserializer();
            var p = d.Deserialize<PersonForXml>(response);

            Assert.Null(p.ReadOnlyProxy);
        }
        public void Can_Deserialize_Google_Weather_Xml_WithDeserializeAs()
        {
            var xmlpath = PathFor("GoogleWeather.xml");
            var doc = XDocument.Load(xmlpath);
            var response = new RestResponse { Content = doc.ToString() };

            var d = new XmlAttributeDeserializer();
            var output = d.Deserialize<GoogleWeatherApi>(response);

            Assert.NotEmpty(output.Weather);
            Assert.Equal(4, output.Weather.Count);
            Assert.Equal("Sunny", output.Weather[0].Condition.Data);
        }
        public void Can_Deserialize_Directly_To_Lists_Off_Root_Element()
        {
            var xmlpath = PathFor("directlists.xml");
            var doc = XDocument.Load(xmlpath);

            var xml = new XmlAttributeDeserializer();
            var output = xml.Deserialize<List<Database>>(new RestResponse { Content = doc.ToString() });

            Assert.NotEmpty(output);
            Assert.Equal(2, output.Count);
        }
        public void Can_Deserialize_Nested_Class()
        {
            var doc = CreateElementsXml();
            var response = new RestResponse { Content = doc };
            var d = new XmlAttributeDeserializer();
            var p = d.Deserialize<PersonForXml>(response);

            Assert.NotNull(p.FavoriteBand);
            Assert.Equal("Goldfinger", p.FavoriteBand.Name);
        }
Esempio n. 29
0
        public void Can_Deserialize_Parentless_aka_Inline_List_Items_With_Matching_Class_Name_Using_XmlAttributeDeserializer()
        {
            var xmlpath = PathFor("InlineListSample.xml");
            var doc = XDocument.Load(xmlpath);

            var xml = new XmlAttributeDeserializer();
            var output = xml.Deserialize<InlineListSample>(new RestResponse { Content = doc.ToString() });

            Assert.NotEmpty(output.images);
            Assert.Equal(4, output.images.Count);
        }
        public void Can_Deserialize_Elements_to_Nullable_Values()
        {
            var culture = CultureInfo.InvariantCulture;
            var doc = CreateXmlWithoutEmptyValues(culture);
            var xml = new XmlAttributeDeserializer() {Culture = culture};
            var output = xml.Deserialize<NullableValues>(new RestResponse { Content = doc });

            Assert.NotNull(output.Id);
            Assert.NotNull(output.StartDate);
            Assert.NotNull(output.UniqueId);

            Assert.Equal(123, output.Id);
            Assert.Equal(new DateTime(2010, 2, 21, 9, 35, 00), output.StartDate);
            Assert.Equal(new Guid(GuidString), output.UniqueId);
        }