public void SetUp()
        {
            this.fileSystem = new TestIFileSystemService();

            this.platform = new TestIPlatformService {
                ReadFileFunc  = x => new MemoryStream(),
                WriteFileFunc = x => new MemoryStream()
            };
            this.streamBuilder = new TestIStreamBuilder();
            this.service       = new DefaultHuffmanEncodingService(fileSystem, platform, streamBuilder);
        }
        public async Task EncodingStatisticsTest()
        {
            TestIFileSelectorService fileSelector = new TestIFileSelectorService();

            fileSelector.FilePath         = @"path";
            viewModel.FileSelectorService = fileSelector;
            viewModel.Path = @"C:\dir\";

            TestIInputDataService inputDataService = new TestIInputDataService();

            inputDataService.InputCommand = InputCommand.Encode;
            viewModel.InputDataService    = inputDataService;

            TestIFileSystemService fileSystem = new TestIFileSystemService();

            fileSystem.EnumFileSystemEntriesFunc = _ => {
                return(new[] {
                    new FileSystemEntry(FileSystemEntryType.Directory, "dir", @"C:\dir\"),
                    new FileSystemEntry(FileSystemEntryType.File, "f1.dat", @"C:\dir\f1.dat"),
                    new FileSystemEntry(FileSystemEntryType.File, "f2.dat", @"C:\dir\f2.dat"),
                });
            };

            WritableMemoryStream outputStream = new WritableMemoryStream();
            TestIPlatformService platform     = new TestIPlatformService();

            platform.WriteFileFunc = _ => outputStream;

            platform.ReadFileFunc = x => {
                switch (x)
                {
                case @"C:\dir\f1.dat": return(new MemoryStream(new byte[200 * 1024]));

                case @"C:\dir\f2.dat": return(new MemoryStream(new byte[300 * 1024]));

                default: throw new NotImplementedException();
                }
            };
            viewModel.EncodingService = new DefaultHuffmanEncodingService(fileSystem, platform, new DefaultStreamBuilder());

            await viewModel.Run();

            window.UpdateLayout();

            TextBlock inputSizeTextBlock  = window.EncodingResultControl.GetContentTemplateControl <TextBlock>("InputSizeTextBlock");
            TextBlock outputSizeTextBlock = window.EncodingResultControl.GetContentTemplateControl <TextBlock>("OutputSizeTextBlock");
            TextBlock saveFactorTextBlock = window.EncodingResultControl.GetContentTemplateControl <TextBlock>("SaveFactorTextBlock");

            Assert.AreEqual("Input Size: 512 Kb", inputSizeTextBlock.Text);
            Assert.AreEqual("Output Size: 64.1 Kb", outputSizeTextBlock.Text);
            Assert.AreEqual("Save Factor: 87.48%", saveFactorTextBlock.Text);
        }
        public async Task EncodingCancellationTest1()
        {
            TestIFileSelectorService fileSelector = new TestIFileSelectorService();

            fileSelector.FilePath         = @"path";
            viewModel.FileSelectorService = fileSelector;
            viewModel.Path = @"C:\dir\";

            TestIInputDataService inputDataService = new TestIInputDataService();

            inputDataService.InputCommand = InputCommand.Encode;
            viewModel.InputDataService    = inputDataService;

            TestIFileSystemService fileSystem = new TestIFileSystemService();

            fileSystem.EnumFileSystemEntriesFunc = _ => {
                return(new[] {
                    new FileSystemEntry(FileSystemEntryType.Directory, "dir", @"C:\dir\"),
                    new FileSystemEntry(FileSystemEntryType.File, "f1.dat", @"C:\dir\f1.dat"),
                    new FileSystemEntry(FileSystemEntryType.File, "f2.dat", @"C:\dir\f2.dat"),
                });
            };

            WritableMemoryStream outputStream = new WritableMemoryStream();
            TestIPlatformService platform     = new TestIPlatformService();

            platform.WriteFileFunc = _ => outputStream;

            int fileRequest = 0;

            platform.ReadFileFunc = x => {
                if (++fileRequest == 4)
                {
                    viewModel.Cancel();
                }
                switch (x)
                {
                case @"C:\dir\f1.dat": return(new MemoryStream(new byte[200 * 1024]));

                case @"C:\dir\f2.dat": return(new MemoryStream(new byte[300 * 1024]));

                default: throw new NotImplementedException();
                }
            };
            viewModel.EncodingService = new DefaultHuffmanEncodingService(fileSystem, platform, new DefaultStreamBuilder());

            await viewModel.Run();

            Assert.AreEqual(32855, outputStream.Length);
        }
 public void SetUp()
 {
     this.fileSystem = new TestIFileSystemService();
     this.platform   = new TestIPlatformService();
     this.service    = new DefaultHuffmanEncodingService(fileSystem, platform, new DefaultStreamBuilder());
 }
 public void SetUp()
 {
     this.fileSystemService = new TestIFileSystemService();
     this.platform          = new TestIPlatformService();
 }