public void FileScriptLoaderLoadsFilesFromSearchPaths()
        {
            var configuration = new V8Configuration()
                .AddScriptSearchPath(Environment.CurrentDirectory + "\\Root");

            var sut = new FileScriptLoader()
            {
                Configuration = configuration
            };

            var result = sut.Load("scriptAtRoot.js");

            Assert.Equal("baz", result);
        }
        public void FileScriptLoaderLoadsFiles(string script, string scriptText)
        {
            var configuration = new V8Configuration()
                .AddScriptSearchPath(Environment.CurrentDirectory);

            var sut = new FileScriptLoader()
            {
                Configuration = configuration
            };

            var result = sut.Load(script);

            Assert.Equal(scriptText, result);
        }
        public void FileScriptLoaderThrowsWhenItFailsToLoadFile(string scriptName, string searchFolders, string pathsConsidered)
        {
            var paths = searchFolders.Split(',');
            var configuration = new V8Configuration();

            foreach (var path in paths)
            {
                configuration.AddScriptSearchPath(path);
            }

            var sut = new FileScriptLoader()
            {
                Configuration = configuration
            };

            var exception = Assert.Throws<ScriptLoadException>(() => sut.Load(scriptName));

            var expectedText = "Could not find script " + scriptName + ". Paths considered:\r\n" + 
                string.Join("\r\n", pathsConsidered.Split(',')
                .Select(x => Environment.CurrentDirectory + "\\" + x));

            Assert.Equal(expectedText, exception.Message);
        }
        public void FileScriptLoaderHandlesLoadErrorsGracefully(string scriptToLoad)
        {
            var configuration = new V8Configuration()
                .AddScriptSearchPath("");

            var sut = new FileScriptLoader()
            {
                Configuration = configuration
            };

            var exception = Assert.Throws<ScriptLoadException>(() => sut.Load(scriptToLoad));

            Assert.Equal(exception.Message, "Could not load script " + scriptToLoad + ". Check inner exception for details.");
            Assert.IsType<ArgumentException>(exception.InnerException);
        }
        public void FileScriptLoaderLoadsFilesFromSearchPathsInOrder(string searchPaths, string expectedText)
        {
            var configuration = new V8Configuration();

            foreach (var path in searchPaths.Split(','))
            {
                configuration.AddScriptSearchPath(path);
            }

            var sut = new FileScriptLoader()
            {
                Configuration = configuration
            };

            var result = sut.Load("innerScript.js");

            Assert.Equal(expectedText, result);
        }
        public void LoaderHandlesUrlPaths()
        {
            var configuration = new V8Configuration()
                .AddScriptSearchPath("Root")
                .AddScriptSearchPath("Root\\Inner1");

            var sut = new FileScriptLoader()
            {
                Configuration = configuration
            };

            var actual = sut.Load("./Inner2/innerScript.js");

            Assert.Equal("qux", actual);
        }
        public void FileScriptLoaderHandlesRelativeDirectories()
        {
            var configuration = new V8Configuration()
                .AddScriptSearchPath("Root")
                .AddScriptSearchPath("Root\\Inner1");

            var sut = new FileScriptLoader()
            {
                Configuration = configuration
            };

            var actual = sut.Load("Inner2\\innerScript.js");

            Assert.Equal("qux", actual);
        }
        public void FileScriptLoaderHandlesTrailingSlashes()
        {
            var configuration = new V8Configuration()
                .AddScriptSearchPath("Root\\");

            var sut = new FileScriptLoader()
            {
                Configuration = configuration
            };

            var actual = sut.Load("scriptAtRoot.js");

            Assert.Equal("baz", actual);
        }