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)));
            }
        }
        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);
        }
Пример #5
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)));
            }
        }
Пример #6
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);
        }
Пример #7
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);
        }
Пример #8
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)));
            }
        }