Пример #1
0
        public void TestBadPut()
        {
            var client = new BunClient(ConnectionInfo.apiKey, ConnectionInfo.badZone);

            var writeResponse = client.PutFile(testContent, testFile).Result;

            Assert.AreEqual(HttpStatusCode.Unauthorized, writeResponse);
        }
Пример #2
0
        public void TestStreamOperations()
        {
            var client = new BunClient(ConnectionInfo.apiKey, ConnectionInfo.zone);

            // Write a file.
            var progress = new NaiveProgress <ICopyProgress>(x =>
            {
                ;
            });

            using (var ms = new MemoryStream())
                using (var writer = new StreamWriter(ms))
                {
                    writer.Write(testContent);
                    writer.Flush();
                    ms.Position = 0;

                    var writeResponse = client.PutFile(ms, testFile, false, progress).Result;

                    ms.Position = 0; // Should be able to do this because stream not closed yet.
                    Assert.AreEqual(HttpStatusCode.Created, writeResponse);
                }

            // Test deleting the file.
            var deleteResult = client.DeleteFile(testFile).Result;

            Assert.AreEqual(HttpStatusCode.OK, deleteResult);

            using (var ms = new MemoryStream())
                using (var writer = new StreamWriter(ms))
                {
                    writer.Write(testContent);
                    writer.Flush();
                    ms.Position = 0;

                    var writeResponse = client.PutFile(ms, testFile, true, progress).Result;

                    Assert.ThrowsException <ObjectDisposedException>(() => { ms.Position = 0; }); // Stream should be disposed.
                    Assert.AreEqual(HttpStatusCode.Created, writeResponse);
                }

            // Test deleting the file.
            deleteResult = client.DeleteFile(testFile).Result;
            Assert.AreEqual(HttpStatusCode.OK, deleteResult);
        }
Пример #3
0
        public void TestFileOperations()
        {
            var client = new BunClient(ConnectionInfo.apiKey, ConnectionInfo.zone);

            // Write a file.
            var progress = new NaiveProgress <ICopyProgress>(x =>
            {
                ;
            });
            var writeResponse = client.PutFile(testContent, testFile, progress).Result;

            Assert.AreEqual(HttpStatusCode.Created, writeResponse);

            // Check for our file in the file listing.
            var listResponse = client.ListFiles().Result;

            Assert.AreEqual(HttpStatusCode.OK, listResponse.StatusCode);
            Assert.IsTrue(listResponse.Files.Where(x => x.ObjectName == testFile).Count() == 1);

            // Read back the file.
            using (var readStream = new MemoryStream())
            {
                var readResponse = client.GetFile(testFile, readStream).Result;
                Assert.AreEqual(HttpStatusCode.OK, readResponse);

                string fileContent = null;
                using (var reader = new StreamReader(readStream))
                {
                    fileContent = reader.ReadToEnd();
                }
                Assert.AreEqual(testContent, fileContent);
            }

            // Test deleting the file.
            var deleteResult = client.DeleteFile(testFile).Result;

            Assert.AreEqual(HttpStatusCode.OK, deleteResult);
        }