Exemple #1
0
 public List <byte[]> SearchImages(string tags, string source)
 {
     try
     {
         //Search
         SearchRequest searchRequest = new SearchRequest();
         var           result        = searchRequest.GetSearchResults(tags, source);
         return(result);
     }
     catch (Exception ex)
     {
         return(null);
     }
 }
        public void GetSearchResult_WhenCalled_VerifyReturnValue()
        {
            //ARRANGE
            var           mockConnection    = MockRepository.GenerateMock <IConnection>();
            var           mockConfiguration = MockRepository.GenerateMock <IConfiguration>();
            SearchRequest searchRequest     = new SearchRequest(mockConnection, mockConfiguration);
            var           http           = new HttpClient();
            var           uri            = "TestUri";
            var           responseString = GetResponseString();

            byte[] downloadByte = new byte[20];
            mockConnection.Stub(mc => mc.GetNewHttpClient()).Return(http);
            mockConfiguration.Stub(mc => mc.GetAppSettings("TestKey")).IgnoreArguments().Return(uri);
            mockConnection.Stub(mc => mc.GetResponseString(http, uri)).IgnoreArguments().Return(responseString);
            mockConnection.Stub(mc => mc.DownloadImage("TestUrl")).IgnoreArguments().Return(downloadByte).Repeat.Any();

            //ACT
            List <byte[]> result = searchRequest.GetSearchResults("nature", "Flickr");

            //ASSERT
            Assert.IsTrue(result.Count == 20);
        }