Example #1
0
 protected Task RunAsync(TestInContextAsync test, [CallerMemberName] string memberName = "")
 {
     return(RunAsync(test, mb => RunInContext(async() => await test.Test(mb)), memberName));
 }
        public async Task Stress_TwoWay_Collection() 
        {

            var test = new TestInContextAsync() 
            {
                Bind = (win) => HTML_Binding.Bind(win, _DataContext, JavascriptBindingMode.TwoWay),
                Test = async (mb) => 
                {
                    var js = mb.JSRootObject;

                    var col = GetSafe(() => GetCollectionAttribute(js, "Skills"));
                    col.GetArrayLength().Should().Be(2);

                    Check(col, _DataContext.Skills);

                    _DataContext.Skills.Add(new Skill() { Name = "C++", Type = "Info" });

                    await Task.Delay(150);
                    col = GetSafe(() => GetCollectionAttribute(js, "Skills"));
                    Check(col, _DataContext.Skills);

                    _DataContext.Skills[0] = new Skill() { Name = "HTML5", Type = "Info" };
                    int iis = 500;
                    for (int i = 0; i < iis; i++) 
                    {
                        _DataContext.Skills.Insert(0, new Skill() { Name = "HTML5", Type = "Info" });
                    }

                    bool notok = true;
                    int tcount = _DataContext.Skills.Count;

                    var stopWatch = new Stopwatch();
                    stopWatch.Start();

                    while (notok) 
                    {
                        await Task.Delay(10);
                        col = GetSafe(() => GetCollectionAttribute(js, "Skills"));
                        notok = col.GetArrayLength() != tcount;
                    }
                    stopWatch.Stop();
                    var ts = stopWatch.ElapsedMilliseconds;
                    _Logger.Info($"Perf: {((double) (ts)) / 1000} sec for {iis} iterations");
                    Check(col, _DataContext.Skills);

                    CheckVsExpectation(ts, TestPerformanceKind.TwoWay_Collection);
                }
            };

            await RunAsync(test);
        }
        public async Task Stress_TwoWay_Int() 
        {
            var test = new TestInContextAsync() 
            {
                Path = TestContext.Simple,
                Bind = (win) => HTML_Binding.Bind(win, _DataContext, JavascriptBindingMode.TwoWay),
                Test = async (mb) => 
                {
                    var js = mb.JSRootObject;
                    int iis = 500;
                    for (int i = 0; i < iis; i++) 
                    {
                        _DataContext.Age += 1;
                    }

                    bool notok = true;
                    var tg = _DataContext.Age;
                    await Task.Delay(700);

                    var stopWatch = new Stopwatch();
                    stopWatch.Start();

                    while (notok) 
                    {
                        await Task.Delay(100);
                        var doublev = GetIntAttribute(js, "Age");
                        notok = doublev != tg;
                    }
                    stopWatch.Stop();
                    var ts = stopWatch.ElapsedMilliseconds;
                    _Logger.Info($"Perf: {((double) (ts)) / 1000} sec for {iis} iterations");

                    CheckVsExpectation(ts, TestPerformanceKind.TwoWay_Int);
                }
            };

            await RunAsync(test);
        }
        public async Task Stress_Collection_Update_From_Javascript() 
        {
            int r = 100;
            var datacontext = new TwoList();
            datacontext.L1.AddRange(Enumerable.Range(0, r).Select(i => new Skill()));

            var test = new TestInContextAsync() 
            {
                Path = TestContext.Simple,
                Bind = (win) => HTML_Binding.Bind(win, datacontext, JavascriptBindingMode.TwoWay),
                Test = async (mb) => 
                {
                    var js = mb.JSRootObject;

                    var col1 = GetCollectionAttribute(js, "L1");
                    col1.GetArrayLength().Should().Be(r);

                    var col2 = GetCollectionAttribute(js, "L2");
                    col2.GetArrayLength().Should().Be(0);

                    var l2c = GetAttribute(js, "L2");
                    l2c.Should().NotBeNull();

                    var javascript = "window.app = function(value,coll){var args = []; args.push(0); args.push(0); for (var i = 0; i < value.length; i++) { args.push(value[i]);} coll.splice.apply(coll, args);  console.log(value.length); console.log(coll.length);};";
                    IJavascriptObject res = null;
                    bool ok = _WebView.Eval(javascript, out res);
                    ok.Should().BeTrue();

                    bool notok = true;
                    var stopWatch = new Stopwatch();
                    stopWatch.Start();

                    DoSafe(() => Call(_WebView.GetGlobal(), "app", col1, l2c));
                    while (notok) 
                    {
                        await Task.Delay(100);
                        notok = datacontext.L2.Count != r;
                    }
                    stopWatch.Stop();
                    long ts = stopWatch.ElapsedMilliseconds;

                    _Logger.Info($"Perf: {((double) (ts)) / 1000} sec for {r} iterations");
                    CheckVsExpectation(ts, TestPerformanceKind.TwoWay_Collection_Update_From_Javascript);
                }
            };

            await RunAsync(test);
        }
 protected Task RunAsync(TestInContextAsync test, [CallerMemberName] string memberName = "") 
 {
     return RunAsync(test, mb => RunInContext(async () => await test.Test(mb)), memberName);        
 }
 protected Task RunAsync <TContext>(TestInContextAsync <TContext> test, [CallerMemberName] string memberName = "") where TContext : IDisposable
 {
     return(RunAsync(test, mb => RunInContext(async() => await test.Test(mb)), memberName));
 }