public void DeserializationWorks_WhenPassedRightXML() {
            var xmlpath = Path.Combine(Environment.CurrentDirectory,"ResponseJobSearch.xml");
            var doc = XDocument.Load(xmlpath);

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

            Assert.IsNotNull(output.Results);
            Assert.AreEqual(25, output.Results.Count);
            Assert.AreEqual("Direct Sales Recruiting, LLC", output.Results[0].Company);
            Assert.AreEqual("c35x165rs82x1bnbbc", output.Results[0].CompanyDID);
            Assert.AreEqual("http://www.careerbuilder.com/Jobs/Company/C35X165RS82X1BNBBC/Direct-Sales-Recruiting-LLC/?sc_cmp1=13_JobRes_ComDet", output.Results[0].CompanyDetailsURL);
            Assert.AreEqual("JHM0LH6LPCGLF3FR3ZB", output.Results[0].DID);
            Assert.AreEqual("41-4011.00", output.Results[0].OnetCode);
            Assert.AreEqual("Full-Time", output.Results[0].EmploymentType);
            Assert.AreEqual("http://api.careerbuilder.com/v1/joblink?TrackingID=DLR0T71H&DID=JHM0LH6LPCGLF3FR3ZB", output.Results[0].JobDetailsURL);
            Assert.AreEqual("http://api.careerbuilder.com/v1/job?DID=JHM0LH6LPCGLF3FR3ZB&DeveloperKey=WXXXXXXXXXXXXXXXXXX", output.Results[0].JobServiceURL);
            Assert.AreEqual("TN - Chattanooga", output.Results[0].Location);
            Assert.AreEqual(35.04644f, output.Results[0].LocationLatitude);
            Assert.AreEqual(-85.30946f, output.Results[0].LocationLongitude);
            Assert.AreEqual("10/28/2012", output.Results[0].PostedDate);
            Assert.AreEqual("$70k - $80k/year", output.Results[0].Pay);
            Assert.AreEqual("http://www.careerbuilder.com/jobseeker/jobs/recommendedjobs.aspx?ipath=JELO&job_did=JHM0LH6LPCGLF3FR3ZB", output.Results[0].SimilarJobsURL);
            Assert.AreEqual("Medical Sales-Tissue Graft/Biologics-Wound Care", output.Results[0].JobTitle);
            Assert.AreEqual("http://emj.icbdr.com/MediaManagement/QS/I8F50C63D7B6SGPDXQS.gif", output.Results[0].CompanyImageURL);
            Assert.IsNotNull(output.Facets);
            Assert.AreEqual(0, output.Facets.Count);
        }
コード例 #2
0
        public void TestGraphWithEnumNode()
        {
            Node rootNode = new Node(1);
            Node intNode = new Node(42);
            Node enumNode = new Node(TestEnum.Two);

            rootNode.Nodes.Add(intNode);
            rootNode.Nodes.Add(enumNode);

            intNode.Nodes.Add(rootNode);

            Graph g = new Graph(rootNode);

            XmlSerializer s = new XmlSerializer();
            string result = s.Serialize(g);

            XmlDeserializer d = new XmlDeserializer();
            Graph newGraph = d.Deserialize<Graph>(result);

            Assert.IsNotNull(newGraph);
            Assert.AreEqual(g.Root.Data, newGraph.Root.Data);
            Assert.AreEqual(g.Root.Nodes[0].Data, newGraph.Root.Nodes[0].Data);
            Assert.AreEqual(g.Root.Nodes[1].Data, newGraph.Root.Nodes[1].Data);
            Assert.AreEqual(g.Root.Nodes[0].Nodes[0].Data, newGraph.Root.Nodes[0].Nodes[0].Data);
            Assert.AreSame(newGraph.Root, newGraph.Root.Nodes[0].Nodes[0]);
        }
