コード例 #1
0
        public void DataPicker_GetNumericValue_ShouldThrowException_IfMinimumLimitIsGreaterThanMaximumLimit()
        {
            // Assert
            Assert.Throws <ArgumentException>(() =>
            {
                // Arrange
                var dummyKeyboard = Mock.Of <IPinpadKeyboard>();
                var dummyInfos    = Mock.Of <IPinpadInfos>();
                var dummyDisplay  = Mock.Of <IPinpadDisplay>();

                IDataPicker picker = new DataPicker(
                    dummyKeyboard,
                    dummyInfos,
                    dummyDisplay);

                short invalidMaxLimit = 1;
                short invalidMinLimit = (short)(invalidMaxLimit + 1);

                // Act
                picker.GetNumericValue(
                    label: "testLabel",
                    circularBehavior: false,
                    minimunLimit: invalidMinLimit,
                    maximumLimit: invalidMaxLimit);
            });
        }
コード例 #2
0
        public void DataPicker_GetNumericValue_ShouldReturnNull_IfCancelIsPressed()
        {
            // Arrange
            var displayStub = new Mock <IPinpadDisplay>();

            displayStub.Setup(x => x.ShowMessage("label",
                                                 string.Empty,
                                                 DisplayPaddingType.Center))
            .Returns(true);

            var keyboardStub = new Mock <IPinpadKeyboard>();

            keyboardStub.Setup(x => x.GetKey())
            .Returns(PinpadKeyCode.Cancel);

            var dummyInfos = Mock.Of <IPinpadInfos>();

            IDataPicker picker = new DataPicker(
                keyboardStub.Object,
                dummyInfos,
                displayStub.Object);

            // Act
            Nullable <short> readValue = picker.GetNumericValue(
                label: "label",
                circularBehavior: false,
                minimunLimit: 0,
                maximumLimit: 1);

            // Assert
            Assert.IsNull(readValue);
            Assert.IsFalse(readValue.HasValue);
        }
コード例 #3
0
        public void DataPicker_GetNumericValue_ShouldThrowException_IfLabelIsNull()
        {
            // Assert
            Assert.Throws <ArgumentException>(() =>
            {
                // Arrange
                var dummyKeyboard = Mock.Of <IPinpadKeyboard>();
                var dummyInfos    = Mock.Of <IPinpadInfos>();
                var dummyDisplay  = Mock.Of <IPinpadDisplay>();

                IDataPicker picker = new DataPicker(
                    dummyKeyboard,
                    dummyInfos,
                    dummyDisplay);

                string nullLabel = null;

                // Act
                picker.GetNumericValue(
                    label: nullLabel,
                    circularBehavior: false,
                    minimunLimit: 0,
                    maximumLimit: 1);
            });
        }
コード例 #4
0
        public void DataPicker_GetNumericValue_ShouldReturnAValue_WhenReturnKeyIsPressed()
        {
            // Arrange
            var displayStub = new Mock <IPinpadDisplay>();

            displayStub.Setup(x => x.ShowMessage("label",
                                                 string.Empty,
                                                 DisplayPaddingType.Center))
            .Returns(true);

            var keyboardStub = new Mock <IPinpadKeyboard>();

            keyboardStub.Setup(x => x.GetKey())
            .Returns(PinpadKeyCode.Return);

            var dummyInfos = Mock.Of <IPinpadInfos>();

            IDataPicker picker = new DataPicker(
                keyboardStub.Object,
                dummyInfos,
                displayStub.Object);

            Random itemsProvider    = new Random();
            short  expectedMinLimit = (short)itemsProvider.Next(400);
            short  expectedMaxLimit = (short)itemsProvider.Next(
                expectedMinLimit,
                expectedMinLimit + 400);

            // Act
            Nullable <short> readValue = picker.GetNumericValue(
                label: "testLabel",
                circularBehavior: false,
                minimunLimit: expectedMinLimit,
                maximumLimit: expectedMaxLimit);

            // Assert
            Assert.IsNotNull(readValue);
            Assert.IsTrue(readValue.HasValue);
            Assert.AreEqual(expectedMinLimit, readValue.Value);
        }