public TResult Execute <TResult>(ICouchCommand couchCommand) { var restRequest = CreateRestRequestFrom(couchCommand); RestResponse <TResult> restResponse = null; try { restResponse = RestClient.Process <TResult>(restRequest, couchCommand.SuccessStatusCode); } catch (UnexpectedHttpResponseException e) { CommandErrorResult errorResult; if (!String.IsNullOrEmpty(e.RawResponse.Content)) { errorResult = Serializer.Deserialize <CommandErrorResult>(e.RawResponse.Content); } else { errorResult = new CommandErrorResult { Error = "Unexpected Exception", Reason = e.RawResponse.Error.Message }; } couchCommand.HandleError(RestClient.BaseUri.ToString(), errorResult, e); } return(restResponse.ContentDeserialized); }
protected override void Given() { restClient = Fake <IRestClient>(); couchCommand = Fake <ICouchCommand>(); couchCommand.Route.Returns("some/path"); couchCommand.Operation.Returns(HttpMethod.Get); couchCommand.SuccessStatusCode.Returns(HttpStatusCode.OK); // TODO: How to tell restClient to throw exception when Process gets called. }
protected override void Given() { restClient = Fake <IRestClient>(); couchCommand = Fake <ICouchCommand>(); couchCommand.Route.Returns("some/path"); couchCommand.Operation.Returns(HttpMethod.Get); couchCommand.SuccessStatusCode.Returns(HttpStatusCode.OK); restResponse = new RestResponse <ResultStub> { ContentType = "application/json", ContentLength = 5, Content = "{\"status\":\"completed\"}", StatusCode = HttpStatusCode.OK, StatusDescription = HttpStatusCode.OK.ToString(), ContentDeserialized = new ResultStub() }; restClient.Process <ResultStub>(Arg.Any <RestRequest>(), Arg.Any <HttpStatusCode>()).Returns(restResponse); }
protected override void Given() { entity1 = new Employee { Name = "Bob", Login = "******" }; restClient = Fake <IRestClient>(); couchCommand = Fake <ICouchCommand>(); couchCommand.Route.Returns("some/path"); couchCommand.Operation.Returns(HttpMethod.Post); couchCommand.Message.Returns(entity1); couchCommand.SuccessStatusCode.Returns(HttpStatusCode.Created); restResponse = new RestResponse <ResultStub> { ContentType = "application/json", ContentLength = 5, Content = "{\"status\":\"completed\"}", StatusCode = HttpStatusCode.Created, StatusDescription = HttpStatusCode.Created.ToString(), ContentDeserialized = new ResultStub() }; restClient.Process <ResultStub>(Arg.Any <RestRequest>(), Arg.Any <HttpStatusCode>()).Returns(restResponse); }
protected static void WireUpCommandMock(ICouchCommand commandMock) { ObjectFactory.Configure(x => x.For<ICouchCommand>().Use(commandMock)); }
private RestRequest CreateRestRequestFrom(ICouchCommand couchCommand) { return(new RestRequest { Path = couchCommand.Route, Method = couchCommand.Operation, Payload = couchCommand.Message }); }