コード例 #3
0
        public void DeserializationWorks_WhenPassedRightXML() {
            var xmlpath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "testdata","ResponseBlankApplication.xml");
            var doc = XDocument.Load(xmlpath);

            var xml = new XmlDeserializer();
            var output = xml.Deserialize<BlankApplication>(new RestResponse() { Content = doc.ToString() });
            Assert.IsNotNull(output.Questions);
            Assert.AreEqual(4,output.Questions.Count);

            Assert.AreEqual("ApplicantName", output.Questions[0].QuestionID);
            Assert.AreEqual("Basic", output.Questions[0].QuestionType);
            Assert.AreEqual(true, output.Questions[0].IsRequired);
            Assert.AreEqual("Text 50", output.Questions[0].ExpectedResponseFormat);
            Assert.AreEqual("Your name", output.Questions[0].QuestionText);

            Assert.AreEqual("ApplicantEmail", output.Questions[1].QuestionID);
            Assert.AreEqual("Basic", output.Questions[1].QuestionType);
            Assert.AreEqual(true, output.Questions[1].IsRequired);
            Assert.AreEqual("Text 50", output.Questions[1].ExpectedResponseFormat);
            Assert.AreEqual("Your email", output.Questions[1].QuestionText);


            Assert.AreEqual("Resume", output.Questions[2].QuestionID);
            Assert.AreEqual("Basic", output.Questions[2].QuestionType);
            Assert.AreEqual(true, output.Questions[2].IsRequired);
            Assert.AreEqual("Text 5000", output.Questions[2].ExpectedResponseFormat);
            Assert.AreEqual("Your resume", output.Questions[2].QuestionText);

            Assert.AreEqual("CoverLetter", output.Questions[3].QuestionID);
            Assert.AreEqual("Basic", output.Questions[3].QuestionType);
            Assert.AreEqual(false, output.Questions[3].IsRequired);
            Assert.AreEqual("Text 5000", output.Questions[3].ExpectedResponseFormat);
            Assert.AreEqual("Your cover letter", output.Questions[3].QuestionText);
        }
        public void DeserializationWorks_WhenPassedRightXML()
        {
            //using the same XML as SavedSearchCreate since they output the same
            var xmlPath = Path.Combine(Environment.CurrentDirectory, "SaveSearchCreateData.xml");
            var doc = XDocument.Load(xmlPath);

            var xml = new XmlDeserializer();
            var output = xml.Deserialize<SavedSearchRetrieveResponseModel>(new RestResponse() { Content = doc.ToString() });
            Assert.IsNotNull(output, "no deserialization worked");
            Assert.IsNotNull(output.SavedSearch.SavedSearchParameters, "SavedSearchParameters deserialization Did not work");
            Assert.AreEqual("lotsloc", output.SavedSearch.SearchName, "search name did not dezerialize");
            Assert.AreEqual("none", output.SavedSearch.IsDailyEmail.ToLower(), "IsDailyEmail did not dezerialize");
            Assert.AreEqual("Chicago, Il, Atlanta, Ga, New York, Ny", output.SavedSearch.SavedSearchParameters.Location, "Location did not dezerialize");
            Assert.AreEqual(false, output.SavedSearch.SavedSearchParameters.ExcludeNational, "ExcludeNational did not dezerialize");
            Assert.AreEqual("DRNS", output.SavedSearch.SavedSearchParameters.EducationCode, "educationCode did not dezerialize");
            Assert.AreEqual("AND", output.SavedSearch.SavedSearchParameters.BooleanOperator, "booleanoperator did not dezerialize");
            Assert.AreEqual("Pay", output.SavedSearch.SavedSearchParameters.OrderBy, "OrderBy did not dezerialize");
            Assert.AreEqual(70, output.SavedSearch.SavedSearchParameters.PayHigh, "pay high did not dezerialize");
            Assert.AreEqual(40, output.SavedSearch.SavedSearchParameters.PayLow, "Pay Low did not dezerialize");
            Assert.AreEqual(30, output.SavedSearch.SavedSearchParameters.PostedWithin, "posted within did not dezerialize");
            Assert.AreEqual(30, output.SavedSearch.SavedSearchParameters.Radius, "radius did not dezerialize");
            Assert.AreEqual(false, output.SavedSearch.SavedSearchParameters.PayInfoOnly, "pay info only did not dezerialize");
            Assert.AreEqual(false, output.SavedSearch.SavedSearchParameters.SpecificEducation, "specific education did not dezerialize");
            Assert.AreEqual("ascending", output.SavedSearch.SavedSearchParameters.OrderDirection, "order direction did not dezerialize");
        }
コード例 #5
0
 public void DeserializeTest()
 {
     XmlDeserializer target = new XmlDeserializer();
     DotSpatial.Controls.Map map = new DotSpatial.Controls.Map();
     string path = Path.Combine("Data", "DeserializeTest.map.xml");
     target.Deserialize(map, File.ReadAllText(path));
 }
        public void DeserializationWorks_WhenPassedRightXML()
        {
            var xmlPath = Path.Combine(Environment.CurrentDirectory, "SavedSearchListData.xml");
            var doc = XDocument.Load(xmlPath);

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

            Assert.IsNotNull(output, "no deserialization worked");
            Assert.IsNull(output.Errors, "deserialized errors wrong");
            Assert.IsNotNull(output.SavedSearches, "SavedSearched did not Deserialize");
            Assert.IsNotNull(output.SavedSearches.SavedSearchList, "SavedSearchList did not Deserialize");
            //make a SavedSearchList to compare to
            //this will simplify the Asserts
            List<SavedSearch> searches = new List<SavedSearch>();
            SavedSearch viewRetrieve = new SavedSearch();
            viewRetrieve.SearchName = "viewRetrieve";
            viewRetrieve.HostSite = "US";
            viewRetrieve.ExternalID = "366f62b16ac491fed0ed848baa0fbc109128e67b30e75d9614d60ef1fe207d75";
            searches.Add(viewRetrieve);
            SavedSearch lister = new SavedSearch();
            lister.SearchName = "lister";
            lister.HostSite = "US";
            lister.ExternalID = "67f87348bf0da271924400d9197eeba7a291c76362a9398ab1699659c60c585f";
            searches.Add(lister);
            Assert.AreEqual(searches[0].SearchName, output.SavedSearches.SavedSearchList[0].SearchName, "first in searchList searchname did not desearialize");
            Assert.AreEqual(searches[0].HostSite, output.SavedSearches.SavedSearchList[0].HostSite, "first in searchList hostsite did not desearialize");
            Assert.AreEqual(searches[0].ExternalID, output.SavedSearches.SavedSearchList[0].ExternalID, "first in searchList externalID did not desearialize");
            Assert.AreEqual(searches[1].SearchName, output.SavedSearches.SavedSearchList[1].SearchName, "second in searchList searchName did not desearialize");
            Assert.AreEqual(searches[1].HostSite, output.SavedSearches.SavedSearchList[1].HostSite, "second in searchList hostsite did not desearialize");
            Assert.AreEqual(searches[1].ExternalID, output.SavedSearches.SavedSearchList[1].ExternalID, "second in searchList ExternalID did not desearialize");
        }
