public async void GetMetadata_InternalServerErrorStatusCode_ThrowsException() { // Arrange var httpResponseMessage = new HttpResponseMessage { StatusCode = HttpStatusCode.InternalServerError, Content = new StringContent("") }; var httpService = new Mock <IHttpService>(); httpService .Setup(m => m.GetAsync(It.IsAny <string>())) .ReturnsAsync(httpResponseMessage); var metadataClient = new MetadataClient(httpService.Object); Exception exception = null; try { // Act await metadataClient.GetMetadata(It.IsAny <string>()); } catch (FailedToGetResourceException e) { exception = e; } // Assert Assert.NotNull(exception); }
public async Task WaitForChange() { const string newValue = "foo"; string key = _fixture.GenerateCustomKey(); await _fixture.UpdateMetadataAsync($"instance/attributes/{key}", "initial value"); var task = Task.Run(async() => { await Task.Delay(TimeSpan.FromSeconds(2)); await _fixture.UpdateMetadataAsync($"instance/attributes/{key}", newValue); }); // Snippet: WaitForChange MetadataClient client = MetadataClient.Create(); // Get the original metadata and its ETag so we know when the metadata changes. MetadataResult initialResult = client.GetMetadata("instance/attributes"); Console.WriteLine("Initial Metadata:"); JObject initialMetadata = JObject.Parse(initialResult.Content); foreach (JProperty property in initialMetadata.Properties()) { Console.WriteLine(property.Name + " = " + property.Value); } string lastETag = initialResult.ETag; MetadataResult changeResult; while (true) { // Wait in 30 second blocks until the value actually changes. changeResult = client.WaitForChange("instance/attributes", lastETag, TimeSpan.FromSeconds(30)); if (changeResult.ETag != lastETag) { Console.WriteLine("Changed Metadata:"); JObject currentMetadata = JObject.Parse(changeResult.Content); foreach (JProperty property in currentMetadata.Properties()) { Console.WriteLine(property.Name + " = " + property.Value); } break; } } // End snippet dynamic obj = JsonConvert.DeserializeObject(changeResult.Content); Assert.Equal(newValue, obj[key].Value); await task; }
public void GetMetadata() { // Snippet: GetMetadata MetadataClient client = MetadataClient.Create(); MetadataResult result = client.GetMetadata("instance/attributes"); JObject initialMetadata = JObject.Parse(result.Content); foreach (JProperty property in initialMetadata.Properties()) { Console.WriteLine(property.Name + " = " + property.Value); } // End snippet }
public async void GetMetadata_ValidMetadataId_ReturnsMetadataModel() { // Arrange var metadataId = "4439722e-a6d0-4f7a-9d33-0cc5a2a66da0"; var httpService = new HttpService(new HttpClient()); var metadataClient = new MetadataClient( httpService ); // Act var result = await metadataClient.GetMetadata(metadataId); // Assert Assert.NotNull(result); }
public async void GetMetadata_OkStatusCode_ReturnsMetadataModel() { // Arrange var httpResponseMessage = new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent(MetadataModelDataMocks.MockToBeDeletedMetadataModelJson) }; var httpService = new Mock <IHttpService>(); httpService .Setup(m => m.GetAsync(It.IsAny <string>())) .ReturnsAsync(httpResponseMessage); var metadataClient = new MetadataClient(httpService.Object); // Act var result = await metadataClient.GetMetadata(It.IsAny <string>()); // Assert Assert.NotNull(result); }