public async void SoftdeleteApplication() { string applicationId = "TEST-app21"; string requestUri = $"{versionPrefix}/applications?applicationId={applicationId}"; ApplicationMetadata appInfo = CreateApplicationMetadata(applicationId); HttpResponseMessage postResponse = await client.PostAsync(requestUri, appInfo.AsJson()); postResponse.EnsureSuccessStatusCode(); string json = await postResponse.Content.ReadAsStringAsync(); ApplicationMetadata existingApplication = JsonConvert.DeserializeObject <ApplicationMetadata>(json); // do the delete requestUri = $"{versionPrefix}/applications/{applicationId}"; HttpResponseMessage deleteResponse = await client.DeleteAsync(requestUri); deleteResponse.EnsureSuccessStatusCode(); string content = await deleteResponse.Content.ReadAsStringAsync(); ApplicationMetadata softDeletedApplication = JsonConvert.DeserializeObject <ApplicationMetadata>(content); Assert.NotEqual(softDeletedApplication.ValidTo, existingApplication.ValidTo); Assert.True(softDeletedApplication.ValidTo < DateTime.UtcNow); }
public ApplicationMetadata CreateApplication(string applicationId, Dictionary <string, string> title) { ApplicationMetadata appMetadata = new ApplicationMetadata { Id = applicationId, Title = title, Forms = new List <ApplicationForm>() }; ApplicationForm defaultAppForm = new ApplicationForm { Id = "default", AllowedContentType = new List <string>() { "application/xml" } }; appMetadata.Forms.Add(defaultAppForm); string url = endpointUri + resourcePrefix + "?applicationId=" + applicationId; HttpResponseMessage response = client.PostAsync(url, appMetadata.AsJson()).Result; response.EnsureSuccessStatusCode(); string json = response.Content.ReadAsStringAsync().Result; ApplicationMetadata application = JsonConvert.DeserializeObject <ApplicationMetadata>(json); return(application); }
public async void CreateApplicationWrongFormatApplicationId() { string applicationId = "TEST/app"; string requestUri = $"{versionPrefix}/applications?applicationId={applicationId}"; ApplicationMetadata appInfo = CreateApplicationMetadata(applicationId); HttpResponseMessage postResponse = await client.PostAsync(requestUri, appInfo.AsJson()); Assert.Equal(HttpStatusCode.BadRequest, postResponse.StatusCode); }
public ApplicationMetadata CreateApplication(ApplicationMetadata application) { string url = $"{endpointUri}/{resourcePrefix}?applicationId={application.Id}"; HttpResponseMessage response = client.PostAsync(url, application.AsJson()).Result; response.EnsureSuccessStatusCode(); string json = response.Content.ReadAsStringAsync().Result; ApplicationMetadata result = JsonConvert.DeserializeObject <ApplicationMetadata>(json); return(result); }
public async void CreateApplicationMetadataHappyDays() { string applicationId = "TEST-app20"; string requestUri = $"{versionPrefix}/applications?applicationId={applicationId}"; ApplicationMetadata appInfo = CreateApplicationMetadata(applicationId); HttpResponseMessage postResponse = await client.PostAsync(requestUri, appInfo.AsJson()); postResponse.EnsureSuccessStatusCode(); string content = postResponse.Content.ReadAsStringAsync().Result; logger.Information(content); }
public async void GetAndUpdateApplication() { string applicationId = "TEST-app22"; string requestUri = $"{versionPrefix}/applications?applicationId={applicationId}"; ApplicationMetadata appInfo = CreateApplicationMetadata(applicationId); // create one HttpResponseMessage postResponse = await client.PostAsync(requestUri, appInfo.AsJson()); postResponse.EnsureSuccessStatusCode(); requestUri = $"{versionPrefix}/applications/{applicationId}"; // read one HttpResponseMessage getResponse = await client.GetAsync(requestUri); getResponse.EnsureSuccessStatusCode(); string json = await getResponse.Content.ReadAsStringAsync(); ApplicationMetadata application = JsonConvert.DeserializeObject <ApplicationMetadata>(json); application.MaxSize = 2000; // update it HttpResponseMessage putResponse = await client.PutAsync(requestUri, application.AsJson()); putResponse.EnsureSuccessStatusCode(); // get it again HttpResponseMessage getResponse2 = await client.GetAsync(requestUri); getResponse2.EnsureSuccessStatusCode(); string json2 = await getResponse2.Content.ReadAsStringAsync(); ApplicationMetadata application2 = JsonConvert.DeserializeObject <ApplicationMetadata>(json2); Assert.Equal(application.MaxSize, application2.MaxSize); }
private async Task <bool> RegisterApplicationInStorage(string applicationOwnerId, string applicationCode, string versionId) { bool applicationInStorage = false; ApplicationMetadata applicationMetadataFromRepository = _repository.GetApplicationMetadata(applicationOwnerId, applicationCode); using (HttpClient client = new HttpClient()) { string applicationId = $"{applicationOwnerId}-{applicationCode}"; string storageEndpoint = _platformSettings.GetApiStorageEndpoint; ApplicationMetadata application = null; string getApplicationMetadataUrl = $"{storageEndpoint}applications/{applicationId}"; HttpResponseMessage getApplicationMetadataResponse = await client.GetAsync(getApplicationMetadataUrl); if (getApplicationMetadataResponse.IsSuccessStatusCode) { string json = getApplicationMetadataResponse.Content.ReadAsStringAsync().Result; application = JsonConvert.DeserializeObject <ApplicationMetadata>(json); applicationInStorage = true; if (application.Title == null) { application.Title = new Dictionary <string, string>(); } application.Title = applicationMetadataFromRepository.Title; application.VersionId = versionId; if (application.Forms == null) { application.Forms = new List <ApplicationForm>(); } application.Forms = applicationMetadataFromRepository.Forms; HttpResponseMessage response = client.PutAsync(getApplicationMetadataUrl, application.AsJson()).Result; if (response.IsSuccessStatusCode) { _logger.LogInformation($"Application Metadata for {applicationId} is created. New versionId is {versionId}."); } else { _logger.LogInformation($"An error occured while trying to update application Metadata for {applicationId}. VersionId is {versionId}."); } } else if (getApplicationMetadataResponse.StatusCode == System.Net.HttpStatusCode.NotFound) { ApplicationMetadata appMetadata = GetApplicationMetadata(applicationId, versionId); appMetadata.ApplicationOwnerId = applicationMetadataFromRepository.ApplicationOwnerId; appMetadata.CreatedBy = applicationMetadataFromRepository.CreatedBy; appMetadata.CreatedDateTime = applicationMetadataFromRepository.CreatedDateTime; appMetadata.Forms = new List <ApplicationForm>(); appMetadata.Forms = applicationMetadataFromRepository.Forms; appMetadata.Title = applicationMetadataFromRepository.Title; string createApplicationMetadataUrl = $"{storageEndpoint}applications?applicationId={applicationId}"; HttpResponseMessage createApplicationMetadataResponse = await client.PostAsync(createApplicationMetadataUrl, appMetadata.AsJson()); if (createApplicationMetadataResponse.IsSuccessStatusCode) { applicationInStorage = true; } else { applicationInStorage = false; _logger.LogError("Something went wrong when trying to create metadata, response code is: ", createApplicationMetadataResponse.StatusCode); } } else { applicationInStorage = false; _logger.LogError("Something went wrong when trying to get metadata, response code is: ", getApplicationMetadataResponse.StatusCode); } return(applicationInStorage); } }