Example #1
0
        /// <inheritdoc />
        public async Task <DataElement> Update(Instance instance, DataElement dataElement)
        {
            string apiUrl = $"{_platformSettings.ApiStorageEndpoint}instances/{instance.Id}/dataelements/{dataElement.Id}";
            string token  = JwtTokenUtil.GetTokenFromContext(_httpContextAccessor.HttpContext, _settings.RuntimeCookieName);

            JwtTokenUtil.AddTokenToRequestHeader(_client, token);

            HttpResponseMessage response = await _client.PutAsync(apiUrl, dataElement.AsJson());

            if (response.IsSuccessStatusCode)
            {
                DataElement result = JsonConvert.DeserializeObject <DataElement>(await response.Content.ReadAsStringAsync());

                return(result);
            }

            throw new PlatformHttpException(response);
        }
Example #2
0
        private async Task <List <DataElement> > CreateInstanceWithData(int count)
        {
            List <DataElement> dataElements = new List <DataElement>();

            // create instance
            Instance newInstance = await storageClient.PostInstances(testAppId, testInstanceOwnerId);

            for (int i = 0; i < count; i++)
            {
                object jsonContent = new
                {
                    number   = i,
                    universe = 42,
                    årsjul   = 365,
                    text     = "Fem flotte åer er bedre en to ærlige øl!",
                };

                string requestUri = $"{versionPrefix}/instances/{newInstance.Id}/data?dataType={dataType}";

                // post the file
                HttpResponseMessage postResponse = await client.PostAsync(requestUri, jsonContent.AsJson());

                DataElement dataElement = JsonConvert.DeserializeObject <DataElement>(await postResponse.Content.ReadAsStringAsync());

                // update downloaded structure on data element
                dataElement.AppOwner ??= new ApplicationOwnerDataState();
                dataElement.AppOwner.Downloaded = new List <DateTime>();
                dataElement.AppOwner.Downloaded.Add(DateTime.UtcNow);

                requestUri = $"{versionPrefix}/instances/{newInstance.Id}/dataelements/{dataElement.Id}";
                HttpResponseMessage putResponse = await client.PutAsync(requestUri, dataElement.AsJson());

                dataElements.Add(JsonConvert.DeserializeObject <DataElement>(await putResponse.Content.ReadAsStringAsync()));
            }

            return(dataElements);
        }
        public async void Put_OnLockedDataElement_ReturnsConflict()
        {
            if (!blobSetup)
            {
                await EnsureValidStorage();
            }

            List <DataElement> dataElements = await CreateInstanceWithData(1);

            DataElement dataElement = dataElements[0];

            Assert.NotNull(dataElement);

            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", _validToken);
            string instanceId = $"{testInstanceOwnerId}/{dataElement.instanceGuid}";
            string dataElementResourcePath = $"{versionPrefix}/instances/{instanceId}/dataelements/{dataElement.Id}";
            string dataResourcePath        = $"{versionPrefix}/instances/{instanceId}/data/{dataElement.Id}";

            // Lock and update data element
            dataElement.Locked = true;
            HttpResponseMessage putDataelementResponse = await client.PutAsync($"{dataElementResourcePath}", dataElement.AsJson());

            putDataelementResponse.EnsureSuccessStatusCode();

            // Attemt to upload data file
            HttpResponseMessage putDataReponse = await client.PutAsync($"{dataResourcePath}", new StringContent("any content"));

            Assert.Equal(HttpStatusCode.Conflict, putDataReponse.StatusCode);
        }