Пример #1
0
        public async Task HavingMacrosWillReadThemIn()
        {
            var    writer   = new MockTextWriter();
            var    settings = Substitute.For <IChauffeurSettings>();
            string dir;

            settings.TryGetChauffeurDirectory(out dir).Returns(x =>
            {
                x[0] = "";
                return(true);
            });
            var fs = new MockFileSystem(new Dictionary <string, MockFileData>
            {
                { "Text.xml", new MockFileData(macrosXml) }
            });
            var packagingService = Substitute.For <IPackagingService>();

            packagingService.ImportMacros(Arg.Any <XElement>()).Returns(Enumerable.Empty <IMacro>());

            var package = new PackageDeliverable(null, writer, fs, settings, packagingService);

            await package.Run(null, new[] { "Text" });

            packagingService.Received(1).ImportMacros(Arg.Any <XElement>());
        }
        public async Task CanImportPackageWithFiles()
        {
            var          writer       = new MockTextWriter();
            var          settings     = Substitute.For <IChauffeurSettings>();
            const string siteRootPath = "C:\\SiteRoot";

            settings.TryGetSiteRootDirectory(out string dir).Returns(x =>
            {
                x[0] = siteRootPath;
                return(true);
            });
            var fs = new MockFileSystem(new Dictionary <string, MockFileData>
            {
                { "C:\\Path\\Text.xml", new MockFileData(filesXml) },
                { "C:\\Path\\foo.txt", new MockFileData("something") }
            });

            fs.AddDirectory(siteRootPath);

            var package = new PackageDeliverable(null, writer, fs, settings, null, null, null);

            await package.Run(null, new[] { "Text", "-f:C:\\Path" });

            Assert.Collection(
                fs.Directory.GetFiles(siteRootPath),
                item => Assert.Equal("foo.txt", fs.Path.GetFileName(item))
                );
        }
        public async Task CanOverrideTheDefaultLookupDirectory()
        {
            var writer   = new MockTextWriter();
            var settings = Substitute.For <IChauffeurSettings>();

            settings.TryGetChauffeurDirectory(out string dir).Returns(x =>
            {
                x[0] = "";
                return(false);
            });
            var fs = new MockFileSystem(new Dictionary <string, MockFileData>
            {
                { "C:\\Path\\Text.xml", new MockFileData(multipleDocumentTypesXml) }
            });

            var packagingService = Substitute.For <IPackagingService>();

            packagingService.ImportContentTypes(Arg.Any <XElement>()).Returns(Enumerable.Empty <IContentType>());

            var package = new PackageDeliverable(null, writer, fs, settings, packagingService, Substitute.For <IContentTypeService>(), null);

            await package.Run(null, new[] { "Text", "-f:C:\\Path" });

            packagingService.Received(1).ImportContentTypes(Arg.Any <XElement>());
        }
Пример #4
0
        public async Task NoPackagesAbortsEarly()
        {
            var writer  = Substitute.ForPartsOf <TextWriter>();
            var package = new PackageDeliverable(null, writer, null, null, null);

            await package.Run(null, new string[0]);

            writer.Received(1).WriteLineAsync(Arg.Any <string>()).IgnoreAwaitForNSubstituteAssertion();
        }
Пример #5
0
        public async Task NotFoundPackageAbortsEarly()
        {
            var    writer   = new MockTextWriter();
            var    settings = Substitute.For <IChauffeurSettings>();
            string dir;

            settings.TryGetChauffeurDirectory(out dir).Returns(x =>
            {
                x[0] = "";
                return(true);
            });
            var package = new PackageDeliverable(null, writer, new MockFileSystem(), settings, null);

            await package.Run(null, new[] { "Test" });

            Assert.That(writer.Messages.Count(), Is.EqualTo(1));
        }