public void ReadQueryTest(Common.Enums.FhirVersion fhirVersion, string resourceName, string resourceId) { //Setup var IOperationOutcomeSupportMock = IOperationOutcomeSupport_MockFactory.Get(); var IFhirResourceNameSupportMock = IFhirResourceNameSupport_MockFactory.Get(resourceName); var IFhirResourceIdSupportMock = IFhirResourceIdSupport_MockFactory.Get(resourceId); FhirUriFactory FhirUriFactory = GetFhirUriFactory(resourceName); ValidateQueryService ValidateQueryService = new ValidateQueryService(IOperationOutcomeSupportMock.Object, IFhirResourceNameSupportMock.Object, IFhirResourceIdSupportMock.Object, FhirUriFactory); var ReadQuery = new ReadQuery( HttpVerb.GET, fhirVersion, new Uri($"{TestData.BaseUrlServer}/{resourceName}/{resourceId}"), new Dictionary <string, Microsoft.Extensions.Primitives.StringValues>(), new Dictionary <string, Microsoft.Extensions.Primitives.StringValues>(), resourceName, resourceId); //Act bool Result = ValidateQueryService.IsValid(ReadQuery, out Common.FhirTools.FhirResource? IsNotValidOperationOutCome); //Assert Assert.True(Result); Assert.Null(IsNotValidOperationOutCome); }
public override async Task <TModelEntity> Handle(ReadQuery <TModelEntity, TApiEntityKey> request, CancellationToken cancellationToken) { var result = await CrudApiManager .ExecuteAsync((ct, api) => api.Read(request.Key, request.Priority, ct), cancellationToken) .ConfigureAwait(false); return(Map <TApiEntity, TModelEntity>(result)); }
public void When_InputIsNull_MapThrowsException() { ReadQuery getReadQuery = null; _target = _fixture.Freeze <ReadQueryHandler>(); Assert.ThrowsAsync <ArgumentNullException>(async() => await _target.Handle(getReadQuery, default(CancellationToken))); }
public async Task <IEnumerable <ContactDTO> > Handle(ReadQuery request, CancellationToken cancellationToken) { request.ThrowIfNull(nameof(request)); var contactList = await _service.GetAllContactAsync(); var output = _mapper.Map <IEnumerable <ContactDTO> >(contactList); return(output); }
public async Task <IEnumerable <FApps.Core.DTO.UserDTO> > Handle(ReadQuery request, CancellationToken cancellationToken) { request.ThrowIfNull(nameof(request)); var userList = await _services.GetAllUserAsync(); var output = _mapper.Map <IEnumerable <UserDTO> >(userList); return(output); }
/// <summary> /// Publishes a stream of data for a given schema /// </summary> /// <param name="request"></param> /// <param name="responseStream"></param> /// <param name="context"></param> /// <returns></returns> public override async Task ReadStream(ReadRequest request, IServerStreamWriter <Record> responseStream, ServerCallContext context) { var schema = request.Schema; var limit = request.Limit; var limitFlag = request.Limit > 0; Logger.SetLogPrefix(request.JobId); Logger.Info($"Publishing records for schema: {schema.Name}"); try { var recordsCount = 0; // check if query is empty if (string.IsNullOrWhiteSpace(schema.Query)) { Logger.Info("Query not defined."); return; } // build read record couchDB query ReadQuery readQuery = new ReadQuery { fields = new List <string>(), selector = new JObject() }; // set limit to couchDB query if limitFlag is on if (limitFlag) { readQuery.limit = limit; } foreach (Property property in schema.Properties) { readQuery.fields.Add(property.Name); } var couchdbReadRecordQuery = JsonConvert.SerializeObject(readQuery); // read record from couchDB Logger.Info($"Reading records from {_server.Settings.DatabaseName} database"); var readRecordUri = $"{_server.Settings.DatabaseName}/_find"; var response = await _client.PostAsync(readRecordUri, new StringContent(couchdbReadRecordQuery, Encoding.UTF8, "application/json")); response.EnsureSuccessStatusCode(); var documents = JObject.Parse(await response.Content.ReadAsStringAsync())["docs"]; // build record map if (documents.ToList().Count > 0) { foreach (JObject document in documents) { // build record map var recordMap = new Dictionary <string, object>(); foreach (JProperty property in document.Properties()) { recordMap[property.Name] = property.Value; } //create record var record = new Record { Action = Record.Types.Action.Upsert, DataJson = JsonConvert.SerializeObject(recordMap) }; //publish record await responseStream.WriteAsync(record); recordsCount++; } Logger.Info($"Published {recordsCount} records"); } else { Logger.Info("No record read from database."); } } catch (Exception e) { Logger.Error(e, e.Message, context); } }