Exemple #1
0
            public void ErrorInConfigAfterLambdaExpansionContainsCorrectLineNumbers()
            {
                // Given
                RemoveListener();
                Engine engine = new Engine();
                FileSystem fileSystem = new FileSystem();
                Config config = new Config(engine, fileSystem);
                string configScript = @"
                Assemblies.Load("""");
                ===
                Pipelines.Add(
                Content(true
                && @doc.Get<bool>(""Key"") == false
                )
                );

                foo bar;
                ";

                // When
                AggregateException exception = null;
                try
                {
                    config.Configure(configScript, false, null, false);
                }
                catch (AggregateException ex)
                {
                    exception = ex;
                }

                // Then
                Assert.AreEqual(1, exception.InnerExceptions.Count);
                StringAssert.StartsWith("Line 10", exception.InnerExceptions[0].Message);
            }
Exemple #2
0
            public void CanSetCustomDocumentFactory()
            {
                // Given
                Engine engine = new Engine();
                FileSystem fileSystem = new FileSystem();
                Config config = new Config(engine, fileSystem);
                string configScript = @"
                public class MyDocument : CustomDocument
                {
                public int Count { get; set; }

                protected override CustomDocument Clone()
                {
                return new MyDocument();
                }
                }
                ---
                Engine.DocumentFactory = new CustomDocumentFactory<MyDocument>(Engine.DocumentFactory);
                ";

                // When
                config.Configure(configScript, false, null, false);

                // Then
                Assert.AreEqual("CustomDocumentFactory`1", engine.DocumentFactory.GetType().Name);
            }
            public void ModifiesFolders()
            {
                // Given
                FileSystem fileSystem = new FileSystem
                {
                    RootPath = @"C:/A",
                    OutputPath = "C"
                };
                fileSystem.InputPaths.Add("B");
                PackagesCollection packages = new PackagesCollection(fileSystem);
                AssemblyCollection assemblies = new AssemblyCollection();
                string setup = @"
                FileSystem.RootPath = @""C:\X"";
                FileSystem.InputPaths.Add(""Y"");
                FileSystem.OutputPath = ""Z"";
                ";
                SetupScript setupScript = new SetupScript(setup);
                setupScript.Compile();

                // When
                setupScript.Invoke(packages, assemblies, fileSystem);

                // Then
                Assert.AreEqual(@"C:/X", fileSystem.RootPath.FullPath);
                Assert.AreEqual(@"Z", fileSystem.OutputPath.FullPath);
                CollectionAssert.AreEquivalent(new[] { "input", "B", "Y" }, fileSystem.InputPaths.Select(x => x.FullPath));
            }
Exemple #4
0
            public void SetThrowsForNullValue()
            {
                // Given
                FileSystem fileSystem = new FileSystem();

                // When, Then
                Assert.Throws<ArgumentNullException>(() => fileSystem.OutputPath = null);
            }
Exemple #5
0
            public void SetThrowsForRelativePath()
            {
                // Given
                FileSystem fileSystem = new FileSystem();

                // When, Then
                Assert.Throws<ArgumentException>(() => fileSystem.RootPath = "foo");
            }
Exemple #6
0
            public void AddsDefaultInputPath()
            {
                // Given, When
                FileSystem fileSystem = new FileSystem();

                // Then
                CollectionAssert.AreEquivalent(new [] { "theme", "input" }, fileSystem.InputPaths.Select(x => x.FullPath));
            }     
Exemple #7
0
            public void CanSet()
            {
                // Given
                FileSystem fileSystem = new FileSystem();

                // When
                fileSystem.RootPath = "/foo/bar";

                // Then
                Assert.AreEqual("/foo/bar", fileSystem.RootPath.FullPath);
            }
Exemple #8
0
            public void ShouldThrowForNullPatterns()
            {
                // Given
                FileSystem fileSystem = new FileSystem();
                fileSystem.FileProviders.Add(NormalizedPath.DefaultFileProvider.Scheme, GetFileProvider());
                IDirectory dir = fileSystem.GetDirectory("/");

                // When, Then
                Assert.Throws<ArgumentNullException>(() => fileSystem.GetFiles(dir, null));
            }
Exemple #9
0
            public void ThrowsIfProviderNotFoundForFilePath()
            {
                // Given
                FileSystem fileSystem = new FileSystem();
                FilePath path = new FilePath("foo", "/a/b/c.txt");

                // When, Then
                Assert.Throws<KeyNotFoundException>(() => fileSystem.GetFileProvider(path));
            }
Exemple #10
0
            public void ReturnsOtherProviderForFilePath()
            {
                // Given
                FileSystem fileSystem = new FileSystem();
                IFileProvider defaultProvider = Substitute.For<IFileProvider>();
                IFileProvider fooProvider = Substitute.For<IFileProvider>();
                fileSystem.FileProviders.Add(NormalizedPath.DefaultFileProvider.Scheme, defaultProvider);
                fileSystem.FileProviders.Add("foo", fooProvider);
                FilePath path = new FilePath("foo", "/a/b/c.txt");

                // When
                IFileProvider result = fileSystem.GetFileProvider(path);

                // Then
                Assert.AreEqual(fooProvider, result);
            }
Exemple #11
0
            public void ThrowsForRelativeFilePath()
            {
                // Given
                FileSystem fileSystem = new FileSystem();
                FilePath relativePath = new FilePath("A/B/C.txt");

                // When, Then
                Assert.Throws<ArgumentException>(() => fileSystem.GetFileProvider(relativePath));
            }
Exemple #12
0
            public void ReturnsInputFileWhenInputDirectoryAndFileAscend()
            {
                // Given
                FileSystem fileSystem = new FileSystem();
                fileSystem.RootPath = "/a/b";
                fileSystem.InputPaths.Add("../x/y");
                fileSystem.FileProviders.Add(NormalizedPath.DefaultFileProvider.Scheme, GetFileProvider());

                // When
                IFile result = fileSystem.GetInputFile("../bar.txt");

                // Then
                Assert.AreEqual("/a/x/bar.txt", result.Path.FullPath);
            }
Exemple #13
0
            public void ErrorInSetupContainsCorrectLineNumbers()
            {
                // Given
                RemoveListener();
                Engine engine = new Engine();
                FileSystem fileSystem = new FileSystem();
                Config config = new Config(engine, fileSystem);
                string configScript = @"
                Assemblies.Load("""");
                foo
                ===
                class Y { };
                ---
                int z = 0;
                ";

                // When
                AggregateException exception = null;
                try
                {
                    config.Configure(configScript, false, null, false);
                }
                catch (AggregateException ex)
                {
                    exception = ex;
                }

                // Then
                Assert.AreEqual(2, exception.InnerExceptions.Count);
                StringAssert.StartsWith("Line 3", exception.InnerExceptions[0].Message);
                StringAssert.StartsWith("Line 3", exception.InnerExceptions[1].Message);
            }
Exemple #14
0
            public void ThrowsForNullPath()
            {
                // Given
                FileSystem fileSystem = new FileSystem();

                // When, Then
                Assert.Throws<ArgumentNullException>(() => fileSystem.GetContainingInputPath(null));
            }
Exemple #15
0
            public void ReturnsCombinedInputDirectories()
            {
                // Given
                FileSystem fileSystem = new FileSystem();
                fileSystem.RootPath = "/a";
                fileSystem.InputPaths.Add("b/c");
                fileSystem.InputPaths.Add("b/d");
                fileSystem.InputPaths.Add("x");
                fileSystem.InputPaths.Add("y");
                fileSystem.InputPaths.Add("../z");
                fileSystem.FileProviders.Add(NormalizedPath.DefaultFileProvider.Scheme, GetFileProvider());

                // When
                IEnumerable<IDirectory> result = fileSystem.GetInputDirectories();

                // Then
                CollectionAssert.AreEquivalent(new []
                {
                    "/a/theme",
                    "/a/input",
                    "/a/b/c",
                    "/a/b/d",
                    "/a/x",
                    "/a/y",
                    "/z"
                }, result.Select(x => x.Path.FullPath));
            }
Exemple #16
0
            public void ReturnsDirectoryForAbsolutePath()
            {
                // Given 
                FileSystem fileSystem = new FileSystem();

                // When
                IDirectory result = fileSystem.GetInputDirectory("/A/B/C");

                // Then
                Assert.AreEqual("/A/B/C", result.Path.FullPath);
            }
Exemple #17
0
            public void ReturnsVirtualInputDirectoryForNullPath()
            {
                // Given 
                FileSystem fileSystem = new FileSystem();

                // When
                IDirectory result = fileSystem.GetInputDirectory();

                // Then
                Assert.IsInstanceOf<VirtualInputDirectory>(result);
                Assert.AreEqual(".", result.Path.FullPath);
            }
Exemple #18
0
            public void ShouldNotThrowForNullPattern()
            {
                // Given
                FileSystem fileSystem = new FileSystem();
                fileSystem.FileProviders.Add(NormalizedPath.DefaultFileProvider.Scheme, GetFileProvider());
                IDirectory dir = fileSystem.GetDirectory("/");

                // When
                IEnumerable<IFile> results = fileSystem.GetFiles(dir, null, "**/foo.txt");

                // Then
                CollectionAssert.AreEquivalent(new[] { "/a/b/c/foo.txt" }, results.Select(x => x.Path.FullPath));
            }
Exemple #19
0
            public void ShouldReturnContainingPathForRelativeDirectoryPath(string path, string expected)
            {
                // Given
                FileSystem fileSystem = new FileSystem();
                fileSystem.RootPath = "/a";
                fileSystem.InputPaths.Add("b");
                fileSystem.InputPaths.Add("y");
                fileSystem.FileProviders.Add(NormalizedPath.DefaultFileProvider.Scheme, GetFileProvider());

                // When
                DirectoryPath inputPath = fileSystem.GetContainingInputPath(new DirectoryPath(path));

                // Then
                Assert.AreEqual(expected, inputPath?.FullPath);
            }
Exemple #20
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));
                }
            }
