Exemple #1
0
        public async Task TwoWay_Cache_Value_From_Javascript()
        {
            var stringValue = "batman";
            var dataContext = new VmWithTwoStrings(null, null);

            var test = new TestInContextAsync <BindingInContext>()
            {
                Bind = (win) => BindInContext(win, dataContext, JavascriptBindingMode.TwoWay),
                Test = async(context) =>
                {
                    var root         = context.Binding.JsRootObject;
                    var stringFormJs = Factory.CreateString(stringValue);
                    await SetAttributeAsync(root, nameof(dataContext.String2), stringFormJs);

                    var cache = context.Cache;

                    await DoSafeAsyncUI(() =>
                    {
                        dataContext.String2.Should().Be(stringValue);
                        cache.GetCached(stringValue).Should().NotBeNull();
                    });

                    await DoSafeAsyncUI(() => dataContext.String1 = stringValue);

                    var string1Value = GetAttribute(root, nameof(dataContext.String1));
                    string1Value.GetStringValue().Should().Be(stringValue);
                }
            };

            await RunAsync(test);
        }
Exemple #2
0
        public async Task TwoWay_Is_Garbage_Collecting_String()
        {
            var stringValue  = "batman";
            var stringValue2 = "robin";
            var root         = new VmWithTwoStrings(stringValue, null);

            Task CacheShouldHaveOnlyString1(ICSharpToJsCache cSharpToJsCache) =>
            DoSafeAsyncUI(() =>
            {
                cSharpToJsCache.GetCached(stringValue).Should().NotBeNull();
                cSharpToJsCache.GetCached(stringValue2).Should().BeNull();
            });

            Task CacheShouldHaveNoString(ICSharpToJsCache cSharpToJsCache) =>
            DoSafeAsyncUI(() =>
            {
                cSharpToJsCache.GetCached(stringValue).Should().BeNull();
                cSharpToJsCache.GetCached(stringValue2).Should().BeNull();
            });

            Task CacheShouldHaveBothString(ICSharpToJsCache cSharpToJsCache) =>
            DoSafeAsyncUI(() =>
            {
                cSharpToJsCache.GetCached(stringValue).Should().NotBeNull();
                cSharpToJsCache.GetCached(stringValue2).Should().NotBeNull();
            });

            async Task UpdateRoot(Action <VmWithTwoStrings> update) => await DoSafeAsyncUI(() => update(root));

            var test = new TestInContextAsync <BindingInContext>()
            {
                Bind = (win) => BindInContext(win, root, JavascriptBindingMode.TwoWay),
                Test = async(context) =>
                {
                    var cache = context.Cache;

                    await CacheShouldHaveOnlyString1(cache);

                    await UpdateRoot((vm) =>
                    {
                        vm.String2 = stringValue2;
                    });
                    await CacheShouldHaveBothString(cache);

                    await UpdateRoot((vm) =>
                    {
                        vm.String2 = null;
                    });
                    await CacheShouldHaveOnlyString1(cache);

                    await UpdateRoot((vm) =>
                    {
                        vm.String2 = stringValue;
                    });
                    await CacheShouldHaveOnlyString1(cache);

                    await UpdateRoot((vm) =>
                    {
                        vm.String1 = null;
                    });
                    await CacheShouldHaveOnlyString1(cache);

                    await UpdateRoot((vm) =>
                    {
                        vm.String2 = null;
                    });
                    await CacheShouldHaveNoString(cache);
                }
            };

            await RunAsync(test);
        }