public void Create_CallsCreateWithExpectedArgs() { var api = new ScriptedAzureManagementLowLevelApiFake(); var wasCalled = false; api.Script.Add(() => wasCalled = true); api.Script.Add(() => api.NextRequestStatus = AzureRequestStatus.Succeeded); var azureManagement = new AzureManagementApiWithRetries(api, 2, TimeSpan.FromMilliseconds(30000)); var config = MockRepository.GenerateStub<IDeploymentConfiguration>(); azureManagement.Create(FooUri, config); Assert.That(wasCalled, "was called"); Assert.That(api.BeginCreateDeploymentUri, Is.EqualTo(FooUri), "deployment uri"); Assert.That(api.BeginCreateConfiguration, Is.SameAs(config)); }
public void Create_RetriesOnExpectedExceptionAndThrowsOnUnexpected() { using (SpinLoop.ForTests(i => { })) { var api = new ScriptedAzureManagementLowLevelApiFake(); api.Script.Add(() => { throw new UnhandledHttpException(); }); api.Script.Add(() => { throw new ArgumentException(); }); api.Script.Add(() => api.NextRequestStatus = AzureRequestStatus.Succeeded); var azureManagement = new AzureManagementApiWithRetries( api, 2, TimeSpan.FromMilliseconds(30000)); var config = MockRepository.GenerateStub<IDeploymentConfiguration>(); Assert.That( () => azureManagement.Create(FooUri, config), Throws.ArgumentException); } }
public void Create_RetriesTheRightNumberOfTimesThenGivesUpAndThrowsIfException() { var sleepCount = 0; using (SpinLoop.ForTests(i => { sleepCount++; })) { var api = new ScriptedAzureManagementLowLevelApiFake(); api.Script.Add(() => { throw new UnhandledHttpException(); }); api.Script.Add(() => { throw new UnhandledHttpException(); }); api.Script.Add(() => { throw new UnhandledHttpException(); }); api.Script.Add(() => api.NextRequestStatus = AzureRequestStatus.Succeeded); var azureManagement = new AzureManagementApiWithRetries( api, 2, TimeSpan.FromMilliseconds(30000)); var config = MockRepository.GenerateStub<IDeploymentConfiguration>(); Assert.That( () => azureManagement.Create(FooUri, config), Throws.TypeOf<MaxRetriesExceededException>().With.InnerException.TypeOf<UnhandledHttpException>()); Assert.That(sleepCount, Is.EqualTo(2)); } }
public void Create_RetriesTheCreateWhenRequestStatusReturnsFailed() { using (SpinLoop.ForTests(i => { })) { var api = new ScriptedAzureManagementLowLevelApiFake(); var createCallCount = 0; var requestId = 12345; Action incrCallCount = () => { createCallCount++; api.NextRequestId = (++requestId).ToString(); }; api.Script.Add(incrCallCount); api.Script.Add(() => api.NextRequestStatus = AzureRequestStatus.InProgress); api.Script.Add(() => api.NextRequestStatus = AzureRequestStatus.Failed); api.Script.Add(incrCallCount); api.Script.Add(() => api.NextRequestStatus = AzureRequestStatus.Succeeded); var azureManagement = new AzureManagementApiWithRetries( api, 2, TimeSpan.FromMilliseconds(30000)); var config = MockRepository.GenerateStub<IDeploymentConfiguration>(); azureManagement.Create(FooUri, config); Assert.That(createCallCount, Is.EqualTo(2)); var expectedUri = FooUri.ToRequestUri(api.NextRequestId); Assert.That(api.LastCheckRequestStatusRequestUri, Is.EqualTo(expectedUri)); } }