コード例 #7
0
 public void DeserializeTest()
 {
     XmlDeserializer target = new XmlDeserializer();
     DotSpatial.Controls.Map map = new DotSpatial.Controls.Map();
     string path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "TestFiles", "DeserializeTest.map.xml");
     target.Deserialize(map, File.ReadAllText(path));
 }
コード例 #8
0
ファイル: XmlTests.cs プロジェクト: florinn/RestSharp
        public void Can_Deserialize_Attributes_Without_Matching_Case_On_Default_Root()
        {
            var doc = CreateLowercaseDashesXml();
            var response = new RestResponse { Content = doc };

            var d = new XmlDeserializer();
            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.Friends);
            Assert.Equal(10, p.Friends.Count);

            Assert.NotNull(p.BestFriend);
            Assert.Equal("The Fonz", p.BestFriend.Name);
            Assert.Equal(1952, p.BestFriend.Since);

            Assert.NotNull(p.Foes);
            Assert.Equal(5, p.Foes.Count);
            Assert.Equal("Yankees", p.Foes.Team);
        }
コード例 #9
0
        public void HasReceivedPlayListWith(ImageId imageId)
        {
            ProbeFor(5000, 500, () =>
                                    {

                                        var request = new RestRequest
                                                      	{
                                                      		Resource = "playlists.xml",
                                                      		RootElement = "playlists",
                                                      		XmlNamespace = "",
                                                      		RequestFormat = DataFormat.Xml,
                                                      		Method = Method.GET
                                                      	};
                                        var response = m_Client.Execute(request);

                                        if (response.StatusCode != HttpStatusCode.OK)
                                        {
                                            throw new ApplicationException(string.Format("Unable to get playlists"));
                                        }

                                        var deserializer = new XmlDeserializer {Namespace = "", RootElement = ""};
                                        var playLists = deserializer.Deserialize<RestArchive.PlayLists>(response);

                                        Assert.That(GetImageIdsOf(playLists), Contains.Item(imageId));
                                    });
        }
コード例 #10
0
        public void Can_Deserialize_Elements_With_Namespace()
        {
            var doc = CreateElementsXml();

            var response = new RestResponse { Content = doc };

            var d = new XmlDeserializer();
            d.Namespace = "http://restsharp.org";
            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.Friends);
            Assert.Equal(10, p.Friends.Count);

            Assert.NotNull(p.BestFriend);
            Assert.Equal("The Fonz", p.BestFriend.Name);
            Assert.Equal(1952, p.BestFriend.Since);
        }
コード例 #11
0
ファイル: XmlTests.cs プロジェクト: CSharpByDesign/RestSharp
        public void Can_Deserialize_Names_With_Underscores_On_Default_Root()
        {
            var doc = CreateUnderscoresXml();

            var d = new XmlDeserializer();
            var p = d.Deserialize<PersonForXml>(doc);

            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.NotNull(p.Friends);
            Assert.Equal(10, p.Friends.Count);

            Assert.NotNull(p.BestFriend);
            Assert.Equal("The Fonz", p.BestFriend.Name);
            Assert.Equal(1952, p.BestFriend.Since);

            Assert.NotNull(p.Foes);
            Assert.Equal(5, p.Foes.Count);
            Assert.Equal("Yankees", p.Foes.Team);
        }
コード例 #12
0
        public void Deserialize_SerializationRepresentation_DeserializedObject()
        {
            var subject = new XmlDeserializer();
            var deserialized = subject.Deserialize<Serializable>(Serializable.XmlString("s", 3m));

                Assert.That(deserialized.D, Is.EqualTo(3m));
                Assert.That(deserialized.S, Is.EqualTo("s"));
        }
