Exemple #1
0
            public void EmptyOutputForEmptyContent()
            {
                // Given
                string input = string.Empty;

                TestFileProvider fileProvider = new TestFileProvider();

                fileProvider.AddDirectory("/");
                fileProvider.AddDirectory("/input");
                fileProvider.AddDirectory("/input/assets");
                fileProvider.AddFile("/input/assets/test.scss", input);
                TestFileSystem fileSystem = new TestFileSystem
                {
                    FileProvider = fileProvider
                };
                IExecutionContext context = new TestExecutionContext
                {
                    FileSystem = fileSystem
                };
                IDocument document = new TestDocument(input, new MetadataItems
                {
                    { Keys.RelativeFilePath, new FilePath("assets/test.scss") }
                });

                Sass sass = new Sass();

                // When
                List <IDocument> results = sass.Execute(new[] { document }, context).ToList(); // Make sure to materialize the result list

                // Then
                Assert.That(results.Select(x => x.Content), Is.EqualTo(new[] { string.Empty }));
                Assert.That(results.Select(x => x.FilePath(Keys.RelativeFilePath).FullPath), Is.EqualTo(new[] { "assets/test.css" }));
            }
        protected static TestExecutionContext GetExecutionContext(out TestFileProvider fileProvider)
        {
            fileProvider = new TestFileProvider();

            fileProvider.AddDirectory("/");
            fileProvider.AddDirectory("/TestFiles");
            fileProvider.AddDirectory("/TestFiles/Input");
            fileProvider.AddDirectory("/TestFiles/Input/Subfolder");

            fileProvider.AddFile("/TestFiles/test-above-input.txt", "test");
            fileProvider.AddFile("/TestFiles/Input/test-a.txt", "aaa");
            fileProvider.AddFile("/TestFiles/Input/test-b.txt", "bbb");
            fileProvider.AddFile("/TestFiles/Input/Subfolder/test-c.txt", "ccc");

            TestFileSystem fileSystem = new TestFileSystem
            {
                FileProvider = fileProvider,
                RootPath     = "/"
            };

            fileSystem.InputPaths.Clear();
            fileSystem.InputPaths.Add("/TestFiles/Input");

            return(new TestExecutionContext
            {
                FileSystem = fileSystem
            });
        }
            public async Task IncludesFile()
            {
                // Given
                TestFileProvider fileProvider = new TestFileProvider();

                fileProvider.AddDirectory("/");
                fileProvider.AddDirectory("/A");
                fileProvider.AddDirectory("/A/B");
                fileProvider.AddFile("/A/B/c.txt", "foo");
                TestFileSystem fileSystem = new TestFileSystem
                {
                    FileProvider = fileProvider
                };

                fileSystem.InputPaths.Clear();
                fileSystem.InputPaths.Add("/A");

                TestExecutionContext context = new TestExecutionContext
                {
                    FileSystem = fileSystem
                };
                TestDocument document = new TestDocument();

                KeyValuePair <string, string>[] args = new KeyValuePair <string, string>[]
                {
                    new KeyValuePair <string, string>(null, "B/c.txt")
                };
                IncludeShortcode shortcode = new IncludeShortcode();

                // When
                TestDocument result = (TestDocument)await shortcode.ExecuteAsync(args, string.Empty, document, context);

                // Then
                result.Content.ShouldBe("foo");
            }
        protected static TestExecutionContext GetExecutionContext(IEnumerable <TestDocument> inputs)
        {
            TestFileProvider fileProvider = new TestFileProvider();

            fileProvider.AddDirectory("/");
            fileProvider.AddDirectory("/TestFiles");
            fileProvider.AddDirectory("/TestFiles/Input");
            fileProvider.AddDirectory("/TestFiles/Input/Subfolder");

            fileProvider.AddFile("/TestFiles/test-above-input.txt", "test");
            fileProvider.AddFile("/TestFiles/Input/markdown-x.md", "xxx");
            fileProvider.AddFile("/TestFiles/Input/test-a.txt", "aaa");
            fileProvider.AddFile("/TestFiles/Input/test-b.txt", "bbb");
            fileProvider.AddFile("/TestFiles/Input/Subfolder/markdown-y.md", "yyy");
            fileProvider.AddFile("/TestFiles/Input/Subfolder/test-c.txt", "ccc");

            TestFileSystem fileSystem = new TestFileSystem
            {
                FileProvider = fileProvider,
                RootPath     = "/"
            };

            fileSystem.InputPaths.Clear();
            fileSystem.InputPaths.Add("/TestFiles/Input");

            return(new TestExecutionContext(inputs)
            {
                FileSystem = fileSystem
            });
        }
