Пример #1
0
        public void RunCopyFileCompletesSuccessfullyTest(string baseName)
        {
            // Setup
            string sourceFolderName = $"{baseName} Folder";
            string sourceFileName   = $"{baseName} audio.mp3";
            string collectionName   = $"{baseName} Collection";
            string bookTitle        = $"{baseName} Book";

            (string sourceFilePath, string destDirPath) = SetupCopyFileTests(sourceFolderName, sourceFileName, collectionName, bookTitle);
            string encodedSourceFilePath = EncodeFilenameForHttpRequest(sourceFilePath);

            string destFilePath        = Path.Combine(destDirPath, "fa22704c-6f27-4c1f-9f1b-7eb62baf2fde.mp3");
            string encodedDestFilePath = EncodeFilenameForHttpRequest(destFilePath);

            string jsonData = $"{{ \"from\": \"{encodedSourceFilePath}\", \"to\": \"{encodedDestFilePath}\" }}";

            // System Under Test //

            // Debugging tip: If debugging with breakpoints, set the timeout to some high value
            int?timeoutInMilliseconds = null;
            var result = ApiTest.PostString(_server, "fileIO/copyFile", jsonData, ApiTest.ContentType.JSON, timeoutInMilliseconds: timeoutInMilliseconds);

            // Verification
            Assert.That(result, Is.EqualTo("OK"), "Request should reply \"OK\" if successful");
            Assert.That(File.ReadAllText(destFilePath), Is.EqualTo("fakeSourceFileContents"), "Contents of copied file were not as expected.");
        }
        public void Post_JSON_JSONReceived()
        {
            var result = ApiTest.PostString(_server, endPoint: "test", data: "{\"color\": \"blue\"}", returnType: ApiTest.ContentType.JSON,
                                            handler: request =>
            {
                var requiredPostJson = request.RequiredPostJson();
                request.ReplyWithText(DynamicJson.Parse(requiredPostJson).color);
            });

            Assert.That(result, Is.EqualTo("blue"));
        }