예제 #1
0
 private Response GetResponse()
 {
     if (this.invokableWaiterAgent != null)
     {
         return(this.invokableWaiterAgent.Invoke());
     }
     return(agent.Execute(this.configuration));
 }
예제 #2
0
        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));
        }
예제 #3
0
        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));
        }
예제 #4
0
        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));
        }
예제 #5
0
        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));
        }