Exemple #5
0
            public async Task ConvertingBadSassFails()
            {
                // Given
                const string     input        = @"
$font-stack:    Helvetica, sans-serif
$primary-color: #333

body {
  font: 100% $font-stack;
  color: $primary-color;
}";
                TestFileProvider fileProvider = new TestFileProvider();

                fileProvider.AddDirectory("/");
                fileProvider.AddDirectory("/input");
                fileProvider.AddDirectory("/input/assets");
                fileProvider.AddFile("/input/assets/test.scss", input);
                TestFileSystem fileSystem = new TestFileSystem
                {
                    FileProvider = fileProvider
                };
                TestExecutionContext context = new TestExecutionContext
                {
                    FileSystem = fileSystem
                };
                TestDocument document = new TestDocument(
                    new FilePath("/input/assets/test.scss"),
                    new FilePath("assets/test.scss"),
                    input);

                CompileSass sass = new CompileSass();

                // When, Then
                await Should.ThrowAsync <Exception>(async() => await ExecuteAsync(document, context, sass));
            }
Exemple #6
0
            public async Task EmptyOutputForEmptyContent()
            {
                // Given
                string input = string.Empty;

                TestFileProvider fileProvider = new TestFileProvider();

                fileProvider.AddDirectory("/");
                fileProvider.AddDirectory("/input");
                fileProvider.AddDirectory("/input/assets");
                fileProvider.AddFile("/input/assets/test.scss", input);
                TestFileSystem fileSystem = new TestFileSystem
                {
                    FileProvider = fileProvider
                };
                TestExecutionContext context = new TestExecutionContext
                {
                    FileSystem = fileSystem
                };
                TestDocument document = new TestDocument(
                    new FilePath("/input/assets/test.scss"),
                    new FilePath("assets/test.scss"),
                    input);

                CompileSass sass = new CompileSass();

                // When
                TestDocument result = await ExecuteAsync(document, context, sass).SingleAsync();

                // Then
                result.Content.ShouldBeEmpty();
                result.Destination.FullPath.ShouldBe("assets/test.css");
            }
Exemple #7
0
            public void ShouldReturnExistingFiles(string directory, string[] patterns, string[] expected, bool reverseSlashes)
            {
                // TestContext.Out.WriteLine($"Patterns: {string.Join(",", patterns)}");

                // Given
                FileSystem fileSystem = new FileSystem();

                fileSystem.FileProviders.Add(NormalizedPath.DefaultFileProvider.Scheme, GetFileProvider());
                TestFileProvider alternateProvider = new TestFileProvider();

                alternateProvider.AddDirectory("/");
                alternateProvider.AddDirectory("/q");
                alternateProvider.AddFile("/q/werty.txt");
                fileSystem.FileProviders.Add("qwerty", alternateProvider);
                IDirectory dir = fileSystem.GetDirectory(directory);

                // When
                IEnumerable <IFile> results = fileSystem.GetFiles(dir, patterns);

                // Then
                CollectionAssert.AreEquivalent(expected, results.Select(x => x.Path.FullPath));

                if (reverseSlashes)
                {
                    // When
                    results = fileSystem.GetFiles(dir, patterns.Select(x => x.Replace("/", "\\")));

                    // Then
                    CollectionAssert.AreEquivalent(expected, results.Select(x => x.Path.FullPath));
                }
            }
            public async Task ThrowsForBadLess()
            {
                // Given
                const string input = @"
@foo: black

div {
 color: @foo;
}";

                TestFileProvider fileProvider = new TestFileProvider();

                fileProvider.AddDirectory("/");
                fileProvider.AddDirectory("/input");
                fileProvider.AddDirectory("/input/assets");
                fileProvider.AddFile("/input/assets/test.less", input);
                TestFileSystem fileSystem = new TestFileSystem
                {
                    FileProvider = fileProvider
                };
                TestExecutionContext context = new TestExecutionContext
                {
                    FileSystem = fileSystem
                };
                TestDocument document = new TestDocument(
                    new FilePath("/input/assets/test.less"),
                    new FilePath("assets/test.less"),
                    input);
                CompileLess less = new CompileLess();

                // When, Then
                await Should.ThrowAsync <Exception>(async() => await ExecuteAsync(document, context, less));
            }
