public ExemploRequestDadosCotna() { Console.WriteLine("Exemplo de requisição de dados."); ContaBancaria conta = new ContaBancaria("Elcio", 15000.00); ResponseChain requestDadosConta = new ResponseChain(); Console.WriteLine("\n XML \n" + requestDadosConta.DadosConta(conta, new RequestDadosConta(Formato.XML))); Console.WriteLine("\n CSV \n" + requestDadosConta.DadosConta(conta, new RequestDadosConta(Formato.CSV))); Console.WriteLine("\n Por cento \n" + requestDadosConta.DadosConta(conta, new RequestDadosConta(Formato.PORCENTO))); }
public void it_should_follow_redirects() { var service = new Mock <IRemoteResourceService>(); var dispatcher = new Mock <IRequestDispatcher>(); var chain = new ResponseChain(service.Object, new IResponseFeature[0]); var response = TestHelper.CreateResponse(HttpStatusCode.Created, new Dictionary <string, string> { { "Location", "file://NotImportant" } }); service.SetupGet(s => s.Dispatcher).Returns(dispatcher.Object); new FollowRedirects().Process(chain, response); dispatcher.Verify(d => d.Process(service.Object, It.IsAny <string>(), It.IsAny <Uri>(), It.IsAny <string>())); }
public void it_should_auto_refresh() { var service = new Mock <IRemoteResourceService>(); var dispatcher = new Mock <IRequestDispatcher>(); var chain = new ResponseChain(service.Object, new IResponseFeature[0]); var response = TestHelper.CreateResponse(headers: new Dictionary <string, string> { { "Refresh", "5; url=http://NotImportant" } }); service.SetupGet(s => s.IsAsynch).Returns(true); service.SetupGet(s => s.Dispatcher).Returns(dispatcher.Object); new AutoRefresh().Process(chain, response); dispatcher.Verify(d => d.Process(service.Object, It.IsAny <string>(), It.IsAny <Uri>(), It.IsAny <string>())); }
public HttpRemoteResponse Process(ResponseChain chain, HttpRemoteResponse response) { response = chain.Next(response); if (!ShouldRedirect(response)) return response; string uri; if (response.Headers.TryGetValue("Location", out uri) && !String.IsNullOrWhiteSpace(uri)) { chain.Reset(); response = chain.Service.Dispatcher.Process(chain.Service, "GET", new Uri(uri), null); response = chain.Next(response); } return response; }
public HttpRemoteResponse Process(ResponseChain chain, HttpRemoteResponse response) { if (!chain.Service.IsAsynch) { throw new NotSupportedException("AutoRefresh is not supported on synchronous requests"); } response = chain.Next(response); Refresh refresh; if (!ShouldRefresh(response, out refresh) || refresh == null) { return(response); } Thread.Sleep(TimeSpan.FromSeconds(refresh.Seconds)); // TODO: use a better alternative response = chain.Service.Dispatcher.Process(chain.Service, "GET", new Uri(refresh.Uri), null); response = chain.Next(response); return(response); }