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 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 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 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);
		}