public void HappyPathTest(ResourceId resource, FileType fileType) { var fileInfo = CommonConstants.Files[fileType]; var path = Path.Combine(Util.GetTestDirectory(), fileInfo.Location); var base64string = Util.ReadFileAsBase64String(path); var recordInfo = RecordsCreator.Data[resource]; var handler = new FileStorageManager(); var request = GenerateUploadFileRequest(fileName: fileInfo.Location.Split('/').Last(), recordId: recordInfo.Id.ToString(), resourceId: ((int)resource).ToString(), sublist: "1", contentType: fileInfo.MimeType); request.Content = base64string; var uploadResponse = handler.Upload(request); PrAssert.That(uploadResponse, PrIs.SuccessfulResponse()); //send request as string, not as object, to make sure we receive string as is, without json.NET formatting. using (LogHelper.LoggerForCurrentTest.EnterReproStep("Sending request to read file content.")) using (var readResponse = PrivateApiConnection.GetConnectionForCurrentTest().SendAsync(FileStorageManager.EndPoint, new Dictionary <string, string> { ["id"] = uploadResponse.Result.Id }, System.Net.Http.HttpMethod.Get).Result) { var receivedContent = readResponse.Content.ReadAsByteArrayAsync().Result; PrAssert.That((int)readResponse.StatusCode, PrIs.LessThan(300)); PrAssert.That(receivedContent, PrIs.EqualTo(File.ReadAllBytes(path))); } var deleteResponse = handler.Delete(uploadResponse.Result.Id); PrAssert.That(deleteResponse, PrIs.SuccessfulResponse()); }
public void UploadSeveralFilesToSameRecordTest() { const int filesNumber = 50; var fileIdsList = new List <string>(); var handler = new FileStorageManager(); using (LogHelper.LoggerForCurrentTest.EnterReproStep($"Uploading {filesNumber} files")) { for (var i = 0; i < filesNumber; i++) { //upload a file of 1MB size var response = handler.Upload(GenerateUploadFileRequest(content: TestContext.CurrentContext.Random.GetString(1 << 20))); PrAssume.That(response, PrIs.SuccessfulResponse(), $"File #{i} was not uploaded successfully"); fileIdsList.Add(response.Result.Id); } } using (LogHelper.LoggerForCurrentTest.EnterReproStep($"Reading {filesNumber} files")) { foreach (var id in fileIdsList) { var response = handler.Read(id); PrAssert.That(response, PrIs.SuccessfulResponse()); } } using (LogHelper.LoggerForCurrentTest.EnterReproStep($"Deleting {filesNumber} files")) { foreach (var id in fileIdsList) { var response = handler.Delete(id); PrAssert.That(response, PrIs.SuccessfulResponse()); } } }
public void UploadFileWihtoutParameterInMetadataTest(string parameterName, bool isRequiredParameter) { var handler = new FileStorageManager(); var response = handler.Upload(GenerateUploadFileRequest(fileSize: defaultContent.Length.ToString()), (o) => { (o["metadata"] as JObject).Property(parameterName).Remove(); return(o); }); try { if (isRequiredParameter) { PrAssert.That(response, PrIs.ErrorResponse().And.ErrorCode(116)); } else { PrAssert.That(response, PrIs.SuccessfulResponse()); } } finally { handler.Delete(response?.Result?.Id); } }
public void DeleteFileContentForIdTest(string id, int errorCode) { var handler = new FileStorageManager(); using (LogHelper.LoggerForCurrentTest.EnterReproStep("Running the test -- sending a read request with the specified id")) { var readResponse = handler.Delete(id); PrAssert.That(readResponse, PrIs.ErrorResponse().And.ErrorCode(errorCode)); } }
private void PerformTestWithPreparedData(Action <string> testAction) { var manager = new FileStorageManager(); var result = manager.Upload(GenerateUploadFileRequest()); PrAssume.That(result, PrIs.SuccessfulResponse()); try { testAction(result.Result.Id); } finally { manager.Delete(result.Result.Id); } }
private void PerformTestWithoutAuthorisationWithDataPreparation(bool doDeauth, Func <PrivateApiConnection, string, object> responseProvider) { var manager = new FileStorageManager(); var result = manager.Upload(GenerateUploadFileRequest()); PrAssume.That(result, PrIs.SuccessfulResponse()); PrivateApiConnection.GetConnectionForCurrentTest().DeAuthenticate(); try { PerformTestWithoutAuthorisation(doDeauth, responseProvider, result.Result.Id); } finally { PrivateApiConnection.GetConnectionForCurrentTest().Authenticate(); manager.Delete(result.Result.Id); } }
private void PerformTestForFileStatus(bool isDeleted, Func <string, FileStorageManager, PrivateApiResponse <object> > testFunc) { var manager = new FileStorageManager(); var id = nonExistingRecordId; if (isDeleted) { var result = manager.Upload(GenerateUploadFileRequest()); PrAssume.That(result, PrIs.SuccessfulResponse()); manager.Delete(result.Result.Id); id = result.Result.Id; } var response = testFunc(id, manager); PrAssert.That(response, PrIs.WithErrorCode(100).And.HttpCode(400)); }
public void UploadFileWihtoutContentParameterTest() { var handler = new FileStorageManager(); var response = handler.Upload(GenerateUploadFileRequest(fileSize: defaultContent.Length.ToString()), (o) => { (o as JObject).Property("content").Remove(); return(o); }); try { PrAssert.That(response, PrIs.ErrorResponse().And.ErrorCode(116)); } finally { handler.Delete(response?.Result?.Id); } }