コード例 #13
0
ファイル: XmlTests.cs プロジェクト: BerndK/RestSharp
        public void Can_Deserialize_AcoustID_Xml()
        {
            var xmlpath = PathFor("AcoustID.xml");
            var doc = XDocument.Load(xmlpath);
            var response = new RestResponse { Content = doc.ToString() };

            var d = new XmlDeserializer();
            var output = d.Deserialize<MTB.Worker.AcoustID.Response>(response);
        }
コード例 #14
0
		public void Ignore_ReadOnly_Property_That_Exists_In_Data() {
			var doc = CreateElementsXml();

			var d = new XmlDeserializer();
			d.Namespace = "http://restsharp.org";
			var p = d.Deserialize<PersonForXml>(doc);

			Assert.Null(p.ReadOnlyProxy);
		}
コード例 #15
0
        public static Parties Convert(XElement xml)
        {
            if (xml == null) return null;

            var s = new XmlDeserializer();
            var parties = new Parties();

            foreach (var party in xml.Descendants("party"))
            {
                string partyType = String.Empty;

                var element = party.Element("type");
                if (element != null)
                    partyType = element.Value;

                if (String.IsNullOrEmpty(partyType))
                {
                    var attribute = party.Attribute("type");
                    if (attribute != null) partyType = attribute.Value;
                }

                if (String.IsNullOrEmpty(partyType)) continue;

                switch (partyType.ToLower())
                {
                    case "person":
                        var person = s.Deserialize<Person>(new RestResponse { Content = party.ToString() });

                        if (person != null)
                            parties.People.Add(person);

                        break;
                    case "company":
                        var company = s.Deserialize<Company>(new RestResponse { Content = party.ToString() });

                        if (company != null)
                            parties.Companies.Add(company);

                        break;
                }
            }

            return parties;
        }
コード例 #16
0
        public void Can_Use_DeserializeAs_Attribute_for_List()
        {
            const string content =
                "<document><response><oddballRootName><sid>1</sid><friendlyName>Jackson</friendlyName><oddballPropertyName>oddball</oddballPropertyName></oddballRootName></response><response><oddballRootName><sid>1</sid><friendlyName>Jackson</friendlyName><oddballPropertyName>evenball</oddballPropertyName></oddballRootName></response></document>";
            var xml = new XmlDeserializer();
            List<Oddball> output = xml.Deserialize<List<Oddball>>(new RestResponse { Content = content });

            Assert.NotNull(output);
            Assert.AreEqual("1", output[0].Sid);
        }
コード例 #17
0
ファイル: MapTest.cs プロジェクト: joelmuzz/DotSpatial
        public void ZoomToMaxExtentTest()
        {
            XmlDeserializer target = new XmlDeserializer();
            Map map = new Map();
            string path = Path.Combine("TestFiles", "testproject1.dspx");

            target.Deserialize(map, File.ReadAllText(path));

            map.ZoomToMaxExtent();
        }
コード例 #18
0
        public void Can_Use_DeserializeAs_Attribute_for_List()
        {
            string xmlpath = this.PathFor("deserialize_as_list.xml");
            XDocument doc = XDocument.Load(xmlpath);
            XmlDeserializer xml = new XmlDeserializer();
            List<Oddball> output = xml.Deserialize<List<Oddball>>(new RestResponse { Content = doc.ToString() });

            Assert.NotNull(output);
            Assert.AreEqual("1", output[0].Sid);
        }
コード例 #19
0
        public void Can_Deserialize_Into_Struct()
        {
            const string content = "<root><one>oneOneOne</one><two>twoTwoTwo</two><three>3</three></root>";
            XmlDeserializer xml = new XmlDeserializer();
            SimpleStruct output = xml.Deserialize<SimpleStruct>(new RestResponse { Content = content });

            Assert.NotNull(output);
            Assert.AreEqual("oneOneOne", output.One);
            Assert.AreEqual("twoTwoTwo", output.Two);
            Assert.AreEqual(3, output.Three);
        }
コード例 #20
0
		public void Can_Deserialize_Directly_To_Lists_Off_Root_Element()
		{
			var xmlpath = PathFor("directlists.xml");
			var doc = XDocument.Load(xmlpath);

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

			Assert.NotEmpty(output);
			Assert.Equal(2, output.Count);
		}
コード例 #21
0
ファイル: XmlTests.cs プロジェクト: ntziolis/RestSharp
        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 XmlDeserializer();
                var output = d.Deserialize<SampleClasses.BooleanTest>(response);

                Assert.True(output.Value);
        }
コード例 #22
0
		public void Can_Deserialize_To_Standalone_List_With_Matching_Class_Case()
		{
			var xmlpath = PathFor("InlineListSample.xml");
			var doc = XDocument.Load(xmlpath);

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

			Assert.NotEmpty(output);
			Assert.Equal(4, output.Count);
		}
コード例 #23
0
        public void DeserializeFrenchCultureTest()
        {
            // Sets the culture to French (France)
            Thread.CurrentThread.CurrentCulture = new CultureInfo("fr-FR");
            // Sets the UI culture to French (France)
            Thread.CurrentThread.CurrentUICulture = new CultureInfo("fr-FR");

            XmlDeserializer target = new XmlDeserializer();
            DotSpatial.Controls.Map map = new DotSpatial.Controls.Map();
            string path = Path.Combine("Data", "DeserializeTest.map.xml");
            target.Deserialize(map, File.ReadAllText(path));
        }
