Esempio n. 1
0
        public async Task TestFileAndAdd()
        {
            var sizeStrategy = new MySizeStrategy();
            var control      = new BreakpointBinder(sizeStrategy);
            await control.LoadFromJsonFileAsync("Common/bind.json");

            control.AddBreakpointWithBindings(1500, AdaptiveContainer.Create().Set("TitleFontSize", "120").Set("TitleColor", "pink").Get())
            .AddBreakpointWithBindings(1800, AdaptiveContainer.Create().Set("TitleFontSize", "150").Set("TitleColor", "yellow").Get());

            Assert.AreEqual(5, control.BindingsByWidth.Count);

            var result = control.TryGetActive(100);

            Assert.AreEqual("20", result["TitleFontSize"]);
            Assert.AreEqual("red", result["TitleColor"]);

            result = control.TryGetActive(600);
            Assert.AreEqual("50", result["TitleFontSize"]);
            Assert.AreEqual("blue", result["TitleColor"]);

            result = control.TryGetActive(1200);
            Assert.AreEqual("100", result["TitleFontSize"]);
            Assert.AreEqual("green", result["TitleColor"]);

            result = control.TryGetActive(1600);
            Assert.AreEqual("120", result["TitleFontSize"]);
            Assert.AreEqual("pink", result["TitleColor"]);

            result = control.TryGetActive(1900);
            Assert.AreEqual("150", result["TitleFontSize"]);
            Assert.AreEqual("yellow", result["TitleColor"]);
        }
        public void RaiseBreakpointChanged()
        {
            var sizeStrategy = new MySizeStrategy();
            var service      = new BreakpointListener(sizeStrategy);

            int count = 0;

            service.BreakpointChanged += (s, e) =>
            {
                count++;
            };

            service.AddBreakpoint(0);
            service.AddBreakpoint(100);
            service.AddBreakpoint(200);
            service.AddBreakpoint(300);

            sizeStrategy.RaiseSizeChanged(10);
            sizeStrategy.RaiseSizeChanged(20);   // ignored
            sizeStrategy.RaiseSizeChanged(150);
            sizeStrategy.RaiseSizeChanged(160);  // ignored
            sizeStrategy.RaiseSizeChanged(170);  // ignored
            sizeStrategy.RaiseSizeChanged(180);  // ignored
            sizeStrategy.RaiseSizeChanged(250);
            sizeStrategy.RaiseSizeChanged(260);  // ignored
            sizeStrategy.RaiseSizeChanged(350);
            sizeStrategy.RaiseSizeChanged(1000); // ignored
            sizeStrategy.RaiseSizeChanged(1600); // ignored

            Assert.AreEqual(4, count);
        }
        public void IsNotified_OnSizeChanged()
        {
            var sizeStrategy = new MySizeStrategy();
            var service      = new BreakpointListener(sizeStrategy);

            Assert.AreEqual(-1, service.CurrentWidth);

            sizeStrategy.RaiseSizeChanged(100);

            Assert.AreEqual(100, service.CurrentWidth);
        }
Esempio n. 4
0
        public async Task TestLoad_WhenFileChange()
        {
            var sizeStrategy = new MySizeStrategy();
            var control      = new BreakpointBinder(sizeStrategy);

            Assert.AreEqual(0, control.BindingsByWidth.Count);

            control.File = "Common/bind.json";

            await Task.Delay(1000);

            Assert.AreEqual(3, control.BindingsByWidth.Count);
        }
        public void AddBreakpoint_SortOnAdd()
        {
            var sizeStrategy = new MySizeStrategy();
            var service      = new BreakpointListener(sizeStrategy);

            service.AddBreakpoint(200);
            service.AddBreakpoint(0);
            service.AddBreakpoint(100);

            Assert.AreEqual(3, service.Breakpoints.Count);
            Assert.AreEqual(0, service.Breakpoints[0]);
            Assert.AreEqual(100, service.Breakpoints[1]);
            Assert.AreEqual(200, service.Breakpoints[2]);
        }
