public async Task ProducesProperZipFileForCollection()
        {
            ExcludeFakeFor <IFileManager>();

            var file1 = Path.GetTempFileName();
            var file2 = Path.GetTempFileName();

            File.WriteAllText(file1, "file1");
            File.WriteAllText(file2, "file2");

            var fileCollectionData = new ClipboardFileCollectionData()
            {
                Files = new[]
                {
                    new ClipboardFileData()
                    {
                        FullPath = file1,
                        FileName = Path.GetFileName(file1)
                    },
                    new ClipboardFileData()
                    {
                        FullPath = file2,
                        FileName = Path.GetFileName(file2)
                    }
                }
            };

            var package = new ClipboardDataPackage();

            package.AddData(fileCollectionData);

            string zipPath = null;

            Container.Resolve <IClipboardInjectionService>()
            .When(x => x.InjectFilesAsync(Arg.Any <string[]>()))
            .Do(
                parameters => {
                var files = (string[])parameters[0];
                zipPath   = files[0];
            });

            await SystemUnderTest.PerformAsync(package);

            Assert.IsNotNull(zipPath);

            using (var archive = ZipFile.Open(zipPath, ZipArchiveMode.Read))
            {
                var entries = archive.Entries;

                Assert.AreEqual(2, entries.Count);
                Assert.AreEqual(
                    1,
                    entries
                    .Count(x => x.FullName == Path.GetFileName(file1)));
                Assert.AreEqual(
                    1,
                    entries
                    .Count(x => x.FullName == Path.GetFileName(file2)));
            }
        }
        IClipboardDataPackage ConstructPackageFromFormats(
            IEnumerable<uint> formats)
        {
            var package = new ClipboardDataPackage();
            DecoratePackageWithClipboardData(formats, package);

            return package;
        }
        IClipboardDataPackage ConstructPackageFromFormats(
            IEnumerable <uint> formats)
        {
            var package = new ClipboardDataPackage();

            DecoratePackageWithClipboardData(formats, package);

            return(package);
        }
        public async Task ThrowsExceptionForInvalidData()
        {
            var fakeData = Substitute.For <IClipboardData>();

            var package = new ClipboardDataPackage();

            package.AddData(fakeData);

            await SystemUnderTest.PerformAsync(package);
        }
        public async Task NoFilesAddedThrowsException()
        {
            var fileCollectionData = new ClipboardFileCollectionData()
            {
                Files = new Collection <IClipboardFileData>()
            };

            var package = new ClipboardDataPackage();

            package.AddData(fileCollectionData);

            await SystemUnderTest.PerformAsync(package);
        }
        public async Task ThrowsExceptionForInvalidData()
        {
            var container = CreateContainer();

            var action = container.Resolve<IZipFilesAction>();

            var fakeData = Substitute.For<IClipboardData>();

            var package = new ClipboardDataPackage();
            package.AddData(fakeData);

            await action.PerformAsync(package);
        }
Exemplo n.º 7
0
        public async Task ProducesProperZipFileForSingleFile()
        {
            var container = CreateContainer(
                c => {
                c.RegisterFake <IClipboardInjectionService>();
            });

            var fakeClipboardInjectionService = container.Resolve <IClipboardInjectionService>();
            var action = container.Resolve <IZipFilesAction>();

            var file = Path.GetTempFileName();

            File.WriteAllText(file, "file");

            var fakeDataSourceService = Substitute.For <IDataSourceService>();

            var fileData = new ClipboardFileData(fakeDataSourceService)
            {
                FullPath = file,
                FileName = Path.GetFileName(file)
            };

            var package = new ClipboardDataPackage();

            package.AddData(fileData);

            string zipPath = null;

            fakeClipboardInjectionService
            .When(x => x.InjectFiles(Arg.Any <string[]>()))
            .Do(
                parameters => {
                var files = (string[])parameters[0];
                zipPath   = files[0];
            });

            await action.PerformAsync(package);

            Assert.IsNotNull(zipPath);

            using (var archive = ZipFile.Open(zipPath, ZipArchiveMode.Read))
            {
                var entries = archive.Entries;

                Assert.AreEqual(1, entries.Count);
                Assert.AreEqual(
                    1,
                    entries
                    .Count(x => x.FullName == Path.GetFileName(file)));
            }
        }
