/// <inheritdoc/> public async Task <SupervisorListModel> QuerySupervisorsAsync( SupervisorQueryModel model, bool onlyServerState, int?pageSize, CancellationToken ct) { var query = "SELECT * FROM devices.modules WHERE " + $"properties.reported.{TwinProperty.Type} = '{IdentityType.Supervisor}'"; if (model?.SiteId != null) { // If site id provided, include it in search query += $"AND (properties.reported.{TwinProperty.SiteId} = " + $"'{model.SiteId}' OR properties.desired.{TwinProperty.SiteId} = " + $"'{model.SiteId}' OR deviceId = '{model.SiteId}') "; } if (EndpointInfoModelEx.IsEndpointId(model?.EndpointId)) { // If endpoint id provided include in search query += $"AND IS_DEFINED(properties.desired.{model.EndpointId}) "; } if (model?.Connected != null) { // If flag provided, include it in search if (model.Connected.Value) { query += $"AND connectionState = 'Connected' "; // Do not use connected property as module might have exited before updating. } else { query += $"AND (connectionState = 'Disconnected' " + $"OR properties.reported.{TwinProperty.Connected} != true) "; } } var queryResult = await _iothub.QueryDeviceTwinsAsync(query, null, pageSize, ct); return(new SupervisorListModel { ContinuationToken = queryResult.ContinuationToken, Items = queryResult.Items .Select(t => t.ToSupervisorRegistration(onlyServerState)) .Select(s => s.ToServiceModel()) .ToList() }); }
public void GetTwinThatExists() { CreateEndpointFixtures(out var site, out var super, out var endpoints, out var devices); var first = endpoints.First(); var id = EndpointInfoModelEx.CreateEndpointId(first.ApplicationId, first.Registration.EndpointUrl, first.Registration.Endpoint.SecurityMode, first.Registration.Endpoint.SecurityPolicy); using (var mock = AutoMock.GetLoose()) { mock.Provide <IIoTHubTwinServices>(new IoTHubServices(devices)); var service = mock.Create <RegistryServices>(); // Run var result = service.GetEndpointAsync(id, false).Result; // Assert Assert.True(result.IsSameAs(endpoints.First())); } }
public void GetTwinThatExists() { CreateEndpointFixtures(out var site, out var super, out var endpoints, out var devices); var first = endpoints.First(); var id = EndpointInfoModelEx.CreateEndpointId(first.ApplicationId, first.Registration.EndpointUrl, first.Registration.Endpoint.SecurityMode, first.Registration.Endpoint.SecurityPolicy); using (var mock = AutoMock.GetLoose(builder => { var hub = IoTHubServices.Create(devices); builder.RegisterType <NewtonSoftJsonConverters>().As <IJsonSerializerConverterProvider>(); builder.RegisterType <NewtonSoftJsonSerializer>().As <IJsonSerializer>(); builder.RegisterInstance(hub).As <IIoTHubTwinServices>(); })) { IEndpointRegistry service = mock.Create <EndpointRegistry>(); // Run var result = service.GetEndpointAsync(id, false).Result; // Assert Assert.True(result.IsSameAs(endpoints.First())); } }