示例#1
0
        private void Setup()
        {
            _mock      = new Mock <IJSRuntime>();
            _formatted = Code + "\r\nabc(1.23,4.56);";
            _mock.Setup(m => m.InvokeAsync <double>(_formatted, It.IsAny <object[]>())).Returns(new ValueTask <double>(Task.FromResult(7.89)));

            _unit = new JavascriptOptimizer(_mock.Object, new BlazorClientConfiguration {
                EnableOptimizerWorker = false
            });
            _unit.Initialize(Code, Mock.Of <IActivityLogger>());
        }
        public async Task Given_function_code_And_configured_to_run_in_ui_thread_When_Minimizing_Then_should_evaluate_function_with_parameters()
        {
            var mock      = new Mock <IJSRuntime>();
            var formatted = Code + "\r\nabc(1.23,4.56);";

            mock.Setup(m => m.InvokeAsync <double>(formatted, It.IsAny <object[]>())).Returns(new ValueTask <double>(Task.FromResult(7.89)));

            var unit = new JavascriptOptimizer(mock.Object, new BlazorClientConfiguration {
                EnableOptimizerWorker = false
            });

            unit.Initialize(Code, Mock.Of <IActivityLogger>());

            await unit.Minimize(new[] { 1.23, 4.56 });

            mock.Verify(m => m.InvokeAsync <double>("BlazorDynamicJavascriptRuntime.evaluate", It.Is <object[]>(p => p[0].ToString() == formatted)));
        }