コード例 #24
0
        public void Can_Use_DeserializeAs_Attribute()
        {
            const string content =
                "<oddball><sid>1</sid><friendlyName>Jackson</friendlyName><oddballPropertyName>oddball</oddballPropertyName></oddball>";
            XmlDeserializer xml = new XmlDeserializer();
            Oddball output = xml.Deserialize<Oddball>(new RestResponse { Content = content });

            Assert.NotNull(output);
            Assert.AreEqual("1", output.Sid);
            Assert.AreEqual("Jackson", output.FriendlyName);
            Assert.AreEqual("oddball", output.GoodPropertyName);
        }
コード例 #25
0
        public void Can_Deserialize_Lists_of_Simple_Types()
        {
            var xmlpath = this.PathFor("xmllists.xml");
            var doc = XDocument.Load(xmlpath);
            var xml = new XmlDeserializer();
            var output = xml.Deserialize<SimpleTypesListSample>(new RestResponse { Content = doc.ToString() });

            Assert.IsNotEmpty(output.Names);
            Assert.IsNotEmpty(output.Numbers);
            Assert.False(output.Names[0].Length == 0);
            Assert.False(output.Numbers.Sum() == 0);
        }
コード例 #26
0
        public void Can_Deserialize_Error()
        {
            var xmlpath = Environment.CurrentDirectory + @"\..\..\..\Lastfm.Tests\Responses\Error.xml";
            var doc = XDocument.Load(xmlpath);
            var response = new RestResponse { Content = doc.ToString() };

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

            Assert.IsNotNull(output.Error);
            Assert.AreEqual(6, output.Error.Code);
        }
        public void DeserializationWorks_WhenPassedRightXML() {
            var xmlpath = Path.Combine(Environment.CurrentDirectory, "ResponseBlankApplication.xml");
            var doc = XDocument.Load(xmlpath);

            var xml = new XmlDeserializer();
            var output = xml.Deserialize<BlankApplication>(new RestResponse() { Content = doc.ToString() });
            Assert.IsNotNull(output.Requirements);
            Assert.AreEqual("2 Year Degree", output.Requirements.DegreeRequired.Trim());
            Assert.AreEqual("Not Specified", output.Requirements.TravelRequired.Trim());
            Assert.AreEqual("At least 5 year(s)", output.Requirements.ExperienceRequired.Trim());
            Assert.IsTrue(output.Requirements.RequirementsText.Contains("nstallation tech, field rep, HVAC, mechanic, installer, repairman, auto technician, service specialist, millwright, millright"));
        }
コード例 #28
0
		public void Can_Deserialize_To_List_Inheritor_From_Custom_Root_With_Attributes()
		{
			var xmlpath = PathFor("ListWithAttributes.xml");
			var doc = XDocument.Load(xmlpath);

			var xml = new XmlDeserializer();
			xml.RootElement = "Calls";
			var output = xml.Deserialize<TwilioCallList>(new RestResponse { Content = doc.ToString() });

			Assert.Equal(3, output.NumPages);
			Assert.NotEmpty(output);
			Assert.Equal(2, output.Count);
		}
コード例 #29
0
        public void Can_Use_DeserializeAs_Attribute()
        {
            const string content =
                "<oddball><sid>1</sid><friendlyName>Jackson</friendlyName><oddballPropertyName>oddball</oddballPropertyName></oddball>";
            XmlDeserializer xml    = new XmlDeserializer();
            Oddball         output = xml.Deserialize <Oddball>(new RestResponse {
                Content = content
            });

            Assert.NotNull(output);
            Assert.AreEqual("1", output.Sid);
            Assert.AreEqual("Jackson", output.FriendlyName);
            Assert.AreEqual("oddball", output.GoodPropertyName);
        }
コード例 #30
0
        public void Can_Deserialize_Inline_List_Without_Elements_To_Empty_List()
        {
            var doc = CreateXmlWithEmptyInlineList();

            var xml    = new XmlDeserializer();
            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);
        }
コード例 #31
0
        public void TestRectangleSerialization()
        {
            var           rectangle = new Rectangle(1, 1, 2, 2);
            XmlSerializer s         = new XmlSerializer();
            string        xml       = s.Serialize(rectangle);

            XmlDeserializer d      = new XmlDeserializer();
            Rectangle       result = d.Deserialize <Rectangle>(xml);

            Assert.AreEqual(1, result.X);
            Assert.AreEqual(1, result.Y);
            Assert.AreEqual(2, result.Width);
            Assert.AreEqual(2, result.Height);
        }
