Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
0
        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]);
        }
Ejemplo n.º 4
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"]);
        }
Ejemplo n.º 5
0
        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);
        }
Ejemplo n.º 6
0
        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);
        }
Ejemplo n.º 7
0
        public void 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);

            Task.Delay(3000);

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


            Assert.AreEqual(1, count);
        }
Ejemplo n.º 8
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"]);
        }