Exemple #21
0
            public void ThrowsForNullPath()
            {
                // Given
                FileSystem fileSystem = new FileSystem();

                // When, Then
                Assert.Throws<ArgumentNullException>(() => fileSystem.GetFileProvider(null));
            }
Exemple #22
0
            public void ShouldReturnContainingPathForInputPathAboveRootPath(string path, string expected)
            {
                // Given
                FileSystem fileSystem = new FileSystem();
                fileSystem.RootPath = "/a/y";
                fileSystem.InputPaths.Add("../b");
                fileSystem.InputPaths.Add("../x");
                fileSystem.FileProviders.Add(string.Empty, GetFileProvider());

                // When
                DirectoryPath inputPathFromFilePath = fileSystem.GetContainingInputPath(new FilePath(path));
                DirectoryPath inputPathFromDirectoryPath = fileSystem.GetContainingInputPath(new DirectoryPath(path));

                // Then
                Assert.AreEqual(expected, inputPathFromFilePath?.FullPath);
                Assert.AreEqual(expected, inputPathFromDirectoryPath?.FullPath);
            }
Exemple #23
0
            public void ReturnsInputFile(string input, string expected)
            {
                // Given
                FileSystem fileSystem = new FileSystem();
                fileSystem.RootPath = "/a";
                fileSystem.InputPaths.Add("b/c");
                fileSystem.InputPaths.Add("b/d");
                fileSystem.InputPaths.Add("x");
                fileSystem.InputPaths.Add("y");
                fileSystem.FileProviders.Add(NormalizedPath.DefaultFileProvider.Scheme, GetFileProvider());

                // When
                IFile result = fileSystem.GetInputFile(input);

                // Then
                Assert.AreEqual(expected, result.Path.FullPath);
            }