public async Task NewDeviceReturnsCreated() { string id = "111"; var metadata = new DeviceMetadata(); IHttpActionResult actionResult = await _controller.PutDeviceMetadata(id, metadata); var createdResult = actionResult as CreatedAtRouteNegotiatedContentResult<DeviceInfo>; Assert.NotNull(createdResult); Assert.Equal("DefaultApi", createdResult.RouteName); Assert.Equal(id, createdResult.RouteValues["id"]); }
public async Task ExistingDeviceReturnsOk() { string id = "112"; var metadata = new DeviceMetadata(); _registry.Setup(x => x.FindAsync(id)) .ReturnsAsync(new DeviceInfo { DeviceId = id }); IHttpActionResult actionResult = await _controller.PutDeviceMetadata(id, metadata); var contentResult = actionResult as OkNegotiatedContentResult<DeviceInfo>; Assert.NotNull(contentResult); Assert.NotNull(contentResult.Content); }
private static async Task RegisterDeviceAsync(CancellationToken token) { string baseUrl = ConfigurationHelper.GetConfigValue<string>("WebApiEndpoint"); HttpClient client = new HttpClient(); client.BaseAddress = new Uri(baseUrl); var metadata = new DeviceMetadata { Building = 1, Room = 42 }; Console.WriteLine("Registering device ID = {0}", DEVICE_ID); var result = await client.PutAsJsonAsync("api/registry/" + DEVICE_ID, metadata, token); Console.WriteLine("{0} ({1})", (int)result.StatusCode, result.ReasonPhrase); if (result.IsSuccessStatusCode) { var info = await result.Content.ReadAsAsync<DeviceInfo>(token); Console.WriteLine("Device state: {0}", info.Status); } }