コード例 #1
0
ファイル: Program.cs プロジェクト: rambotech/BOG.DropZone
        static async Task UnitTestAsync()
        {
            Console.WriteLine("Setup()...");
            const string Access = "YourAccessTokenValueHere";
            const string Admin  = "YourAdminTokenValueHere";

            var zone = new DropZoneConfig
            {
                BaseUrl        = "http://*****:*****@"C:\Users\johnm\research\RR-Dynamic-20201216-C.result.json";
                string bigFishContent = null;
                using (var t = new StreamReader(bigFish))
                {
                    bigFishContent = t.ReadToEnd();
                    result         = await restApiUpdateMaster.SetBlob("TestItem02", bigFishContent);
                }
                testPassed = result.HandleAs == Result.State.OK;
                Console.WriteLine(testPassed ? "pass" : $"FAIL, expected: OK, got: {result.HandleAs}");
                if (!testPassed)
                {
                    UnexpectedResult();
                }
                testPassed = true;

                Console.Write("Clear DropZone ...: ");
                result = await restApiUpdateMaster.Clear();

                testPassed = result.HandleAs == Result.State.OK;
                Console.WriteLine(testPassed ? "pass" : $"FAIL, expected: OK, got: {result.HandleAs}");
                if (!testPassed)
                {
                    UnexpectedResult();
                }
                testPassed = true;

                Console.WriteLine("Read blob list ...: ");
                result = await restApiUpdateMaster.ListBlobs();

                testPassed = result.HandleAs == Result.State.OK;
                Console.WriteLine(testPassed ? "pass" : $"FAIL, expected: OK, got: {result.HandleAs}");
                if (testPassed)
                {
                    Console.Write($"  Blob list has previous items ...: ");
                    var blobCount = Serializer <System.Collections.Generic.List <System.String> > .FromJson(result.Content).Count;

                    testPassed = (blobCount == 2);
                    Console.WriteLine(testPassed ? "pass" : $"FAIL, expected: 2, got: {blobCount}");
                }
                if (!testPassed)
                {
                    UnexpectedResult();
                }
                testPassed = true;

                // Read the blob item TestItem01: test for proper content.
                Console.Write("Read Blob TestItem01 ...: ");
                result = await restApiUpdateMaster.GetBlob("TestItem01");

                testPassed = result.HandleAs == Result.State.OK;
                Console.WriteLine(testPassed ? "pass" : $"FAIL, expected: OK, got: {result.HandleAs}");
                if (testPassed)
                {
                    Console.Write("  Valid Blob Content TestItem01 ...: ");
                    testPassed |= string.Compare(result.Content, TestItem01Value, false) == 0;
                    Console.WriteLine(testPassed ? "pass" : $"FAIL, expected: (empty string), got: {result.Content}");
                }
                if (!testPassed)
                {
                    UnexpectedResult();
                }
                testPassed = true;

                // Read the blob item TestItem01: test for proper content.
                Console.Write("Read Blob TestItem02 ...: ");
                result = await restApiUpdateMaster.GetBlob("TestItem02");

                testPassed = result.HandleAs == Result.State.OK;
                Console.WriteLine(testPassed ? "pass" : $"FAIL, expected: OK, got: {result.HandleAs}");
                if (testPassed)
                {
                    Console.Write("  Valid Blob Content TestItem02 ...: ");
                    testPassed |= string.Compare(result.Content, bigFishContent, false) == 0;
                    Console.WriteLine(testPassed ? "pass" : $"FAIL, expected: (empty string), got: {result.Content}");
                }
                if (!testPassed)
                {
                    UnexpectedResult();
                }
                testPassed = true;
            }
            catch (Exception err)
            {
                Console.WriteLine($"Untrapped: {err.Message}");
            }

            Console.WriteLine("---------------------------");
            Console.WriteLine("### TESTING ENDS ###");
            Console.WriteLine("---------------------------");
#if DEBUG
            Console.WriteLine();
            Console.WriteLine("Press ENTER to finish");
            Console.ReadLine();
#endif
        }