private Response GetResponse() { if (this.invokableWaiterAgent != null) { return(this.invokableWaiterAgent.Invoke()); } return(agent.Execute(this.configuration)); }
public void ExecuteWithUndesiredResponseState() { Mock <Func <IOciRequest, Task <IOciResponse> > > queryMock = new Mock <Func <IOciRequest, Task <IOciResponse> > >(); queryMock.Setup(method => method(It.IsAny <IOciRequest>())).ReturnsAsync(responseMock.Object); var agent = new WaiterAgent <IOciRequest, IOciResponse>( requestMock.Object, queryMock.Object, _ => false ); var waiterConfig = new WaiterConfiguration() { // no sleep time GetNextDelayInSeconds = retryAttempt => 0 }; try { agent.Execute(waiterConfig); } catch (WaitConditionFailedException) { } queryMock.Verify(mock => mock.Invoke(It.IsAny <IOciRequest>()), Times.Exactly(waiterConfig.MaxAttempts + 1)); }
public void ExecuteWithNonSuccessfulResponseStates() { WaiterConfiguration waitConfig = new WaiterConfiguration(); Mock <Func <IOciRequest, Task <IOciResponse> > > queryMock = new Mock <Func <IOciRequest, Task <IOciResponse> > >(); queryMock.Setup(method => method(It.IsAny <IOciRequest>())).ThrowsAsync(new OciException(System.Net.HttpStatusCode.BadGateway, "", "", "")); var agent = new WaiterAgent <IOciRequest, IOciResponse>( requestMock.Object, queryMock.Object, _ => false ); Assert.Throws <OciException>(() => agent.Execute(waitConfig)); }
public void ExecuteWithSuccessfulResponse() { Mock <Func <IOciRequest, Task <IOciResponse> > > queryMock = new Mock <Func <IOciRequest, Task <IOciResponse> > >(); queryMock.Setup(method => method(It.IsAny <IOciRequest>())).ReturnsAsync(responseMock.Object); var agent = new WaiterAgent <IOciRequest, IOciResponse>( requestMock.Object, queryMock.Object, _ => true ); var response = agent.Execute(new WaiterConfiguration()); queryMock.Verify(mock => mock.Invoke(It.IsAny <IOciRequest>()), Times.Exactly(1)); }
public void ExecuteWithAllowed404s() { WaiterConfiguration waitConfig = new WaiterConfiguration(); Mock <Func <IOciRequest, Task <IOciResponse> > > queryMock = new Mock <Func <IOciRequest, Task <IOciResponse> > >(); queryMock.Setup(method => method(It.IsAny <IOciRequest>())).ThrowsAsync(new OciException(System.Net.HttpStatusCode.BadGateway, "", "", "", new OciException(System.Net.HttpStatusCode.NotFound, "", "", ""))); var agent = new WaiterAgent <IOciRequest, IOciResponse>( requestMock.Object, queryMock.Object, _ => false, allow404s: true ); var response = agent.Execute(waitConfig); Assert.Null(response); queryMock.Verify(mock => mock.Invoke(It.IsAny <IOciRequest>()), Times.Exactly(1)); }