コード例 #32
0
        public void Ignore_ReadOnly_Property_That_Exists_In_Data()
        {
            var doc      = CreateElementsXml();
            var response = new RestResponse {
                Content = doc
            };
            var d = new XmlDeserializer();

            d.Namespace = "http://restsharp.org";

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

            Assert.Null(p.ReadOnlyProxy);
        }
コード例 #33
0
        public void Can_Deserialize_Goodreads_Xml()
        {
            string       xmlpath  = this.PathFor("Goodreads.xml");
            XDocument    doc      = XDocument.Load(xmlpath);
            RestResponse response = new RestResponse {
                Content = doc.ToString()
            };
            XmlDeserializer           d      = new XmlDeserializer();
            GoodReadsReviewCollection output = d.Deserialize <GoodReadsReviewCollection>(response);

            Assert.AreEqual(2, output.Reviews.Count);
            Assert.AreEqual("1208943892", output.Reviews[0].Id); // This fails without fixing the XmlDeserializer
            Assert.AreEqual("1198344567", output.Reviews[1].Id);
        }
コード例 #34
0
        public void Can_Deserialize_Google_Weather_Xml()
        {
            string       xmlpath  = this.PathFor("GoogleWeather.xml");
            XDocument    doc      = XDocument.Load(xmlpath);
            RestResponse response = new RestResponse {
                Content = doc.ToString()
            };
            XmlDeserializer d      = new XmlDeserializer();
            xml_api_reply   output = d.Deserialize <xml_api_reply>(response);

            Assert.IsNotEmpty(output.weather);
            Assert.AreEqual(4, output.weather.Count);
            Assert.AreEqual("Sunny", output.weather[0].condition.data);
        }
コード例 #35
0
        public HarvestException(IRestResponse response)
        {
            Response = response;

            try
            {
                IDeserializer deserializer = new XmlDeserializer();
                Result = deserializer.Deserialize<ErrorResult>(response);
            }
            catch
            {
                // could not deserialize the response... eat it
            }
        }
コード例 #36
0
        public void should_handle_numerics_data_as_xml_with_primitive_handler()
        {
            var expected     = SerializationTestHelper.GenerateNumericsModel();
            var serializer   = new XmlSerializer(_mappingRegistry, new[] { new NumericsXmlPrimitiveHandler() });
            var deserializer = new XmlDeserializer(_mappingRegistry, _typeCreator, new[] { new NumericsXmlPrimitiveHandler() });

            var output = serializer.Serialize(expected);

            _outputHelper.WriteLine(output.AsString);

            var actual = deserializer.Deserialize <NumericsTypesModel>(output);

            Assert.AreEqual(expected, actual);
        }
コード例 #37
0
        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 XmlDeserializer();
            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);
        }
コード例 #38
0
        public void Can_Use_DeserializeAs_Attribute_for_List_Property()
        {
            const string content =
                "<oddball><oddballListName><item>TestValue</item></oddballListName></oddball>";

            XmlDeserializer xml    = new XmlDeserializer();
            Oddball         output = xml.Deserialize <Oddball>(new RestResponse {
                Content = content
            });

            Assert.NotNull(output);
            Assert.NotNull(output.ListWithGoodName);
            Assert.IsNotEmpty(output.ListWithGoodName);
        }
コード例 #39
0
        public void Can_Deserialize_Root_Elements_Without_Matching_Case_And_Dashes()
        {
            var doc      = CreateLowerCasedRootElementWithDashesXml();
            var response = new RestResponse {
                Content = doc
            };

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

            Assert.NotNull(p);
            Assert.Equal(1, p.Count);
            Assert.Equal(45, p[0].ConceptId);
        }
コード例 #40
0
        public void Able_to_use_alternative_name_for_arrays()
        {
            string xmlpath = PathFor("header_and_rows.xml");
            var    doc     = XDocument.Load(xmlpath);
            var    xml     = new XmlDeserializer();
            var    output  = xml.Deserialize <Header>(new RestResponse {
                Content = doc.ToString()
            });

            Assert.NotNull(output);
            Assert.AreEqual(output.Title, "text title");
            Assert.IsNotEmpty(output.Othername);
            Assert.IsTrue(output.Othername.Any(x => x.Text1 == "first row text 1 sample"));
        }
コード例 #41
0
        public HarvestException(IRestResponse response)
        {
            Response = response;

            try
            {
                IDeserializer deserializer = new XmlDeserializer();
                Result = deserializer.Deserialize <ErrorResult>(response);
            }
            catch
            {
                // could not deserialize the response... eat it
            }
        }
コード例 #42
0
        public void DeserializeFrenchCultureTest()
        {
            // Sets the culture to French (France)
            Thread.CurrentThread.CurrentCulture = new CultureInfo("fr-FR");

            // Sets the UI culture to French (France)
            Thread.CurrentThread.CurrentUICulture = new CultureInfo("fr-FR");

            XmlDeserializer target = new XmlDeserializer();
            Map             map    = new Map();
            string          path   = Path.Combine("Data", "DeserializeTest.map.xml");

            target.Deserialize(map, File.ReadAllText(path));
        }