Esempio n. 6
0
        public void TestIsNotified()
        {
            var sizeStrategy = new MySizeStrategy();
            var control      = new BreakpointBinder(sizeStrategy);

            control.AddBreakpointWithBindings(0, AdaptiveContainer.Create().Set("TitleFontSize", "20").Set("TitleColor", "red").Get())
            .AddBreakpointWithBindings(500, AdaptiveContainer.Create().Set("TitleFontSize", "50").Set("TitleColor", "blue").Get())
            .AddBreakpointWithBindings(1000, AdaptiveContainer.Create().Set("TitleFontSize", "100").Set("TitleColor", "green").Get());

            Assert.IsNull(control.Active);

            sizeStrategy.RaiseSizeChanged(600);

            Assert.AreEqual("50", control.Active["TitleFontSize"]);
            Assert.AreEqual("blue", control.Active["TitleColor"]);
        }
        public async Task RaiseBreakpointChanged_DeferredOnAdd()
        {
            var sizeStrategy = new MySizeStrategy();
            var service      = new BreakpointListener(sizeStrategy);

            int count = 0;

            service.BreakpointChanged += (s, e) =>
            {
                count++;
            };

            sizeStrategy.RaiseSizeChanged(10);

            await Task.Delay(3000);

            service.AddBreakpoint(0);

            Assert.AreEqual(1, count);
        }
        public void ActiveChange()
        {
            var sizeStrategy = new MySizeStrategy();
            var service      = new BreakpointListener(sizeStrategy);

            var breakpoints = new List <double> {
                0, 100, 200, 300
            };

            Assert.AreEqual(-1, service.CurrentBreakpoint);

            sizeStrategy.RaiseSizeChanged(10);

            Assert.AreEqual(-1, service.CurrentBreakpoint);
            Assert.AreEqual(10, service.CurrentWidth);

            service.AddBreakpoint(0);
            service.AddBreakpoint(100);
            service.AddBreakpoint(200);
            service.AddBreakpoint(300);

            sizeStrategy.RaiseSizeChanged(10);

            Assert.AreEqual(0, service.CurrentBreakpoint);
            Assert.AreEqual(10, service.CurrentWidth);

            sizeStrategy.RaiseSizeChanged(150);

            Assert.AreEqual(100, service.CurrentBreakpoint);
            Assert.AreEqual(150, service.CurrentWidth);

            sizeStrategy.RaiseSizeChanged(250);

            Assert.AreEqual(200, service.CurrentBreakpoint);
            Assert.AreEqual(250, service.CurrentWidth);

            sizeStrategy.RaiseSizeChanged(350);

            Assert.AreEqual(300, service.CurrentBreakpoint);
            Assert.AreEqual(350, service.CurrentWidth);
        }
Esempio n. 9
0
        public async Task TestLoadFromFile()
        {
            var sizeStrategy = new MySizeStrategy();
            var control      = new BreakpointBinder(sizeStrategy);
            await control.LoadFromJsonFileAsync("Common/bind.json");

            Assert.AreEqual(3, control.BindingsByWidth.Count);

            var result = control.TryGetActive(100);

            Assert.AreEqual("20", result["TitleFontSize"]);
            Assert.AreEqual("red", result["TitleColor"]);

            result = control.TryGetActive(600);
            Assert.AreEqual("50", result["TitleFontSize"]);
            Assert.AreEqual("blue", result["TitleColor"]);

            result = control.TryGetActive(1200);
            Assert.AreEqual("100", result["TitleFontSize"]);
            Assert.AreEqual("green", result["TitleColor"]);
        }
Esempio n. 10
0
        public async Task RaiseBreakpointBinderChanged_DeferredOnSubscribe()
        {
            var sizeStrategy = new MySizeStrategy();
            var control      = new BreakpointBinder(sizeStrategy);

            int count = 0;

            control.AddBreakpointWithBindings(0, AdaptiveContainer.Create().Set("TitleFontSize", "20").Set("TitleColor", "red").Get());

            sizeStrategy.RaiseSizeChanged(10);

            await Task.Delay(3000);

            control.ActiveChanged += (s, e) =>
            {
                count++;
            };


            Assert.AreEqual(1, count);
        }
Esempio n. 11
0
        public void TestWithAdd()
        {
            var sizeStrategy = new MySizeStrategy();
            var control      = new BreakpointBinder(sizeStrategy);

            control.AddBreakpointWithBindings(0, AdaptiveContainer.Create().Set("TitleFontSize", "20").Set("TitleColor", "red").Get())
            .AddBreakpointWithBindings(500, AdaptiveContainer.Create().Set("TitleFontSize", "50").Set("TitleColor", "blue").Get())
            .AddBreakpointWithBindings(1000, AdaptiveContainer.Create().Set("TitleFontSize", "100").Set("TitleColor", "green").Get());

            Assert.AreEqual(3, control.BindingsByWidth.Count);

            var result = control.TryGetActive(100);

            Assert.AreEqual("20", result["TitleFontSize"]);
            Assert.AreEqual("red", result["TitleColor"]);

            result = control.TryGetActive(600);
            Assert.AreEqual("50", result["TitleFontSize"]);
            Assert.AreEqual("blue", result["TitleColor"]);

            result = control.TryGetActive(1200);
            Assert.AreEqual("100", result["TitleFontSize"]);
            Assert.AreEqual("green", result["TitleColor"]);
        }