Exemplo n.º 1
0
        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());
        }
Exemplo n.º 2
0
        public void ReadRecordForDeletedResourceTest()
        {
            PrivateApiResponse <RecordsHandlingComponent.DataContract.RecordsCreateOrDeleteResponseItem> recordResponse = null;
            var recordHandler = new RecordManager();

            var fieldHandler = new FieldManager();
            var fields       = fieldHandler.GetFieldGuid(new[] { "P_Name", "P_Owner" }, new[] { Porters.TestCoreFramework.Enums.ResourceType.Client })
                               .Result.Result.ToDictionary(x => $"{char.ToUpper(x.Resource[0]) + x.Resource.Substring(1)}.{x.Alias}", x => (int)UuidUtil.GetId(x.Id));

            var request = RecordRequestComposer.ComposeCreateRequest()
                          .Append(item =>
                                  item.ForResource(Porters.TestCoreFramework.Enums.ResourceType.Client)
                                  .WithField(fields["Client.P_Name"], "TestName")
                                  .WithField(fields["Client.P_Owner"], 1));

            recordResponse = recordHandler.WriteRecords(request.Result);
            PrAssume.That(recordResponse, PrIs.SuccessfulResponse());


            var fileHandler = new FileStorageManager();

            var fileRecordUploadResponse = fileHandler.Upload(GenerateUploadFileRequest(recordId: recordResponse.Result.Ids[0][0].ToString()));

            PrAssume.That(fileRecordUploadResponse, PrIs.SuccessfulResponse());

            var recordDeleteResponse = recordHandler.DeleteRecords(RecordRequestComposer.ComposeDeleteRequest(Porters.TestCoreFramework.Enums.ResourceType.Client, recordResponse.Result.Ids.SelectMany(x => x)));

            PrAssume.That(recordDeleteResponse, PrIs.SuccessfulResponse());

            var fileRecordReadResponse = fileHandler.Read(fileRecordUploadResponse.Result.Id);

            PrAssert.That(fileRecordReadResponse, PrIs.ErrorResponse());
        }
Exemplo n.º 3
0
        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());
                }
            }
        }
Exemplo n.º 4
0
        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);
            }
        }
Exemplo n.º 5
0
        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);
            }
        }
Exemplo n.º 6
0
        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);
            }
        }
Exemplo n.º 7
0
        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));
        }
Exemplo n.º 8
0
        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);
            }
        }