Example #1
0
        public void KeyPositionEnumeratorWorksAsExpected()
        {
            var r1   = new Rectangle(4, 6, 4, 8);
            var r2   = new Rectangle(4, 6, 3, 7);
            var r3   = new Rectangle(4, 6, 2, 6);
            var r4   = new Rectangle(4, 6, 1, 5);
            var keys = new Rectangle[] { r1, r2, r3, r4 };

            var collection = new KeyPositionCollection(keys);

            collection.SequenceEqual(keys).Should().BeTrue();

            for (var i = 0; i < keys.Length; i++)
            {
                collection[i].Should().BeEquivalentTo(keys[i]);
            }

            var cnt = 0;

            foreach (var element in (IEnumerable)collection)
            {
                element.Should().BeEquivalentTo(keys[cnt]);
                cnt++;
            }
        }
Example #2
0
        public void SetKeys_Calls_SetForEveryKey()
        {
            var mock = new Mock <IMacroBoard>();
            var key  = KeyBitmap.Create.FromRgb(1, 2, 3);

            //use a number of keys that can't be ordered into a square
            //to catch hard coded values for stream deck (+mini)
            var keyCnt        = 37;
            var keyCollection = new KeyPositionCollection(Enumerable.Range(0, keyCnt).Select(i => new Rectangle(0, 0, 1, 1)));
            var keySetCalled  = new int[keyCnt];

            mock.Setup(d => d.Keys).Returns(keyCollection);
            mock.Setup(d =>
                       d.SetKeyBitmap(
                           It.IsInRange <int>(0, keyCnt - 1, Range.Inclusive),
                           It.Is <KeyBitmap>(k => ReferenceEquals(key, k))
                           )
                       )
            .Callback <int, KeyBitmap>((i, bmp) =>
            {
                keySetCalled[i]++;
            });

            var deck = mock.Object;

            deck.SetKeyBitmap(key);

            for (var i = 0; i < keyCnt; i++)
            {
                keySetCalled[i].Should().Be(1, "because all keys should be called exactly once");
            }
        }
        public void SimpleLayoutProducesExcpectedResults()
        {
            //creates a key layout with 2x2 = 4 keys, each 10x10px with 5px in between
            var keys = new KeyPositionCollection(2, 2, 20, 30, 5, 10);

            keys.Count.Should().Be(4);
            keys.Area.Left.Should().Be(0);
            keys.Area.Top.Should().Be(0);
            keys.Area.Width.Should().Be(45, $"because 2 keys each 20px wide and a gap of 5px");
            keys.Area.Height.Should().Be(70, $"because 2 keys each 30px high and a gap of 10px");
        }
Example #4
0
        public void KeyPositionCtorThrowsIfLeftOrTopIsNegative()
        {
            var r1 = new Rectangle(-1, 0, 10, 20);
            var r2 = new Rectangle(5, -5, 20, 10);

            var construct = new Action(() =>
            {
                var collection = new KeyPositionCollection(new Rectangle[] { r1, r2 });
            });

            construct.Should().Throw <ArgumentException>();
        }
Example #5
0
        public void KeyPositionCtorThrowsIfHeightOrWidthLessThanOne()
        {
            var r1 = new Rectangle(4, 4, -5, 10);
            var r2 = new Rectangle(4, 4, 10, -5);

            var construct = new Action(() =>
            {
                var collection = new KeyPositionCollection(new Rectangle[] { r1, r2 });
            });

            construct.Should().Throw <ArgumentException>();
        }
Example #6
0
        public void KeyPositionCtorWithAreaZeroThrowsException()
        {
            var r1 = new Rectangle(4, 4, 0, 5);
            var r2 = new Rectangle(4, 4, 5, 0);

            var construct = new Action(() =>
            {
                var collection = new KeyPositionCollection(new Rectangle[] { r1, r2 });
            });

            construct.Should().Throw <ArgumentException>();
        }
Example #7
0
        public void ClearKeysShouldCallSetForCorrespondingKeys()
        {
            var mock = new Mock <IMacroBoard>();

            //use a number of keys that can't be ordered into a square
            //to catch hard coded values for stream deck (+mini)
            var keyCnt        = 37;
            var keyCollection = new KeyPositionCollection(Enumerable.Range(0, keyCnt).Select(i => new Rectangle(0, 0, 1, 1)));
            var keySetCalled  = new int[keyCnt];

            mock.Setup(d => d.Keys).Returns(keyCollection);
            mock.Setup(d =>
                       d.SetKeyBitmap(
                           It.IsInRange <int>(0, keyCnt - 1, Range.Inclusive),
                           It.Is <KeyBitmap>(k => KeyBitmap.Black.Equals(k))
                           )
                       )
            .Callback <int, KeyBitmap>((i, bmp) =>
            {
                keySetCalled[i]++;
            });

            var keyToClear = 7;
            var deck       = mock.Object;

            deck.ClearKey(keyToClear);

            for (var i = 0; i < keyCnt; i++)
            {
                if (i == keyToClear)
                {
                    keySetCalled[i].Should().Be(1, $"because the cleared key {i} should be called once.");
                }
                else
                {
                    keySetCalled[i].Should().Be(0, $"because key {i} was not cleared.");
                }
            }


            keySetCalled[keyToClear] = 0;
            deck.ClearKeys();

            for (var i = 0; i < keyCnt; i++)
            {
                keySetCalled[i].Should().Be(1, $"because the cleared key {i} should be called once.");
            }
        }
Example #8
0
 static StreamDeckMiniHardwareInfo()
 {
     //3x2 keys with 80x80px icons and 25px in between
     keyPositions = new KeyPositionCollection(3, 2, imgWidth, 25);
 }
 static StreamDeckHardwareInfo()
 {
     //3x2 keys with 72x72px icons and 25px in between
     keyPositions = new KeyPositionCollection(5, 3, ImgWidth, 25);
 }