public void SetUp() { IOAuthCredentials oAuthCredentials = EssentialDependencyCheck<IOAuthCredentials>.Instance; IApiUri apiUri = EssentialDependencyCheck<IApiUri>.Instance; var httpGetResolver = new HttpGetResolver(); var urlSigner = new UrlSigner(); _endpointResolver = new EndpointResolver(httpGetResolver, urlSigner, oAuthCredentials, apiUri); }
public void Should_return_xmlnode_if_valid_xml_received() { Given_a_urlresolver_that_returns_valid_xml(); var endpointResolver = new EndpointResolver(_urlResolver); XmlNode hitEndpoint = endpointResolver.HitEndpoint("", "", new NameValueCollection()); Assert.That(hitEndpoint.HasChildNodes); Assert.That(hitEndpoint.SelectSingleNode("//serverTime"), Is.Not.Null); }
public void Should_fire_resolve_with_correct_values() { Given_a_urlresolver_that_returns_valid_xml(); var endpointResolver = new EndpointResolver(_urlResolver); endpointResolver.HitEndpoint("test", "GET", new NameValueCollection()); var expected = new Uri(string.Format("{0}/test?oauth_consumer_key={1}", _apiUrl, _consumerKey)); _urlResolver.AssertWasCalled(x=>x.Resolve(Arg<Uri>.Is.Equal(expected), Arg<string>.Is.Equal("GET"), Arg<WebHeaderCollection>.Is.Equal(new WebHeaderCollection()))); }
public void Can_hit_endpoint() { var httpGetResolver = new EndpointResolver(new HttpGetResolver()); Status status = new FluentApi<Status>(httpGetResolver) .Resolve(); Assert.That(status, Is.Not.Null); Assert.That(status.ServerTime.Day, Is.EqualTo(DateTime.Now.Day)); }
public void Can_hit_endpoint() { var httpGetResolver = new EndpointResolver(new HttpGetResolver()); Track track = new FluentApi<Track>(httpGetResolver) .WithTrackId(12345) .Resolve(); Assert.That(track, Is.Not.Null); Assert.That(track.Title, Is.EqualTo("I Love You")); Assert.That(track.Artist.Name, Is.EqualTo("The Dandy Warhols")); }
public void Can_hit_endpoint() { var httpGetResolver = new EndpointResolver(new HttpGetResolver()); ArtistBrowse artistBrowse = new FluentApi<ArtistBrowse>(httpGetResolver).WithParameter("letter", "radio").Resolve(); Assert.That(artistBrowse, Is.Not.Null); Assert.That(artistBrowse.Page, Is.EqualTo(1)); Assert.That(artistBrowse.PageSize, Is.EqualTo(10)); Assert.That(artistBrowse.Artists.Count,Is.GreaterThan(0)); }
public void Should_throw_argumentexception_if_hitendpoint_fired_with_null_querystring() { _urlResolver = MockRepository.GenerateMock<IUrlResolver>(); _urlResolver.Stub(x => x.Resolve(null, "", null)) .IgnoreArguments() .Return("<response status=\"error\" version=\"1.2\"><error code=\"1001\"><errorMessage>Missing parameter \"tags\".</errorMessage></error></response>"); var endpointResolver = new EndpointResolver(_urlResolver); var argException = Assert.Throws<ArgumentException>(() => endpointResolver.HitEndpoint("", "", null)); Assert.That(argException.Message, Is.EqualTo("querystring parameter cannot be null, please instantiate")); }
public void Can_hit_endpoint() { var httpGetResolver = new EndpointResolver(new HttpGetResolver()); ArtistSearch artist = new FluentApi<ArtistSearch>(httpGetResolver) .WithParameter("q", "pink") .WithParameter("country", "GB") .Resolve(); Assert.That(artist, Is.Not.Null); Assert.That(artist.Results.Artists.Count, Is.GreaterThan(0)); }
public void Setup() { var urlResolver = A.Fake<IUrlResolver>(); A.CallTo(() => urlResolver.Resolve(A<Uri>.Ignored, A<string>.Ignored, A<Dictionary<string, string>>.Ignored)) .Returns(string.Empty); var apiUri = A.Fake<IApiUri>(); A.CallTo(() => apiUri.Uri) .Returns("http://uri/"); _endpointResolver = new EndpointResolver(urlResolver, new UrlSigner(), new AppSettingsCredentials(), apiUri); }
public void Can_hit_endpoint() { var httpGetResolver = new EndpointResolver(new HttpGetResolver()); ArtistTopTracks artist = new FluentApi<ArtistTopTracks>(httpGetResolver) .WithParameter("artistId", "1") .WithParameter("country", "GB") .Resolve(); Assert.That(artist, Is.Not.Null); Assert.That(artist.Tracks.Count, Is.GreaterThan(0)); }
public void Can_hit_endpoint() { var httpGetResolver = new EndpointResolver(new HttpGetResolver()); ReleaseRecommend release = new FluentApi<ReleaseRecommend>(httpGetResolver) .WithParameter("releaseId", "155408") .WithParameter("country", "GB") .Resolve(); Assert.That(release, Is.Not.Null); Assert.That(release.RecommendedItems.Count, Is.GreaterThan(0)); }
public void Should_throw_api_exception_with_correct_error_if_error_xml_received() { _urlResolver = MockRepository.GenerateMock<IUrlResolver>(); _urlResolver.Stub(x => x.Resolve(null, "", null)) .IgnoreArguments() .Return("<response status=\"error\" version=\"1.2\"><error code=\"1001\"><errorMessage>Missing parameter \"tags\".</errorMessage></error></response>"); var endpointResolver = new EndpointResolver(_urlResolver); var apiException = Assert.Throws<ApiXmlException>(() => endpointResolver.HitEndpoint("", "", new NameValueCollection())); Assert.That(apiException.Message, Is.EqualTo("An error has occured in the Api")); Assert.That(apiException.Error.Code, Is.EqualTo(1001)); Assert.That(apiException.Error.ErrorMessage, Is.EqualTo("Missing parameter \"tags\".")); }
public void Can_hit_endpoint() { var httpGetResolver = new EndpointResolver(new HttpGetResolver()); ArtistReleases artist = new FluentApi<ArtistReleases>(httpGetResolver) .WithParameter("artistId", "1") .WithParameter("country", "GB") .Resolve(); Assert.That(artist, Is.Not.Null); Assert.That(artist.Releases.Count, Is.GreaterThan(0)); Assert.That(artist.Releases.FirstOrDefault().Artist.Name, Is.EqualTo("Keane")); }
public void Can_hit_endpoint() { var httpGetResolver = new EndpointResolver(new HttpGetResolver()); Release release = new FluentApi<Release>(httpGetResolver) .WithParameter("releaseId", "155408") .WithParameter("country", "GB") .Resolve(); Assert.That(release, Is.Not.Null); Assert.That(release.Title, Is.EqualTo("Dreams")); Assert.That(release.Artist.Name, Is.EqualTo("The Whitest Boy Alive")); }
public void Can_hit_endpoint() { var httpGetResolver = new EndpointResolver(new HttpGetResolver()); ReleaseByDate release = new FluentApi<ReleaseByDate>(httpGetResolver) .WithParameter("fromDate", "20110101") .WithParameter("toDate", "20110301") .WithParameter("country", "GB") .Resolve(); Assert.That(release, Is.Not.Null); Assert.That(release.Releases.Count, Is.GreaterThan(0)); }
public void Can_hit_endpoint() { var httpGetResolver = new EndpointResolver(new HttpGetResolver()); // TODO: Set up using castle? Artist artist = new FluentApi<Artist>(httpGetResolver) .WithParameter("artistid","1") .Resolve(); Assert.That(artist, Is.Not.Null); Assert.That(artist.Name, Is.EqualTo("Keane")); Assert.That(artist.SortName, Is.EqualTo("Keane")); Assert.That(artist.Url, Is.EqualTo("http://www.7digital.com/artists/keane/?partner=1401")); Assert.That(artist.Image, Is.EqualTo("http://cdn.7static.com/static/img/artistimages/00/000/000/0000000001_150.jpg")); }
public void Can_hit_endpoint_with_paging() { var httpGetResolver = new EndpointResolver(new HttpGetResolver()); ArtistTopTracks artist = new FluentApi<ArtistTopTracks>(httpGetResolver) .WithParameter("artistId", "1") .WithParameter("page", "2") .WithParameter("pageSize", "10") .Resolve(); Assert.That(artist, Is.Not.Null); Assert.That(artist.Page, Is.EqualTo(2)); Assert.That(artist.PageSize, Is.EqualTo(10)); }
public void Can_hit_endpoint_with_paging() { var httpGetResolver = new EndpointResolver(new HttpGetResolver()); ArtistSearch artistBrowse = new FluentApi<ArtistSearch>(httpGetResolver) .WithParameter("q", "pink") .WithParameter("page", "2") .WithParameter("pageSize", "20") .Resolve(); Assert.That(artistBrowse, Is.Not.Null); Assert.That(artistBrowse.Page, Is.EqualTo(2)); Assert.That(artistBrowse.PageSize, Is.EqualTo(20)); }
public void Can_hit_endpoint_with_paging() { var httpGetResolver = new EndpointResolver(new HttpGetResolver()); ReleaseChart artistBrowse = new FluentApi<ReleaseChart>(httpGetResolver) .WithParameter("releaseId", "155408") .WithParameter("page", "2") .WithParameter("pageSize", "20") .Resolve(); Assert.That(artistBrowse, Is.Not.Null); Assert.That(artistBrowse.Page, Is.EqualTo(2)); Assert.That(artistBrowse.PageSize, Is.EqualTo(20)); }
public void Can_hit_endpoint() { var httpGetResolver = new EndpointResolver(new HttpGetResolver()); ReleaseSearch release = new FluentApi<ReleaseSearch>(httpGetResolver) .WithParameter("q", "no surprises") .WithParameter("type", ReleaseType.Video.ToString()) .WithParameter("country", "GB") .Resolve(); Assert.That(release, Is.Not.Null); Assert.That(release.Results.Releases.Count, Is.GreaterThan(0)); Assert.That(release.Results.Releases.FirstOrDefault().Type, Is.EqualTo(ReleaseType.Video)); }
public void Can_hit_endpoint_with_paging() { var httpGetResolver = new EndpointResolver(new HttpGetResolver()); TrackChart artistBrowse = new FluentApi<TrackChart>(httpGetResolver) .WithParameter("fromDate", "20090610") .WithParameter("toDate", "20110101") .WithParameter("page", "2") .WithParameter("pageSize", "20") .Resolve(); Assert.That(artistBrowse, Is.Not.Null); Assert.That(artistBrowse.Page, Is.EqualTo(2)); Assert.That(artistBrowse.PageSize, Is.EqualTo(20)); }
public void Can_hit_endpoint() { var httpGetResolver = new EndpointResolver(new HttpGetResolver()); ReleaseChart release = new FluentApi<ReleaseChart>(httpGetResolver) .WithParameter("fromDate", "20110101") .WithParameter("toDate", "20110301") .WithParameter("country", "GB") .Resolve(); Assert.That(release, Is.Not.Null); Assert.That(release.ChartItems.Count, Is.GreaterThan(0)); Assert.That(release.FromDate, Is.GreaterThan(new DateTime(2011, 01, 01))); Assert.That(release.ToDate, Is.EqualTo(new DateTime(2011, 03, 01))); Assert.That(release.Type, Is.EqualTo(ChartType.album)); }
public void Can_hit_endpoint() { var httpGetResolver = new EndpointResolver(new HttpGetResolver()); ArtistChart artist = new FluentApi<ArtistChart>(httpGetResolver) .WithParameter("period", "week") .WithParameter("toDate", "20110131") .WithParameter("country", "GB") .Resolve(); Assert.That(artist, Is.Not.Null); Assert.That(artist.ChartItems.Count, Is.EqualTo(10)); Assert.That(artist.Type, Is.EqualTo(ChartType.artist)); Assert.That(artist.FromDate, Is.EqualTo(new DateTime(2011, 01, 25))); Assert.That(artist.ToDate, Is.EqualTo(new DateTime(2011, 01, 31))); Assert.That(artist.ChartItems.FirstOrDefault().Artist, Is.Not.Null); }
public void Can_handle_pagingerror_with_paging() { var httpGetResolver = new EndpointResolver(new HttpGetResolver()); try { new FluentApi<ArtistTopTracks>(httpGetResolver) .WithParameter("artistId", "1") .WithParameter("page", "2") .WithParameter("pageSize", "10") .Resolve(); } catch(ApiXmlException ex) { Assert.That(ex.Error, Is.Not.Null); Assert.That(ex.Error.Code, Is.EqualTo(1003)); Assert.That(ex.Error.ErrorMessage, Is.EqualTo("Requested page out of range")); } }
public void Should_return_xmlnode_if_valid_xml_received_using_async() { var resolver = new FakeUrlResolver { StubPayload = SERVICE_STATUS }; var endpointResolver = new EndpointResolver(resolver, _urlSigner, EssentialDependencyCheck<IOAuthCredentials>.Instance, EssentialDependencyCheck<IApiUri>.Instance); var reset = new AutoResetEvent(false); string response = string.Empty; endpointResolver.HitEndpointAsync(new EndPointInfo(), s => { response = s; reset.Set(); }); reset.WaitOne(1000 * 60); var payload = new XmlDocument(); payload.LoadXml(response); Assert.That(payload.HasChildNodes); Assert.That(payload.SelectSingleNode("//serverTime"), Is.Not.Null); }
public void SetUp() { _endpointResolver = new EndpointResolver(new HttpGetResolver(), new AppSettingsCredentials()); }
public void Setup() { _endpointResolver = new EndpointResolver(_urlResolver, new OAuthCredentials(_consumerKey, "")); }
public void Should_use_api_uri_provided_by_IApiUri_interface() { const string expectedApiUri = "http://api.7dizzle"; Given_a_urlresolver_that_returns_valid_xml(); var apiUri = A.Fake<IApiUri>(); A.CallTo(() => apiUri.Uri).Returns(expectedApiUri); IOAuthCredentials oAuthCredentials = EssentialDependencyCheck<IOAuthCredentials>.Instance; var endpointResolver = new EndpointResolver(_urlResolver, _urlSigner, oAuthCredentials, apiUri); var endPointState = new EndPointInfo { Uri = "test", HttpMethod = "GET", Headers = new Dictionary<string, string>() }; endpointResolver.HitEndpoint(endPointState); A.CallTo(() => apiUri.Uri).MustHaveHappened(Repeated.Exactly.Once); A.CallTo(() => _urlResolver.Resolve( A<Uri>.That.Matches(x => x.ToString().Contains(expectedApiUri)), A<string>.Ignored, A<Dictionary<string, string>>.Ignored)) .MustHaveHappened(Repeated.Exactly.Once); }
public void Setup() { _urlResolver = A.Fake<IUrlResolver>(); _urlSigner = A.Fake<IUrlSigner>(); _endpointResolver = new EndpointResolver(_urlResolver, _urlSigner, EssentialDependencyCheck<IOAuthCredentials>.Instance, EssentialDependencyCheck<IApiUri>.Instance); }