public void ThrowsOnAnythingOtherThanAccepted()
        {
            var http = new ScriptedHttpFake();

            http.Script.Add(() => http.NextResponse = new HttpResponse(HttpStatusCode.ServiceUnavailable, ""));

            var api = new AzureManagementLowLevelApi(http);
            Assert.That(() => api.BeginSuspend(TestDeploymentUri), Throws.TypeOf<UnhandledHttpException>());
        }
        public void Http409ConflictReturnsNull()
        {
            var http = new ScriptedHttpFake();

            http.Script.Add(() => http.NextResponse = new HttpResponse(HttpStatusCode.Conflict, ""));

            var api = new AzureManagementLowLevelApi(http);
            Assert.That(api.BeginSuspend(TestDeploymentUri), Is.Null, "RequestUri should be null on 409 conflict");
        }
        public void Http409ConflictReturnsNull()
        {
            var http = new ScriptedHttpFake();

            http.Script.Add(() => http.NextResponse = new HttpResponse(HttpStatusCode.Conflict, ""));

            var api = new AzureManagementLowLevelApi(http);
            var config = MockRepository.GenerateStub<IDeploymentConfiguration>();
            Assert.That(api.BeginCreate(TestDeploymentUri, config), Is.Null, "Should return null on 409 conflict");
        }
        public void SendsCorrectDeleteUri()
        {
            var http = new ScriptedHttpFake();

            http.Script.Add(() => http.NextResponse = new HttpResponse(HttpStatusCode.Accepted, ""));

            var api = new AzureManagementLowLevelApi(http);
            api.BeginDelete(TestDeploymentUri);

            Assert.That(http.LastDeleteUri, Is.EqualTo(TestDeploymentUri.ToString()), "deploymentUri parameter incorrect");
        }
        public void ReturnsRunningTransitioningIfRunningTransitioning()
        {
            var http = new ScriptedHttpFake();

            http.Script.Add(() => http.NextResponse = new HttpResponse(HttpStatusCode.OK, "<xml><Status>RunningTransitioning</Status></xml>"));

            var api = new AzureManagementLowLevelApi(http);
            var status = api.CheckDeploymentStatus(TestDeploymentUri);

            Assert.That(status, Is.EqualTo(AzureDeploymentCheckOutcome.RunningTransitioning));
        }
        public void ReturnsNotFoundIfStatusCode404()
        {
            var http = new ScriptedHttpFake();

            http.Script.Add(() => http.NextResponse = new HttpResponse(HttpStatusCode.NotFound, ""));

            var api = new AzureManagementLowLevelApi(http);
            var status = api.CheckDeploymentStatus(TestDeploymentUri);

            Assert.That(status, Is.EqualTo(AzureDeploymentCheckOutcome.NotFound));
        }
        public void ReturnsFailedOnWebExceptionsNotHandledByHttpGet()
        {
            var http = new ScriptedHttpFake();

            http.Script.Add(() => { throw new UnhandledHttpException(); });

            var api = new AzureManagementLowLevelApi(http);
            var status = api.CheckDeploymentStatus(TestDeploymentUri);

            Assert.That(status, Is.EqualTo(AzureDeploymentCheckOutcome.Failed));
        }
        public void CheckRequestStatus_Succeeded()
        {
            var http = new ScriptedHttpFake();
            http.Script.Add(() => http.NextResponse = new HttpResponse(HttpStatusCode.Accepted, "<Status>Succeeded</Status>"));
            var api = new AzureManagementLowLevelApi(http);

            var requestStatus = api.CheckRequestStatus(TestUrl);

            Assert.That(requestStatus, Is.EqualTo(AzureRequestStatus.Succeeded), "request status");
            Assert.That(http.LastGetUri, Is.EqualTo("https://management.core.windows.net/subId/operations/requestId"), "operation URI");
        }
        public void ThrowsOnAnythingOtherThanAcceptedAndConflict()
        {
            var http = new ScriptedHttpFake();

            http.Script.Add(() => http.NextResponse = new HttpResponse(HttpStatusCode.InternalServerError, ""));

            var api = new AzureManagementLowLevelApi(http);
            var config = MockRepository.GenerateStub<IDeploymentConfiguration>();
            Assert.That(
                () => api.BeginCreate(TestDeploymentUri, config),
                Throws.TypeOf<UnhandledHttpException>());
        }
        public void SendsCorrectPostArguments()
        {
            var http = new ScriptedHttpFake();

            http.Script.Add(() => http.NextResponse = new HttpResponse(HttpStatusCode.Accepted, ""));

            var api = new AzureManagementLowLevelApi(http);
            api.BeginSuspend(TestDeploymentUri);

            Assert.That(http.LastPostUri, Is.EqualTo(TestDeploymentUri + "/?comp=status"), "deploymentUri parameter incorrect");
            Assert.That(http.LastPostContent, Contains.Substring("<UpdateDeploymentStatus "), "is an updateDeploymentStatus request");
            Assert.That(http.LastPostContent, Contains.Substring("<Status>Suspended</Status>"), "has the appropriate status");
        }
        public void SendsCorrectArguments()
        {
            var http = new ScriptedHttpFake();

            http.Script.Add(() => http.NextResponse = new HttpResponse(HttpStatusCode.Accepted, "", "requestId"));

            var api = new AzureManagementLowLevelApi(http);

            var config = MockRepository.GenerateStub<IDeploymentConfiguration>();
            config.Stub(x => x.MakeCreateDeploymentMessage()).Return("foo");
            var requestUrl = api.BeginCreate(TestDeploymentUri, config);

            Assert.That(http.LastPostUri, Is.EqualTo(TestDeploymentUri.ToString()), "deploymentUri parameter incorrect");
            Assert.That(http.LastPostContent, Is.EqualTo("foo"), "expected xml was passed");

            var expectedRequestUri = TestDeploymentUri.ToRequestUri("requestId");
            Assert.That(requestUrl, Is.EqualTo(expectedRequestUri));
        }
        public void SendsCorrectUri()
        {
            var http = new ScriptedHttpFake();

            http.Script.Add(() => http.NextResponse = new HttpResponse(HttpStatusCode.OK, "<xml><Status>Suspended</Status></xml>"));

            var api = new AzureManagementLowLevelApi(http);
            api.CheckDeploymentStatus(TestDeploymentUri);

            Assert.That(http.LastGetUri, Is.EqualTo(TestDeploymentUri.ToString()));
        }