コード例 #1
0
        public void GivenARawResourceInJsonFormat_WhenSerialized_ThenCorrectByteArrayShouldBeProduced()
        {
            var rawResource = new RawResource(
                new FhirJsonSerializer().SerializeToString(_resource),
                FhirResourceFormat.Json);

            ResourceWrapper resourceWrapper = CreateResourceWrapper(rawResource);
            ResourceElement element         = _resourceDeserializaer.DeserializeRaw(resourceWrapper.RawResource, resourceWrapper.Version, resourceWrapper.LastModified);

            byte[] actualBytes = _serializer.Serialize(element);

            Assert.Equal(_expectedBytes, actualBytes);
        }
コード例 #2
0
        private SearchResultEntry CreateSearchResultEntry(string jsonName, IReadOnlyCollection <SearchIndexEntry> searchIndices)
        {
            var json               = Samples.GetJson(jsonName);
            var rawResource        = new RawResource(json, FhirResourceFormat.Json, isMetaSet: false);
            var resourceRequest    = Substitute.For <ResourceRequest>();
            var compartmentIndices = Substitute.For <CompartmentIndices>();
            var resourceElement    = _resourceDeserializer.DeserializeRaw(rawResource, "v1", DateTimeOffset.UtcNow);
            var wrapper            = new ResourceWrapper(resourceElement, rawResource, resourceRequest, false, searchIndices, compartmentIndices, new List <KeyValuePair <string, string> >(), "hash");
            var entry              = new SearchResultEntry(wrapper);

            return(entry);
        }
コード例 #3
0
        /// <inheritdoc />
        public byte[] Serialize(ResourceWrapper resourceWrapper)
        {
            EnsureArg.IsNotNull(resourceWrapper, nameof(resourceWrapper));

            ResourceElement resource = _resourceDeserializer.DeserializeRaw(resourceWrapper.RawResource, resourceWrapper.Version, resourceWrapper.LastModified);

            string resourceData = _fhirJsonSerializer.SerializeToString(resource.ToPoco <Resource>());

            byte[] bytesToWrite = Encoding.UTF8.GetBytes($"{resourceData}\n");

            return(bytesToWrite);
        }
コード例 #4
0
        /// <inheritdoc />
        public byte[] Serialize(ResourceWrapper resourceWrapper)
        {
            EnsureArg.IsNotNull(resourceWrapper, nameof(resourceWrapper));

            string resourceData = null;

            if (resourceWrapper.RawResource.Format == Core.Models.FhirResourceFormat.Json)
            {
                // This is JSON already, we can write as is.
                resourceData = resourceWrapper.RawResource.Data;
            }
            else
            {
                // This is not JSON, so deserialize it and serialize it to JSON.
                ResourceElement resource = _resourceDeserializer.DeserializeRaw(resourceWrapper.RawResource, resourceWrapper.Version, resourceWrapper.LastModified);

                resourceData = _fhirJsonSerializer.SerializeToString(resource.ToPoco <Resource>());
            }

            byte[] bytesToWrite = Encoding.UTF8.GetBytes($"{resourceData}\n");

            return(bytesToWrite);
        }