Beispiel #1
0
        /// <summary>
        /// Stopping an App
        /// <para>For detailed information, see online documentation at: "http://apidocs.cloudfoundry.org/195/apps__experimental_/stopping_an_app.html"</para>
        /// </summary>
        public async Task <StoppingAppResponse> StoppingApp(Guid?guid, StoppingAppRequest value)
        {
            UriBuilder uriBuilder = new UriBuilder(this.Client.CloudTarget);

            uriBuilder.Path = string.Format(CultureInfo.InvariantCulture, "/v3/apps/{0}/stop", guid);
            var client = this.GetHttpClient();

            client.Uri    = uriBuilder.Uri;
            client.Method = HttpMethod.Put;
            var authHeader = await BuildAuthenticationHeader();

            if (!string.IsNullOrWhiteSpace(authHeader.Key))
            {
                client.Headers.Add(authHeader);
            }
            client.ContentType = "application/x-www-form-urlencoded";
            client.Content     = JsonConvert.SerializeObject(value).ConvertToStream();
            var expectedReturnStatus = 200;
            var response             = await this.SendAsync(client, expectedReturnStatus);

            return(Utilities.DeserializeJson <StoppingAppResponse>(await response.ReadContentAsStringAsync()));
        }
Beispiel #2
0
        public void StoppingAppTest()
        {
            using (ShimsContext.Create())
            {
                MockClients clients = new MockClients();

                string json = @"{
  ""guid"": ""guid-1d64d7f4-c300-4ecc-b27b-46342882202d"",
  ""name"": ""original_name"",
  ""desired_state"": ""STOPPED"",
  ""total_desired_instances"": 0,
  ""created_at"": ""2015-06-30T07:10:43Z"",
  ""updated_at"": ""2015-06-30T07:10:43Z"",
  ""environment_variables"": {

  },
  ""_links"": {
    ""self"": {
      ""href"": ""/v3/apps/guid-1d64d7f4-c300-4ecc-b27b-46342882202d""
    },
    ""processes"": {
      ""href"": ""/v3/apps/guid-1d64d7f4-c300-4ecc-b27b-46342882202d/processes""
    },
    ""packages"": {
      ""href"": ""/v3/apps/guid-1d64d7f4-c300-4ecc-b27b-46342882202d/packages""
    },
    ""space"": {
      ""href"": ""/v2/spaces/423cb688-d35d-45bd-aa9d-e360b48ffa6f""
    },
    ""desired_droplet"": {
      ""href"": ""/v3/droplets/guid-cec7a42f-87e7-4841-a87b-3b220bbf7c3e""
    },
    ""start"": {
      ""href"": ""/v3/apps/guid-1d64d7f4-c300-4ecc-b27b-46342882202d/start"",
      ""method"": ""PUT""
    },
    ""stop"": {
      ""href"": ""/v3/apps/guid-1d64d7f4-c300-4ecc-b27b-46342882202d/stop"",
      ""method"": ""PUT""
    },
    ""assign_current_droplet"": {
      ""href"": ""/v3/apps/guid-1d64d7f4-c300-4ecc-b27b-46342882202d/current_droplet"",
      ""method"": ""PUT""
    }
  }
}";
                clients.JsonResponse = json;

                clients.ExpectedStatusCode = (HttpStatusCode)200;
                var cfClient = clients.CreateCloudFoundryClient();

                Guid?guid = Guid.NewGuid();

                StoppingAppRequest value = null;


                var obj = cfClient.Apps.StoppingApp(guid, value).Result;


                Assert.AreEqual("guid-1d64d7f4-c300-4ecc-b27b-46342882202d", TestUtil.ToTestableString(obj.Guid), true);
                Assert.AreEqual("original_name", TestUtil.ToTestableString(obj.Name), true);
                Assert.AreEqual("STOPPED", TestUtil.ToTestableString(obj.DesiredState), true);
                Assert.AreEqual("0", TestUtil.ToTestableString(obj.TotalDesiredInstances), true);
                Assert.AreEqual("2015-06-30T07:10:43Z", TestUtil.ToTestableString(obj.CreatedAt), true);
                Assert.AreEqual("2015-06-30T07:10:43Z", TestUtil.ToTestableString(obj.UpdatedAt), true);
            }
        }