public void ListAllMatchingResourcesTest() { using (ShimsContext.Create()) { MockClients clients = new MockClients(); string json = @"[ { ""sha1"": ""347f832f72ab92dc7afbc0f5af251b94f3fe7f88"", ""size"": 36 } ]"; clients.JsonResponse = json; clients.ExpectedStatusCode = (HttpStatusCode)200; var cfClient = clients.CreateCloudFoundryClient(); ListAllMatchingResourcesRequest[] value = new ListAllMatchingResourcesRequest[0]; var obj = cfClient.ResourceMatch.ListAllMatchingResources(value).Result; Assert.AreEqual("347f832f72ab92dc7afbc0f5af251b94f3fe7f88", TestUtil.ToTestableString(obj[0].Sha1), true); Assert.AreEqual("36", TestUtil.ToTestableString(obj[0].Size), true); } }
public void TestListAllMatchingResourcesRequest() { string json = @"[ { ""sha1"": ""f501983374a01de97a27e6d1f1c2608cbc3cdf9d"", ""size"": 36 }, { ""sha1"": ""a9993e364706816aba3e25717850c26c9cd0d89d"", ""size"": 1 } ]"; ListAllMatchingResourcesRequest[] request = new ListAllMatchingResourcesRequest[2]; request[0] = new ListAllMatchingResourcesRequest(); request[0].Sha1 = "f501983374a01de97a27e6d1f1c2608cbc3cdf9d"; request[0].Size = 36; request[1] = new ListAllMatchingResourcesRequest(); request[1].Sha1 = "a9993e364706816aba3e25717850c26c9cd0d89d"; request[1].Size = 1; string result = JsonConvert.SerializeObject(request, Formatting.None); Assert.AreEqual(TestUtil.ToUnformatedJsonString(json), result); }
public void TestListAllMatchingResourcesRequest() { string json = @"[ { ""sha1"": ""286e4d660a1c2d7b730d69e363db93fb515ef7f8"", ""size"": 36 }, { ""sha1"": ""a9993e364706816aba3e25717850c26c9cd0d89d"", ""size"": 1 } ]"; ListAllMatchingResourcesRequest[] request = new ListAllMatchingResourcesRequest[2]; request[0] = new ListAllMatchingResourcesRequest(); request[0].Sha1 = "286e4d660a1c2d7b730d69e363db93fb515ef7f8"; request[0].Size = 36; request[1] = new ListAllMatchingResourcesRequest(); request[1].Sha1 = "a9993e364706816aba3e25717850c26c9cd0d89d"; request[1].Size = 1; string result = JsonConvert.SerializeObject(request, Formatting.None); Assert.AreEqual(TestUtil.ToUnformatedJsonString(json), result); }
public void TestListAllMatchingResourcesRequest() { string json = @"[ { ""sha1"": ""44e106ddccb33b7ad4bb1c888d8921e8931d2734"", ""size"": 36 }, { ""sha1"": ""a9993e364706816aba3e25717850c26c9cd0d89d"", ""size"": 1 } ]"; ListAllMatchingResourcesRequest[] request = new ListAllMatchingResourcesRequest[2]; request[0] = new ListAllMatchingResourcesRequest(); request[0].Sha1 = "44e106ddccb33b7ad4bb1c888d8921e8931d2734"; request[0].Size = 36; request[1] = new ListAllMatchingResourcesRequest(); request[1].Sha1 = "a9993e364706816aba3e25717850c26c9cd0d89d"; request[1].Size = 1; string result = JsonConvert.SerializeObject(request, Formatting.None); Assert.AreEqual(TestUtil.ToUnformatedJsonString(json), result); }
public void TestListAllMatchingResourcesRequest() { string json = @"[ { ""sha1"": ""347f832f72ab92dc7afbc0f5af251b94f3fe7f88"", ""size"": 36 }, { ""sha1"": ""a9993e364706816aba3e25717850c26c9cd0d89d"", ""size"": 1 } ]"; ListAllMatchingResourcesRequest[] request = new ListAllMatchingResourcesRequest[2]; request[0] = new ListAllMatchingResourcesRequest(); request[0].Sha1 = "347f832f72ab92dc7afbc0f5af251b94f3fe7f88"; request[0].Size = 36; request[1] = new ListAllMatchingResourcesRequest(); request[1].Sha1 = "a9993e364706816aba3e25717850c26c9cd0d89d"; request[1].Size = 1; string result = JsonConvert.SerializeObject(request, Formatting.None); Assert.AreEqual(TestUtil.ToUnformatedJsonString(json), result); }
/// <summary> /// List all matching resources /// <para>For detailed information, see online documentation at: "http://apidocs.cloudfoundry.org/195/resource_match/list_all_matching_resources.html"</para> /// </summary> public async Task<ListAllMatchingResourcesResponse[]> ListAllMatchingResources(ListAllMatchingResourcesRequest[] value) { UriBuilder uriBuilder = new UriBuilder(this.Client.CloudTarget); uriBuilder.Path = "/v2/resource_match"; 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.DeserializeJsonArray<ListAllMatchingResourcesResponse>(await response.ReadContentAsStringAsync()); }
/// <summary> /// Filters the files that already exist on the server. /// </summary> /// <param name="fingerprints">The key of the dictionary is an SHA1 fingerprint</param> /// <returns>A list of files that do not exist on the server.</returns> private async Task <string[]> FilterExistingFiles(Dictionary <string, List <FileFingerprint> > fingerprints) { Dictionary <string, List <FileFingerprint> > filteredResources = new Dictionary <string, List <FileFingerprint> >(); List <ListAllMatchingResourcesRequest> matchRequest = new List <ListAllMatchingResourcesRequest>(); // Loop through each fingerprint and construct our request foreach (KeyValuePair <string, List <FileFingerprint> > fingerprintList in fingerprints) { foreach (FileFingerprint fingerprint in fingerprintList.Value) { ListAllMatchingResourcesRequest match = new ListAllMatchingResourcesRequest() { Sha1 = fingerprint.SHA1, Size = fingerprint.Size }; matchRequest.Add(match); } // We're building the response with all fingerprints, // matches will be removed after the server replies filteredResources.Add(fingerprintList.Key, fingerprintList.Value); } ListAllMatchingResourcesResponse[] response = await this.Client.ResourceMatch.ListAllMatchingResources(matchRequest.ToArray()); // If the request was cancelled, return immediately if (this.CheckCancellation()) { return(filteredResources.Values.SelectMany(list => list.Select(f => f.FileName)).ToArray()); } // Remove all server matches from our result foreach (ListAllMatchingResourcesResponse resource in response) { filteredResources.Remove(resource.Sha1); } return(filteredResources.Values.SelectMany(list => list.Select(f => f.FileName)).ToArray()); }
public void ListAllMatchingResourcesTest() { using (ShimsContext.Create()) { MockClients clients = new MockClients(); string json = @"[{""sha1"":""286e4d660a1c2d7b730d69e363db93fb515ef7f8"",""size"":36}]"; clients.JsonResponse = json; clients.ExpectedStatusCode = (HttpStatusCode)200; var cfClient = clients.CreateCloudFoundryClient(); ListAllMatchingResourcesRequest[] value = new ListAllMatchingResourcesRequest[0]; var obj = cfClient.ResourceMatch.ListAllMatchingResources(value).Result; Assert.AreEqual("286e4d660a1c2d7b730d69e363db93fb515ef7f8", TestUtil.ToTestableString(obj[0].Sha1), true); Assert.AreEqual("36", TestUtil.ToTestableString(obj[0].Size), true); } }
public void ListAllMatchingResourcesTest() { using (ShimsContext.Create()) { MockClients clients = new MockClients(); string json = @"[{""sha1"":""44e106ddccb33b7ad4bb1c888d8921e8931d2734"",""size"":36}]"; clients.JsonResponse = json; clients.ExpectedStatusCode = (HttpStatusCode)200; var cfClient = clients.CreateCloudFoundryClient(); ListAllMatchingResourcesRequest[] value = new ListAllMatchingResourcesRequest[0]; var obj = cfClient.ResourceMatch.ListAllMatchingResources(value).Result; Assert.AreEqual("44e106ddccb33b7ad4bb1c888d8921e8931d2734", TestUtil.ToTestableString(obj[0].Sha1), true); Assert.AreEqual("36", TestUtil.ToTestableString(obj[0].Size), true); } }
/// <summary> /// Filters the files that already exist on the server. /// </summary> /// <param name="fingerprints">The key of the dictionary is an SHA1 fingerprint</param> /// <returns>A list of files that do not exist on the server.</returns> private async Task<HashSet<string>> FilterExistingFiles(Dictionary<string, List<FileFingerprint>> fingerprints) { Dictionary<string, List<FileFingerprint>> filteredResources = new Dictionary<string, List<FileFingerprint>>(); List<ListAllMatchingResourcesRequest> matchRequest = new List<ListAllMatchingResourcesRequest>(); // Loop through each fingerprint and construct our request foreach (KeyValuePair<string, List<FileFingerprint>> fingerprintList in fingerprints) { var fingerprint = fingerprintList.Value.First(); ListAllMatchingResourcesRequest match = new ListAllMatchingResourcesRequest() { Sha1 = fingerprint.SHA1, Size = fingerprint.Size }; matchRequest.Add(match); // We're building the response with all fingerprints, // matches will be removed after the server replies filteredResources.Add(fingerprintList.Key, fingerprintList.Value); } ListAllMatchingResourcesResponse[] response = await this.Client.ResourceMatch.ListAllMatchingResources(matchRequest.ToArray()); // If the request was cancelled, return immediately if (this.CheckCancellation()) { return new HashSet<string>(filteredResources.Values.SelectMany(list => list.Select(f => f.FileName))); } // Remove all server matches from our result foreach (ListAllMatchingResourcesResponse resource in response) { filteredResources.Remove(resource.Sha1); } return new HashSet<string>(filteredResources.Values.SelectMany(list => list.Select(f => f.FileName))); }