Exemple #9
0
        private TestFileProvider GetFileProvider()
        {
            TestFileProvider fileProvider = new TestFileProvider();

            fileProvider.AddDirectory("/");
            fileProvider.AddDirectory("/output");

            fileProvider.AddFile("/output/test.md");

            return(fileProvider);
        }
Exemple #10
0
        private TestFileProvider GetFileProvider()
        {
            TestFileProvider fileProvider = new TestFileProvider
            {
                { "/a/b/c/foo.txt" },
                { "/a/x/bar.txt" }
            };

            // Directories that don't exist as files
            fileProvider.AddDirectory("/a/b/d");
            fileProvider.AddDirectory("/a/y/z");

            return(fileProvider);
        }
Exemple #11
0
            public void NestedImports()
            {
                // Given
                const string outerImport = @"
$font-stack:    Helvetica, sans-serif;";
                const string innerImport = @"
@import 'outer-import.scss';
$primary-color: #333;";
                const string input       = @"
@import 'libs/_inner-import.scss';

body {
  font: 100% $font-stack;
  color: $primary-color;
}";
                const string output      = "body { font: 100% Helvetica, sans-serif; color: #333; }\n";

                TestFileProvider fileProvider = new TestFileProvider();

                fileProvider.AddDirectory("/");
                fileProvider.AddDirectory("/input");
                fileProvider.AddDirectory("/input/assets");
                fileProvider.AddDirectory("/input/assets/libs");
                fileProvider.AddFile("/input/assets/test.scss", input);
                fileProvider.AddFile("/input/assets/libs/_outer-import.scss", outerImport);
                fileProvider.AddFile("/input/assets/libs/_inner-import.scss", innerImport);
                TestFileSystem fileSystem = new TestFileSystem
                {
                    FileProvider = fileProvider
                };
                IExecutionContext context = new TestExecutionContext
                {
                    FileSystem = fileSystem
                };
                IDocument document = new TestDocument(input, new MetadataItems
                {
                    { Keys.RelativeFilePath, new FilePath("assets/test.scss") }
                });

                Sass sass = new Sass().IncludeSourceComments(false).WithCompactOutputStyle();

                // When
                List <IDocument> results = sass.Execute(new[] { document }, context).ToList(); // Make sure to materialize the result list

                // Then
                Assert.That(results.Select(x => x.Content), Is.EqualTo(new[] { output }));
                Assert.That(results.Select(x => x.FilePath(Keys.RelativeFilePath).FullPath), Is.EqualTo(new[] { "assets/test.css" }));
            }
            private TestFileProvider GetFileProvider()
            {
                TestFileProvider fileProvider = new TestFileProvider();

                fileProvider.AddDirectory("/");
                fileProvider.AddDirectory("/AlternateIgnorePrefix");
                fileProvider.AddDirectory("/AlternateViewStart");
                fileProvider.AddDirectory("/AlternateViewStartPath");
                fileProvider.AddDirectory("/IgnoreUnderscores");
                fileProvider.AddDirectory("/Layout");
                fileProvider.AddDirectory("/LayoutWithSection");
                fileProvider.AddDirectory("/SimpleTemplate");
                fileProvider.AddDirectory("/ViewStartAndLayout");

                fileProvider.AddFile(
                    "/Layout/_Layout.cshtml",
                    @"LAYOUT
@RenderBody()");
                fileProvider.AddFile(
                    "/ViewStartAndLayout/_ViewStart.cshtml",
                    @"@{
	Layout = ""_Layout.cshtml"";
}");
                fileProvider.AddFile(
                    "/ViewStartAndLayout/_Layout.cshtml",
                    @"LAYOUT2
@RenderBody()");
                fileProvider.AddFile(
                    "/AlternateViewStart/_ViewStart.cshtml",
                    @"@{
	Layout = @""/AlternateViewStart/_Layout.cshtml"";
}");
                fileProvider.AddFile(
                    "/AlternateViewStart/_ViewStartRelativeLayout.cshtml",
                    @"@{
	Layout = @""_Layout.cshtml"";
}");
                fileProvider.AddFile(
                    "/AlternateViewStart/_Layout.cshtml",
                    @"LAYOUT3
@RenderBody()");
                fileProvider.AddFile(
                    "/IgnoreUnderscores/_Layout.cshtml",
                    @"LAYOUT4
@RenderBody()");
                fileProvider.AddFile(
                    "/LayoutWithSection/_Layout.cshtml",
                    @"LAYOUT5
@RenderSection(""MySection"", false)
@RenderBody()");

                return(fileProvider);
            }
Exemple #13
0
            public async Task NestedImports()
            {
                // Given
                const string outerImport = @"
$font-stack:    Helvetica, sans-serif;";
                const string innerImport = @"
@import 'outer-import.scss';
$primary-color: #333;";
                const string input       = @"
@import 'libs/_inner-import.scss';

body {
  font: 100% $font-stack;
  color: $primary-color;
}";
                const string output      = "body { font: 100% Helvetica, sans-serif; color: #333; }\n";

                TestFileProvider fileProvider = new TestFileProvider();

                fileProvider.AddDirectory("/");
                fileProvider.AddDirectory("/input");
                fileProvider.AddDirectory("/input/assets");
                fileProvider.AddDirectory("/input/assets/libs");
                fileProvider.AddFile("/input/assets/test.scss", input);
                fileProvider.AddFile("/input/assets/libs/_outer-import.scss", outerImport);
                fileProvider.AddFile("/input/assets/libs/_inner-import.scss", innerImport);
                TestFileSystem fileSystem = new TestFileSystem
                {
                    FileProvider = fileProvider
                };
                TestExecutionContext context = new TestExecutionContext
                {
                    FileSystem = fileSystem
                };
                TestDocument document = new TestDocument(
                    new FilePath("/input/assets/test.scss"),
                    new FilePath("assets/test.scss"),
                    input);

                CompileSass sass = new CompileSass().IncludeSourceComments(false).WithCompactOutputStyle();

                // When
                TestDocument result = await ExecuteAsync(document, context, sass).SingleAsync();

                // Then
                result.Content.ShouldBe(output);
                result.Destination.FullPath.ShouldBe("assets/test.css");
            }
        private IFileProvider GetFileProviderB()
        {
            TestFileProvider fileProvider = new TestFileProvider();

            fileProvider.AddDirectory("/foo");
            fileProvider.AddDirectory("/foo/a");
            fileProvider.AddDirectory("/foo/a/b");
            fileProvider.AddDirectory("/foo/c");
            fileProvider.AddDirectory("/bar");

            fileProvider.AddFile("/foo/baz.txt");
            fileProvider.AddFile("/foo/c/baz.txt");
            fileProvider.AddFile("/bar/baz.txt");

            return(fileProvider);
        }
Exemple #15
0
        private TestFileProvider GetFileProvider()
        {
            TestFileProvider fileProvider = new TestFileProvider();

            fileProvider.AddDirectory("/");
            fileProvider.AddDirectory("/TestFiles");
            fileProvider.AddDirectory("/TestFiles/Input");
            fileProvider.AddDirectory("/TestFiles/Input/Subfolder");

            fileProvider.AddFile("/TestFiles/test-above-input.txt", "test");
            fileProvider.AddFile("/TestFiles/Input/test-a.txt", "aaa");
            fileProvider.AddFile("/TestFiles/Input/test-b.txt", "bbb");
            fileProvider.AddFile("/TestFiles/Input/Subfolder/test-c.txt", "ccc");

            return(fileProvider);
        }
Exemple #16
0
            private TestFileProvider GetFileProvider()
            {
                TestFileProvider fileProvider = new TestFileProvider();

                fileProvider.AddDirectory("/");
                fileProvider.AddDirectory("/a");
                fileProvider.AddDirectory("/b");

                fileProvider.AddFile("/a/1.md", @"File a1");
                fileProvider.AddFile("/a/1.md.meta", @"data: a1");
                fileProvider.AddFile("/a/1.md.other", @"data: other");
                fileProvider.AddFile("/a/2.md", @"File a2");
                fileProvider.AddFile("/a/2.md.meta", @"data: a2");

                fileProvider.AddFile("/b/1.md", @"File b1");
                fileProvider.AddFile("/b/1.md.meta", @"data: b1");

                return(fileProvider);
            }
Exemple #17
0
        private IFileProvider GetFileProvider()
        {
            TestFileProvider fileProvider = new TestFileProvider();

            fileProvider.AddDirectory("/");
            fileProvider.AddDirectory("/TestFiles");
            fileProvider.AddDirectory("/TestFiles/Input");
            fileProvider.AddDirectory("/TestFiles/Input/Subfolder");

            fileProvider.AddFile("/TestFiles/test-above-input.txt", "test");
            fileProvider.AddFile("/TestFiles/Input/markdown-x.md", "xxx");
            fileProvider.AddFile("/TestFiles/Input/test-a.txt", "aaa");
            fileProvider.AddFile("/TestFiles/Input/test-b.txt", "bbb");
            fileProvider.AddFile("/TestFiles/Input/Subfolder/markdown-y.md", "yyy");
            fileProvider.AddFile("/TestFiles/Input/Subfolder/test-c.txt", "ccc");
            fileProvider.AddFile("/TestFiles/Input/.dotfile", "dotfile");

            return(fileProvider);
        }
Exemple #18
0
            public void IncludesFileRelativeToSource()
            {
                // Given
                TestFileProvider fileProvider = new TestFileProvider();

                fileProvider.AddDirectory("/");
                fileProvider.AddDirectory("/A");
                fileProvider.AddDirectory("/A/B");
                fileProvider.AddDirectory("/A/D");
                fileProvider.AddFile("/A/B/c.txt", "foo");
                TestFileSystem fileSystem = new TestFileSystem
                {
                    FileProvider = fileProvider
                };

                fileSystem.InputPaths.Clear();
                fileSystem.InputPaths.Add("/A");

                TestExecutionContext context = new TestExecutionContext
                {
                    FileSystem = fileSystem
                };
                TestDocument document = new TestDocument()
                {
                    Source = new FilePath("/A/D/x.txt")
                };

                KeyValuePair <string, string>[] args = new KeyValuePair <string, string>[]
                {
                    new KeyValuePair <string, string>(null, "../B/c.txt")
                };
                Include shortcode = new Include();

                // When
                IShortcodeResult result = shortcode.Execute(args, string.Empty, document, context);

                // Then
                using (TextReader reader = new StreamReader(result.Stream))
                {
                    reader.ReadToEnd().ShouldBe("foo");
                }
            }
            public async Task Convert()
            {
                // Given
                const string input = @"
@foo: black;

div {
 color: @foo;
}";

                const string output = @"div {
  color: black;
}
";

                TestFileProvider fileProvider = new TestFileProvider();

                fileProvider.AddDirectory("/");
                fileProvider.AddDirectory("/input");
                fileProvider.AddDirectory("/input/assets");
                fileProvider.AddFile("/input/assets/test.less", input);
                TestFileSystem fileSystem = new TestFileSystem
                {
                    FileProvider = fileProvider
                };
                TestExecutionContext context = new TestExecutionContext
                {
                    FileSystem = fileSystem
                };
                TestDocument document = new TestDocument(
                    new FilePath("/input/assets/test.less"),
                    new FilePath("assets/test.less"),
                    input);
                CompileLess less = new CompileLess();

                // When
                TestDocument result = await ExecuteAsync(document, context, less).SingleAsync();

                // Then
                result.Content.ShouldBe(output, StringCompareShould.IgnoreLineEndings);
                result.Destination.FullPath.ShouldBe("assets/test.css");
            }
Exemple #20
0
            public async Task Convert()
            {
                // Given
                const string input = @"
$font-stack:    Helvetica, sans-serif;
$primary-color: #333;

body {
  font: 100% $font-stack;
  color: $primary-color;
}";

                const string output = "body { font: 100% Helvetica, sans-serif; color: #333; }\n";

                TestFileProvider fileProvider = new TestFileProvider();

                fileProvider.AddDirectory("/");
                fileProvider.AddDirectory("/input");
                fileProvider.AddDirectory("/input/assets");
                fileProvider.AddFile("/input/assets/test.scss", input);
                TestFileSystem fileSystem = new TestFileSystem
                {
                    FileProvider = fileProvider
                };
                TestExecutionContext context = new TestExecutionContext
                {
                    FileSystem = fileSystem
                };
                TestDocument document = new TestDocument(
                    new NormalizedPath("/input/assets/test.scss"),
                    new NormalizedPath("assets/test.scss"),
                    input);

                CompileSass sass = new CompileSass().WithCompactOutputStyle();

                // When
                TestDocument result = await ExecuteAsync(document, context, sass).SingleAsync();

                // Then
                result.Content.ShouldBe(output);
                result.Destination.FullPath.ShouldBe("assets/test.css");
            }
Exemple #21
0
            public void NestedFoldersWilcard()
            {
                // Given
                TestFileProvider fileProvider = new TestFileProvider();

                fileProvider.AddDirectory("/a");
                fileProvider.AddDirectory("/a/b");
                fileProvider.AddDirectory("/a/b/c");
                fileProvider.AddDirectory("/a/bar");
                fileProvider.AddDirectory("/a/bar/foo");
                fileProvider.AddFile("/a/b/c/x.txt");
                fileProvider.AddFile("/a/bar/foo/y.txt");
                IDirectory directory = fileProvider.GetDirectory("/a");

                // When
                IEnumerable <IFile> matches = Globber.GetFiles(directory, "**/*.txt");

                // Then
                CollectionAssert.AreEquivalent(new[] { "/a/b/c/x.txt", "/a/bar/foo/y.txt" }, matches.Select(x => x.Path.FullPath));
            }
            public void ShouldReturnContainingPathWhenOtherInputPathStartsTheSame()
            {
                // Given
                TestFileProvider fileProvider = GetFileProvider();

                fileProvider.AddDirectory("yz");
                fileProvider.AddDirectory("y");
                fileProvider.AddFile("/a/yz/baz.txt");
                IFileSystem fileSystem = new TestFileSystem(fileProvider);

                fileSystem.RootPath = "/a";
                fileSystem.InputPaths.Add("yz");
                fileSystem.InputPaths.Add("y");

                // When
                NormalizedPath inputPath = fileSystem.GetContainingInputPath(new NormalizedPath("baz.txt"));

                // Then
                inputPath.FullPath.ShouldBe("/a/yz");
            }
            public void ShouldReturnContainingPathWhenOtherInputPathStartsTheSame()
            {
                // Given
                TestFileProvider fileProvider = GetFileProvider();

                fileProvider.AddDirectory("yz");
                fileProvider.AddDirectory("y");
                fileProvider.AddFile("/a/yz/baz.txt");
                IFileSystem fileSystem = new TestFileSystem(fileProvider);

                fileSystem.RootPath = "/a";
                fileSystem.InputPaths.Add("yz");
                fileSystem.InputPaths.Add("y");

                // When
                DirectoryPath inputPath = fileSystem.GetContainingInputPath(new FilePath("baz.txt"));

                // Then
                Assert.AreEqual("/a/yz", inputPath?.FullPath);
            }
Exemple #24
0
            public void ShouldReturnExistingFiles(string directory, string[] patterns, string[] expected)
            {
                // Given
                FileSystem fileSystem = new FileSystem();

                fileSystem.FileProviders.Add(string.Empty, GetFileProvider());
                TestFileProvider alternateProvider = new TestFileProvider();

                alternateProvider.AddDirectory("/");
                alternateProvider.AddDirectory("/q");
                alternateProvider.AddFile("/q/werty.txt");
                fileSystem.FileProviders.Add("qwerty", alternateProvider);
                IDirectory dir = fileSystem.GetDirectory(directory);

                // When
                IEnumerable <IFile> results = fileSystem.GetFiles(dir, patterns);

                // Then
                CollectionAssert.AreEquivalent(expected, results.Select(x => x.Path.FullPath));
            }
            public void DoubleWildcardShouldMatchZeroOrMorePathSegments()
            {
                // Given
                TestFileProvider fileProvider = new TestFileProvider();

                fileProvider.AddDirectory("/");
                fileProvider.AddDirectory("/root");
                fileProvider.AddDirectory("/root/a");
                fileProvider.AddDirectory("/root/a/b");
                fileProvider.AddDirectory("/root/d");
                fileProvider.AddFile("/root/a/x.txt");
                fileProvider.AddFile("/root/a/b/x.txt");
                fileProvider.AddFile("/root/d/x.txt");
                IDirectory directory = fileProvider.GetDirectory("/");

                // When
                IEnumerable <IFile> matches = Globber.GetFiles(directory, new[] { "root/{a,}/**/x.txt" });

                // Then
                matches.Select(x => x.Path.FullPath).ShouldBe(
                    new[] { "/root/a/x.txt", "/root/a/b/x.txt", "/root/d/x.txt" }, true);
            }
Exemple #26
0
            public void ConvertingBadSassFails()
            {
                // Given
                const string     input        = @"
$font-stack:    Helvetica, sans-serif
$primary-color: #333

body {
  font: 100% $font-stack;
  color: $primary-color;
}";
                TestFileProvider fileProvider = new TestFileProvider();

                fileProvider.AddDirectory("/");
                fileProvider.AddDirectory("/input");
                fileProvider.AddDirectory("/input/assets");
                fileProvider.AddFile("/input/assets/test.scss", input);
                TestFileSystem fileSystem = new TestFileSystem
                {
                    FileProvider = fileProvider
                };
                IExecutionContext context = new TestExecutionContext
                {
                    FileSystem = fileSystem
                };
                IDocument document = new TestDocument(input, new MetadataItems
                {
                    { Keys.RelativeFilePath, new FilePath("assets/test.scss") }
                });

                Sass sass = new Sass();

                // When, Then
                Assert.Catch <AggregateException>(() =>
                {
                    sass.Execute(new[] { document }, context).ToList(); // Make sure to materialize the result list
                });
            }
            public void EmptyResultIfFileDoesNotExist()
            {
                // Given
                TestFileProvider fileProvider = new TestFileProvider();

                fileProvider.AddDirectory("/");
                fileProvider.AddDirectory("/A");
                fileProvider.AddDirectory("/A/B");
                fileProvider.AddFile("/A/B/c.txt", "foo");
                TestFileSystem fileSystem = new TestFileSystem
                {
                    FileProvider = fileProvider
                };

                fileSystem.InputPaths.Clear();
                fileSystem.InputPaths.Add("/A");

                TestExecutionContext context = new TestExecutionContext
                {
                    FileSystem = fileSystem
                };

                context.TestLoggerProvider.ThrowLogLevel = LogLevel.Error;
                TestDocument document = new TestDocument();

                KeyValuePair <string, string>[] args = new KeyValuePair <string, string>[]
                {
                    new KeyValuePair <string, string>(null, "B/d.txt")
                };
                IncludeShortcode shortcode = new IncludeShortcode();

                // When
                IDocument result = shortcode.Execute(args, string.Empty, document, context);

                // Then
                result.ShouldBeOfType <TestDocument>().Content.ShouldBeEmpty();
            }
Exemple #28
0
            public void NullResultIfFileDoesNotExist()
            {
                // Given
                ThrowOnTraceEventType(System.Diagnostics.TraceEventType.Error);
                TestFileProvider fileProvider = new TestFileProvider();

                fileProvider.AddDirectory("/");
                fileProvider.AddDirectory("/A");
                fileProvider.AddDirectory("/A/B");
                fileProvider.AddFile("/A/B/c.txt", "foo");
                TestFileSystem fileSystem = new TestFileSystem
                {
                    FileProvider = fileProvider
                };

                fileSystem.InputPaths.Clear();
                fileSystem.InputPaths.Add("/A");

                TestExecutionContext context = new TestExecutionContext
                {
                    FileSystem = fileSystem
                };
                TestDocument document = new TestDocument();

                KeyValuePair <string, string>[] args = new KeyValuePair <string, string>[]
                {
                    new KeyValuePair <string, string>(null, "B/d.txt")
                };
                Include shortcode = new Include();

                // When
                IShortcodeResult result = shortcode.Execute(args, string.Empty, document, context);

                // Then
                result.Stream.ShouldBeNull();
            }
            public void IncludesFileRelativeToSource()
            {
                // Given
                TestFileProvider fileProvider = new TestFileProvider();

                fileProvider.AddDirectory("/");
                fileProvider.AddDirectory("/A");
                fileProvider.AddDirectory("/A/B");
                fileProvider.AddDirectory("/A/D");
                fileProvider.AddFile("/A/B/c.txt", "foo");
                TestFileSystem fileSystem = new TestFileSystem
                {
                    FileProvider = fileProvider
                };

                fileSystem.InputPaths.Clear();
                fileSystem.InputPaths.Add("/A");

                TestExecutionContext context = new TestExecutionContext
                {
                    FileSystem = fileSystem
                };
                TestDocument document = new TestDocument(new NormalizedPath("/A/D/x.txt"), (NormalizedPath)null);

                KeyValuePair <string, string>[] args = new KeyValuePair <string, string>[]
                {
                    new KeyValuePair <string, string>(null, "../B/c.txt")
                };
                IncludeShortcode shortcode = new IncludeShortcode();

                // When
                IDocument result = shortcode.Execute(args, string.Empty, document, context);

                // Then
                result.ShouldBeOfType <TestDocument>().Content.ShouldBe("foo");
            }
Exemple #30
0
        private IFileProvider GetFileProvider()
        {
            TestFileProvider fileProvider = new TestFileProvider();

            fileProvider.AddDirectory("/");
            fileProvider.AddDirectory("/a");
            fileProvider.AddDirectory("/a/b");
            fileProvider.AddDirectory("/a/b/c");
            fileProvider.AddDirectory("/a/b/d");
            fileProvider.AddDirectory("/a/x");
            fileProvider.AddDirectory("/a/y");
            fileProvider.AddDirectory("/a/y/z");

            fileProvider.AddFile("/a/b/c/foo.txt");
            fileProvider.AddFile("/a/x/bar.txt");

            return(fileProvider);
        }