Пример #1
0
        public void SingleSegmentUploader_UploadFileRange()
        {
            int length = _smallFileContents.Length / 3;

            var fe = new InMemoryFrontEnd();

            var metadata        = CreateMetadata(_smallFilePath, length);
            var progressTracker = new TestProgressTracker();
            var ssu             = new SingleSegmentUploader(0, metadata, fe, progressTracker);

            ssu.UseBackOffRetryStrategy = false;
            ssu.Upload();

            var actualContents   = fe.GetStreamContents(StreamPath);
            var expectedContents = new byte[length];

            Array.Copy(_smallFileContents, 0, expectedContents, 0, length);
            AssertExtensions.AreEqual(expectedContents, actualContents, "Unexpected uploaded stream contents.");
            VerifyTracker(progressTracker, true);
        }
Пример #2
0
        public void SingleSegmentUploader_VerifyUploadStreamFails()
        {
            //create a mock front end which doesn't do anything
            var fe = new MockableFrontEnd();

            fe.CreateStreamImplementation    = (streamPath, overwrite, data, byteCount) => { };
            fe.DeleteStreamImplementation    = (streamPath, recurse) => { };
            fe.StreamExistsImplementation    = (streamPath) => { return(true); };
            fe.AppendToStreamImplementation  = (streamPath, data, offset, byteCount) => { };
            fe.GetStreamLengthImplementation = (streamPath) => { return(0); };

            //upload some data
            var metadata = CreateMetadata(_smallFilePath, _smallFileContents.Length);
            var ssu      = new SingleSegmentUploader(0, metadata, fe);

            ssu.UseBackOffRetryStrategy = false;

            //the Upload method should fail if it cannot verify that the stream was uploaded after the upload (i.e., it will get a length of 0 at the end)
            Assert.Throws <UploadFailedException>(() => { ssu.Upload(); });
        }