Пример #1
0
        public void Inner_Stream_Calls_CanSeek(bool canSeek) {
            string key = "test";
            var mockStream = new Mock<Stream>();
            var progressStream = new ProgressStream(key, mockStream.Object, null, null);

            mockStream.SetupGet(s => s.CanWrite).Returns(canSeek);

            bool actualCanSeek = progressStream.CanWrite;

            mockStream.Verify(s => s.CanWrite, Times.Once);

            Assert.Equal(canSeek, actualCanSeek);
        }
Пример #2
0
        public void Inner_Stream_Calls_Length(long length) {
            string key = "test";
            var mockStream = new Mock<Stream>();
            var progressStream = new ProgressStream(key, mockStream.Object, null, null);

            mockStream.SetupGet(s => s.Length).Returns(length);

            long actualLength = progressStream.Length;

            mockStream.Verify(s => s.Length, Times.Once);

            Assert.Equal(length, actualLength);
        }
Пример #3
0
        public override int Run(string[] remainingArguments) {
            var config = Program.CabinetConfigStore.GetConfig(configName);
            var cabinet = Program.CabinetFactory.GetCabinet(config);

            Console.WriteLine($"Starting download {key}...");

            Nito.AsyncEx.AsyncContext.Run(async () => {
                using(var writeStream = File.OpenWrite(filePath)) {
                    using(var readStream = await cabinet.OpenReadStreamAsync(key)) {
                        long? length = readStream.TryGetStreamLength();
                        var progressStream = new ProgressStream(key, writeStream, length, new ConsoleProgress());
                        await readStream.CopyToAsync(progressStream);
                    }
                }
            });

            Console.WriteLine();
            Console.WriteLine($"Completed downloading {key} to {filePath}");

            return 0;
        }
Пример #4
0
        public void Inner_Stream_Calls_Position(long position) {
            string key = "test";
            var mockStream = new Mock<Stream>();
            var progressStream = new ProgressStream(key, mockStream.Object, null, null);

            mockStream.SetupGet(s => s.Position).Returns(position);

            long actualPosition = progressStream.Position;

            mockStream.Verify(s => s.Position, Times.Once);

            Assert.Equal(position, actualPosition);
        }
Пример #5
0
        public void Inner_Stream_Calls_Dispose(bool disposeStream) {
            string key = "test";
            var mockStream = new Mock<Stream>();
            var mockProgress = new Mock<IProgress<IWriteProgress>>();
            var progressStream = new ProgressStream(key, mockStream.Object, null, mockProgress.Object, disposeStream);

            progressStream.Dispose();
        }
Пример #6
0
        public void Inner_Stream_Calls_Write() {
            string key = "test";
            var mockStream = new Mock<Stream>();
            var mockProgress = new Mock<IProgress<IWriteProgress>>();
            var progressStream = new ProgressStream(key, mockStream.Object, null, mockProgress.Object);

            byte[] buffer = new byte[0];
            int offset = 0;
            int count = 0;

            mockProgress.Setup(p => p.Report(It.IsAny<IWriteProgress>()));

            progressStream.Write(buffer, offset, count);

            mockProgress.Verify(p => p.Report(It.IsAny<IWriteProgress>()), Times.Once);
            mockStream.Verify(s => s.Write(buffer, offset, count), Times.Once);
        }
Пример #7
0
        public void Inner_Stream_Calls_SetLength() {
            string key = "test";
            var mockStream = new Mock<Stream>();
            var progressStream = new ProgressStream(key, mockStream.Object, null, null);

            long length = 0;

            progressStream.SetLength(length);

            mockStream.Verify(s => s.SetLength(length), Times.Once);
        }
Пример #8
0
        public void Inner_Stream_Calls_Seek() {
            string key = "test";
            var mockStream = new Mock<Stream>();
            var progressStream = new ProgressStream(key, mockStream.Object, null, null);

            long offset = 0;
            SeekOrigin origin = SeekOrigin.Begin;

            progressStream.Seek(offset, origin);

            mockStream.Verify(s => s.Seek(offset, origin), Times.Once);
        }
Пример #9
0
        public void Inner_Stream_Calls_Read() {
            string key = "test";
            var mockStream = new Mock<Stream>();
            var progressStream = new ProgressStream(key, mockStream.Object, null, null);

            byte[] buffer = new byte[0];
            int offset = 0;
            int count = 0;

            progressStream.Read(buffer, offset, count);

            mockStream.Verify(s => s.Read(buffer, offset, count), Times.Once);
        }
Пример #10
0
        public void Inner_Stream_Calls_Flush() {
            string key = "test";
            var mockStream = new Mock<Stream>();
            var progressStream = new ProgressStream(key, mockStream.Object, null, null);

            progressStream.Flush();

            mockStream.Verify(s => s.Flush(), Times.Once);
        }