Пример #1
0
        public void JsAggregateModuleLoaderPrefixesMustBeSpecified()
        {
            var inMemoryModuleLoader1 = new InMemoryModuleLoader();

            inMemoryModuleLoader1.RegisterModule(new HelloWorldModule());

            var inMemoryModuleLoader2 = new InMemoryModuleLoader();

            inMemoryModuleLoader2.RegisterModule(new GoodnightMoonModule());

            var aggregateModuleLoader = new PrefixedAggregateModuleLoader();

            Assert.Throws <ArgumentNullException>(() =>
            {
                aggregateModuleLoader.RegisterModuleLoader("", inMemoryModuleLoader1);
            });

            Assert.Throws <ArgumentNullException>(() =>
            {
                aggregateModuleLoader.RegisterModuleLoader(null, inMemoryModuleLoader2);
            });

            Assert.Throws <ArgumentNullException>(() =>
            {
                aggregateModuleLoader.RegisterModuleLoader("foobar", null);
            });
        }
Пример #2
0
        public void JsAggregateModuleLoaderThrowsWhenWhitespacePrefixesAreUsed()
        {
            var script = @"
        import helloworld from '       !hello_world';
        export default helloworld;
        ";

            var inMemoryModuleLoader1 = new InMemoryModuleLoader();

            inMemoryModuleLoader1.RegisterModule(new HelloWorldModule());

            var aggregateModuleLoader = new PrefixedAggregateModuleLoader();

            Assert.Throws <ArgumentNullException>(() =>
            {
                aggregateModuleLoader.RegisterModuleLoader("       ", inMemoryModuleLoader1);
            });

            var baristaRuntime = GetRuntimeFactory(aggregateModuleLoader);

            using (var rt = baristaRuntime.CreateRuntime())
            {
                using (var ctx = rt.CreateContext())
                {
                    Assert.Throws <JsScriptException>(() =>
                    {
                        var result = ctx.EvaluateModule(script);
                    });
                }
            }
        }
Пример #3
0
        public void JsAggregateModuleLoaderPrefixesMustBeUnique()
        {
            var inMemoryModuleLoader1 = new InMemoryModuleLoader();

            inMemoryModuleLoader1.RegisterModule(new HelloWorldModule());

            var inMemoryModuleLoader2 = new InMemoryModuleLoader();

            inMemoryModuleLoader2.RegisterModule(new GoodnightMoonModule());

            var aggregateModuleLoader = new PrefixedAggregateModuleLoader();

            aggregateModuleLoader.RegisterModuleLoader("daytime", inMemoryModuleLoader1);
            Assert.Throws <ArgumentException>(() =>
            {
                aggregateModuleLoader.RegisterModuleLoader("daytime", inMemoryModuleLoader2);
            });
        }
Пример #4
0
        public void JsAggregateModuleLoaderPrefixedModules()
        {
            var script = @"
        import helloworld from 'daytime!hello_world';
        export default helloworld;
        ";

            var script2 = @"
        import helloworld from 'nighttime!goodnight_moon';
        export default helloworld;
        ";

            var inMemoryModuleLoader1 = new InMemoryModuleLoader();

            inMemoryModuleLoader1.RegisterModule(new HelloWorldModule());

            var inMemoryModuleLoader2 = new InMemoryModuleLoader();

            inMemoryModuleLoader2.RegisterModule(new GoodnightMoonModule());

            var aggregateModuleLoader = new PrefixedAggregateModuleLoader();

            aggregateModuleLoader.RegisterModuleLoader("daytime", inMemoryModuleLoader1);
            aggregateModuleLoader.RegisterModuleLoader("nighttime", inMemoryModuleLoader2);

            var baristaRuntime = GetRuntimeFactory(aggregateModuleLoader);

            using (var rt = baristaRuntime.CreateRuntime())
            {
                using (var ctx = rt.CreateContext())
                {
                    var result = ctx.EvaluateModule(script);

                    Assert.Equal("Hello, World!", result.ToString());

                    result = ctx.EvaluateModule(script2);

                    Assert.Equal("Goodnight, moon.", result.ToString());
                }
            }
        }
Пример #5
0
        public void JsAggregateModuleLoaderCanRemoveLoader()
        {
            var inMemoryModuleLoader1 = new InMemoryModuleLoader();

            inMemoryModuleLoader1.RegisterModule(new HelloWorldModule());

            var inMemoryModuleLoader2 = new InMemoryModuleLoader();

            inMemoryModuleLoader2.RegisterModule(new GoodnightMoonModule());

            var aggregateModuleLoader = new PrefixedAggregateModuleLoader();

            Assert.False(aggregateModuleLoader.HasModuleLoader("foo"));
            aggregateModuleLoader.RegisterModuleLoader("foo", inMemoryModuleLoader1);
            Assert.True(aggregateModuleLoader.HasModuleLoader("foo"));
            aggregateModuleLoader.RemoveModuleLoader("foo");
            Assert.False(aggregateModuleLoader.HasModuleLoader("foo"));
        }