コード例 #43
0
        public void Can_Deserialize_Lastfm_Xml()
        {
            string       xmlpath  = this.PathFor("Lastfm.xml");
            XDocument    doc      = XDocument.Load(xmlpath);
            RestResponse response = new RestResponse {
                Content = doc.ToString()
            };
            XmlDeserializer d      = new XmlDeserializer();
            Event           output = d.Deserialize <Event>(response);

            //Assert.IsNotEmpty(output.artists);
            Assert.AreEqual("http://www.last.fm/event/328799+Philip+Glass+at+Barbican+Centre+on+12+June+2008", output.url);
            Assert.AreEqual("http://www.last.fm/venue/8777860+Barbican+Centre", output.venue.url);
        }
コード例 #44
0
    public void Can_Deserialize_List_Of_Primitives_With_Namespace()
    {
        var doc      = CreateListOfPrimitivesXml();
        var response = new RestResponse {
            Content = doc
        };
        var d = new XmlDeserializer {
            Namespace = "http://restsharp.org"
        };
        var a = d.Deserialize <List <artist> >(response);

        Assert.Equal(2, a.Count);
        Assert.Equal("first", a[0].Value);
        Assert.Equal("second", a[1].Value);
    }
コード例 #45
0
        public void should_correctly_serialize_nulled_dynamic_data_with_xml()
        {
            var model      = SerializationTestHelper.GenerateNulledDynamicTypesModel();
            var serializer = new XmlSerializer(_mappingRegistry);

            var output = serializer.Serialize(model);

            testOutputHelper.WriteLine("FileSize: " + output.AsString.Length + " bytes");
            testOutputHelper.WriteLine(output.AsString);

            var deserializer = new XmlDeserializer(_mappingRegistry, _typeCreator);
            var result       = deserializer.Deserialize <DynamicTypesModel>(output);

            SerializationTestHelper.AsserNulledDynamicTypesData(model, result);
        }
コード例 #46
0
        private static void Main(string[] args)
        {
            Stream      xmlResouce = LoadResource("Payload.xml");
            XmlDocument document   = new XmlDocument();

            document.Load(xmlResouce);

            Debug.WriteLine(document.ToString());

            XmlDeserializer deserializer = new XmlDeserializer(document);

            MainContent parsedContent = deserializer.Deserialize <MainContent>();

            Debug.WriteLine(parsedContent);
        }
コード例 #47
0
        public void TestKeyValuePair()
        {
            KeyValuePair <int, int> pairIn = new KeyValuePair <int, int>(5, 100);
            XmlDocument             doc    = XmlSerializer.Serialize(pairIn, 1, "pair");
            //doc.Save(Application.dataPath + "/" + "pair_test.xml");
            KeyValuePair <int, int> pairOut = (KeyValuePair <int, int>)XmlDeserializer.Deserialize(doc.InnerXml, 1);


            Assert.AreNotSame(pairIn, pairOut);
            Assert.False(ReferenceEquals(pairIn, pairOut));

            Assert.AreEqual(pairIn.Key, pairOut.Key);
            Assert.AreEqual(pairIn.Value, pairOut.Value);
            Assert.AreEqual(pairOut.Value, 100);
        }
コード例 #48
0
        public void TestMapPointLayer()
        {
            const string filename = @".\TestFiles\test-RandomPts.shp";

            IFeatureSet   fs     = FeatureSet.Open(filename);
            MapPointLayer l      = new MapPointLayer(fs);
            XmlSerializer s      = new XmlSerializer();
            string        result = s.Serialize(l);

            XmlDeserializer d             = new XmlDeserializer();
            MapPointLayer   newPointLayer = d.Deserialize <MapPointLayer>(result);

            Assert.IsNotNull(newPointLayer);
            Assert.AreEqual(filename, newPointLayer.DataSet.Filename);
        }
コード例 #49
0
        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 XmlDeserializer();
            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);
        }
コード例 #50
0
    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 XmlDeserializer();
        var output = d.Deserialize <VenueSearch>(response) !;

        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);
    }
コード例 #51
0
    public void Can_Deserialize_When_RootElement_Deeper_Then_One()
    {
        const string content =
            "<root><subroot><subsubroot><one>oneOneOne</one><two>twoTwoTwo</two><three>3</three></subsubroot></subroot></root>";
        var xml = new XmlDeserializer {
            RootElement = "subsubroot"
        };
        var output = xml.Deserialize <SimpleStruct>(new RestResponse {
            Content = content
        });

        Assert.Equal("oneOneOne", output.One);
        Assert.Equal("twoTwoTwo", output.Two);
        Assert.Equal(3, output.Three);
    }
コード例 #52
0
        private void OnEndUploadNewPlaylist(RestResponse response)
        {
            if (response.StatusCode != HttpStatusCode.Created)
            {
                m_Listener.Error(CreateErrorDescription(response));
                return;
            }

            var deserializer = new XmlDeserializer {
                Namespace = "", RootElement = ""
            };
            var playList = deserializer.Deserialize <playlist>(response);

            m_Listener.NewPlayListUploaded(CreatePlayList(playList));
        }