Exemplo n.º 8
0
        public async Task ThrowsExceptionForInvalidData()
        {
            var container = CreateContainer();

            var action = container.Resolve <IZipFilesAction>();

            var fakeData = Substitute.For <IClipboardData>();

            var package = new ClipboardDataPackage();

            package.AddData(fakeData);

            await action.PerformAsync(package);
        }
Exemplo n.º 9
0
        public async Task NoFilesAddedThrowsException()
        {
            var fakeDataSourceService = Substitute.For <IDataSourceService>();

            var fileCollectionData = new ClipboardFileCollectionData(fakeDataSourceService)
            {
                Files = new Collection <IClipboardFileData>()
            };

            var package = new ClipboardDataPackage();

            package.AddData(fileCollectionData);

            await SystemUnderTest.PerformAsync(package);
        }
Exemplo n.º 10
0
        public IClipboardDataPackage CreateFromFormatsAndData(params FormatDataPair[] formatsAndData)
        {
            if (!IsAnyFormatSupported(formatsAndData.Select(x => x.Format)))
            {
                return(null);
            }

            var package = new ClipboardDataPackage();

            foreach (var pair in formatsAndData)
            {
                DecoratePackageWithClipboardDataFromRawDataAndFormat(package, pair.Format, pair.Data);
            }

            return(package);
        }
        public IClipboardDataPackage CreateFromFormatsAndData(params FormatDataPair[] formatsAndData)
        {
            if (!IsAnyFormatSupported(
                formatsAndData.Select(x => x.Format)))
            {
                return null;
            }

            var package = new ClipboardDataPackage();
            foreach (var pair in formatsAndData)
            {
                DecoratePackageWithClipboardDataFromRawDataAndFormat(package, pair.Format, pair.Data);
            }

            return package;
        }
Exemplo n.º 12
0
        public async Task NoFilesAddedThrowsException()
        {
            var container = CreateContainer();

            var action = container.Resolve <IZipFilesAction>();

            var fakeDataSourceService = Substitute.For <IDataSourceService>();

            var fileCollectionData = new ClipboardFileCollectionData(fakeDataSourceService)
            {
                Files = new Collection <IClipboardFileData>()
            };

            var package = new ClipboardDataPackage();

            package.AddData(fileCollectionData);

            await action.PerformAsync(package);
        }
        public async Task NoFilesAddedThrowsException()
        {
            var container = CreateContainer();

            var action = container.Resolve<IZipFilesAction>();

            var fakeDataSourceService = Substitute.For<IDataSourceService>();

            var fileCollectionData = new ClipboardFileCollectionData(fakeDataSourceService)
            {
                Files = new Collection<IClipboardFileData>()
            };

            var package = new ClipboardDataPackage();
            package.AddData(fileCollectionData);

            await action.PerformAsync(package);
        }
        public async Task ProducesProperZipFileForSingleFile()
        {
            var container = CreateContainer(
                c => {
                    c.RegisterFake<IClipboardInjectionService>();
                });

            var fakeClipboardInjectionService = container.Resolve<IClipboardInjectionService>();
            var action = container.Resolve<IZipFilesAction>();

            var file = Path.GetTempFileName();

            File.WriteAllText(file, "file");

            var fakeDataSourceService = Substitute.For<IDataSourceService>();

            var fileData = new ClipboardFileData(fakeDataSourceService)
            {
                FullPath = file,
                FileName = Path.GetFileName(file)
            };

            var package = new ClipboardDataPackage();
            package.AddData(fileData);

            string zipPath = null;
            fakeClipboardInjectionService
                .When(x => x.InjectFiles(Arg.Any<string[]>()))
                .Do(
                    parameters => {
                        var files = (string[]) parameters[0];
                        zipPath = files[0];
                    });

            await action.PerformAsync(package);

            Assert.IsNotNull(zipPath);

            using (var archive = ZipFile.Open(zipPath, ZipArchiveMode.Read))
            {
                var entries = archive.Entries;

                Assert.AreEqual(1, entries.Count);
                Assert.AreEqual(
                    1,
                    entries
                        .Count(x => x.FullName == Path.GetFileName(file)));
            }
        }