/// <summary> /// Sample response that has to be parsed: /// <entry> /// <title> /// <link rel="enclosure" type="image/jpeg" href="https://live.staticflickr.com/65535/50044712313_aefaa149b2_b.jpg" /> /// </title> /// </entry> /// </summary> /// <param name="response"></param> /// <returns></returns> private IResponseContext ParseResponse(HTTPAPIResponse response) { ImageResponseDataModel responseDataModel = new ImageResponseDataModel(); if (response.Code != ErrorCodes.NoError) { responseDataModel.URI = new ObservableCollection <string>(); responseDataModel.Status = "Error in receiving response from server"; return(responseDataModel);//in case of exception list wil be empty } try { //TODO: Add sample response here XmlDocument xmlResponseDoc = new XmlDocument(); xmlResponseDoc.LoadXml(response.ResponseString); XmlNodeList entryNodes = xmlResponseDoc.GetElementsByTagName("entry"); ObservableCollection <string> imageURICol = new ObservableCollection <string>(); foreach (XmlNode entryNode in entryNodes) { var childNodes = entryNode.ChildNodes.GetEnumerator(); while (childNodes.MoveNext()) { XmlNode curNode = (XmlNode)childNodes.Current; if (curNode?.Name == "link") { XmlNode hrefNode = curNode.Attributes.GetNamedItem("type"); if (hrefNode.Value == "image/jpeg") { imageURICol.Add(curNode.Attributes.GetNamedItem("href").Value); } } } } responseDataModel.URI = imageURICol; Logger.Log("Successfully parsed flicker response"); responseDataModel.Status = "Parsed response successfully"; } catch (Exception exp) { Logger.Log("Exception while parsing response from flicker. Details:" + exp); responseDataModel.URI = new ObservableCollection <string>(); responseDataModel.Status = "Error in parsing response from server"; //in case of exception list wil be empty } return(responseDataModel); }
public async Task Test_FlickerSearchComponent_Negative() { IQueryContext qc = new QueryContext(); qc.QueryParam = "Nature"; qc.ApplicationConfiguration = new ApplicationConfiguration(); IDataSource data = qc.ApplicationConfiguration.GetDataSource(DataSources.Flicker); ISearchComponent SearchComponent = new FlickerSearchSearchComponent(new MockHTTPAPIHelper("Test_FlickerSearchComponent_Negative")); IResponseContext rc = await SearchComponent.PerformSearch(qc); ImageResponseDataModel responseModel = rc as ImageResponseDataModel; Assert.IsNotNull(responseModel); Assert.AreEqual(responseModel.URI.Count, 0); Assert.IsNotNull(rc.Status); }