コード例 #53
0
    public void Can_Deserialize_Node_That_Has_Attribute_And_Content()
    {
        var doc = CreateNoteXml();

        var response = new RestResponse {
            Content = doc
        };
        var d = new XmlDeserializer();

        var note = d.Deserialize <Note>(response) !;

        Assert.Equal(1, note.Id);
        Assert.Equal(Note.TITLE, note.Title);
        Assert.Equal(Note.MESSAGE, note.Message);
    }
コード例 #54
0
        public void should_correctly_serialize_populated_nullable_data_with_xml()
        {
            var model = SerializationTestHelper.GeneratePopulatedNullableModel();

            var serializer = new XmlSerializer(_mappingRegistry);
            var output     = serializer.Serialize(model);

            _outputHelper.WriteLine("FileSize: " + output.AsString.Length + " bytes");
            _outputHelper.WriteLine(output.AsString);

            var deserializer = new XmlDeserializer(_mappingRegistry, _typeCreator);
            var result       = deserializer.Deserialize <NullableTypesModel>(output);

            SerializationTestHelper.AssertNullableModelData(model, result);
        }
コード例 #55
0
        public void TestMapPointLayer()
        {
            string filename = Path.Combine("Data", "test-RandomPts.shp");

            IFeatureSet   fs     = FeatureSet.Open(filename);
            MapPointLayer l      = new MapPointLayer(fs);
            XmlSerializer s      = new XmlSerializer();
            string        result = s.Serialize(l);

            XmlDeserializer d             = new XmlDeserializer();
            MapPointLayer   newPointLayer = d.Deserialize <MapPointLayer>(result);

            Assert.IsNotNull(newPointLayer);
            Assert.AreEqual(newPointLayer.DataSet.Filename, Path.GetFullPath(filename));
        }
コード例 #56
0
        public void Can_Deserialize_Lists_of_Simple_Types()
        {
            string                xmlpath = this.PathFor("xmllists.xml");
            XDocument             doc     = XDocument.Load(xmlpath);
            XmlDeserializer       xml     = new XmlDeserializer();
            SimpleTypesListSample output  = xml.Deserialize <SimpleTypesListSample>(
                new RestResponse {
                Content = doc.ToString()
            });

            Assert.IsNotEmpty(output.Names);
            Assert.IsNotEmpty(output.Numbers);
            Assert.False(output.Names[0].Length == 0);
            Assert.False(output.Numbers.Sum() == 0);
        }
コード例 #57
0
        public void Cannot_Deserialize_Node_To_An_Object_That_Has_Two_Properties_With_Text_Content_Attributes()
        {
            var doc = CreateNoteXml();

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

            Assert.Throws(typeof(ArgumentException), () =>
            {
                var note = d.Deserialize <WrongNote>(response);
            });
        }
コード例 #58
0
        public void Can_Deserialize_To_List_Inheritor_From_Custom_Root_With_Attributes()
        {
            var xmlpath = PathFor("ListWithAttributes.xml");
            var doc     = XDocument.Load(xmlpath);
            var xml     = new XmlDeserializer {
                RootElement = "Calls"
            };
            var output = xml.Deserialize <TwilioCallList>(new RestResponse {
                Content = doc.ToString()
            });

            Assert.AreEqual(3, output.NumPages);
            Assert.IsNotEmpty(output);
            Assert.AreEqual(2, output.Count);
        }
コード例 #59
0
        public void ShouldDeserializeListOfResourcesInXml()
        {
            const string xml =
                "<ArrayOfSomeResource>" +
                "<SomeResource><Name>John Doe</Name><Amount>123.45</Amount></SomeResource>" +
                "<SomeResource><Name>Sally Doe</Name><Amount>67.89</Amount></SomeResource>" +
                "</ArrayOfSomeResource>";
            var deserializer = new XmlDeserializer();
            var resources    = (SomeResource[])deserializer.Deserialize(xml, typeof(SomeResource[]));

            Assert.AreEqual("John Doe", resources[0].Name);
            Assert.AreEqual(123.45, resources[0].Amount);
            Assert.AreEqual("Sally Doe", resources[1].Name);
            Assert.AreEqual(67.89, resources[1].Amount);
        }
コード例 #60
0
        public void DeserializationWorks_WhenPassedRightXML() {
            var xmlpath = Path.Combine(Environment.CurrentDirectory,"ResponseJobSearch.xml");
            var doc = XDocument.Load(xmlpath);

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

            Assert.IsNotNull(output);
            Assert.AreEqual(386163, output.TotalCount);
            Assert.AreEqual(15447, output.TotalPages);
            Assert.AreEqual(1, output.FirstItemIndex);
            Assert.AreEqual(25, output.LastItemIndex);

            Assert.IsNotNull(output.Results);
            Assert.AreEqual(25, output.Results.Count);

        }