Exemple #1
0
        public void RequireFunctionIsAvailable()
        {
            // Arrange
            var withoutBuiltinLibrary = new NodeSettings {
                UseBuiltinLibrary = false
            };
            var withBuiltinLibrary = new NodeSettings {
                UseBuiltinLibrary = true
            };

            const string input = @"typeof require !== 'undefined';";

            // Act
            bool output1 = false;
            bool output2 = false;

            using (var jsEngine = new NodeJsEngine(withoutBuiltinLibrary))
            {
                output1 = jsEngine.Evaluate <bool>(input);
            }

            using (var jsEngine = new NodeJsEngine(withBuiltinLibrary))
            {
                output2 = jsEngine.Evaluate <bool>(input);
            }

            // Assert
            Assert.False(output1);
            Assert.True(output2);
        }
Exemple #2
0
        public void FileReadingIsCorrect()
        {
            // Arrange
            const string input        = @"let fs = require('fs');
fs.readFileSync('Files/link.txt', 'utf8')";
            const string targetOutput = "http://www.panopticoncentral.net/2015/09/09/the-two-faces-of-jsrt-in-windows-10/";

            // Act
            string output = string.Empty;

            using (var jsEngine = new NodeJsEngine(new NodeSettings {
                UseBuiltinLibrary = true
            }))
            {
                output = jsEngine.Evaluate <string>(input);
            }

            // Assert
            Assert.Equal(targetOutput, output);
        }