public static void DisplayResult()
        {
            try
            {
                if (Input == null)
                {
                    throw new ArgumentNullException();
                }

                int _decimal;
                int.TryParse(Input, out _decimal);

                if (_decimal != 0)
                {
                    DecimalModel decimalModel = new DecimalModel();

                    if (decimalModel != null)
                    {
                        decimalModel.Decimal = _decimal;
                        decimalModel.DisplayResult();
                        LogModel.InputLog.Add($"{_decimal} was converted to {decimalModel.ConvertedNumeral}");
                    }
                }
                else
                {
                    RomanModel romanModel = new RomanModel();

                    if (romanModel != null)
                    {
                        romanModel.Numeral = Input;
                        if (romanModel.Numeral != null)
                        {
                            romanModel.DisplayResult();
                            LogModel.InputLog.Add($"{Input.ToUpper()} was converted to {romanModel.ConvertedDecimal}");
                        }
                    }
                }
            }

            catch (ArgumentException e)
            {
                MessageBox.Show("Invalid input");
            }
        }
        public void Extract_Decimal_EmptyString_ShouldMapToDecimalZero()
        {
            // Assert
            uint         stringLength = 0;
            RfcErrorInfo errorInfo;

            _interopMock.Setup(x => x.GetString(It.IsAny <IntPtr>(), It.IsAny <string>(), It.IsAny <char[]>(), It.IsAny <uint>(), out stringLength, out errorInfo));

            // Act
            DecimalModel result = OutputMapper.Extract <DecimalModel>(_interopMock.Object, DataHandle);

            // Assert
            uint discard;

            _interopMock.Verify(
                x => x.GetString(DataHandle, "DECIMALVALUE", Array.Empty <char>(), 0, out discard, out errorInfo),
                Times.Once);
            result.Should().NotBeNull();
            result.DecimalValue.Should().Be(0M);
        }
Example #3
0
        public void Extract_Decimal_ShouldMapFromDecimalString(double val)
        {
            decimal value = (decimal)val;
            // Assert
            string       stringValue  = value.ToString("G", CultureInfo.InvariantCulture);
            uint         stringLength = (uint)stringValue.Length;
            RfcErrorInfo errorInfo;
            var          resultCodeQueue = new Queue <RfcResultCodes>();

            resultCodeQueue.Enqueue(RfcResultCodes.RFC_BUFFER_TOO_SMALL);
            resultCodeQueue.Enqueue(RfcResultCodes.RFC_OK);
            _interopMock
            .Setup(x => x.GetString(It.IsAny <IntPtr>(), It.IsAny <string>(), It.IsAny <char[]>(), It.IsAny <uint>(), out stringLength, out errorInfo))
            .Callback(new GetStringCallback((IntPtr dataHandle, string name, char[] buffer, uint bufferLength, out uint sl, out RfcErrorInfo ei) =>
            {
                ei = default;
                sl = stringLength;
                if (buffer.Length <= 0 || bufferLength <= 0)
                {
                    return;
                }
                Array.Copy(stringValue.ToCharArray(), buffer, stringValue.Length);
            }))
            .Returns(resultCodeQueue.Dequeue);

            // Act
            DecimalModel result = OutputMapper.Extract <DecimalModel>(_interopMock.Object, DataHandle);

            // Assert
            uint discard;

            _interopMock.Verify(
                x => x.GetString(DataHandle, "DECIMALVALUE", Array.Empty <char>(), 0, out discard, out errorInfo),
                Times.Once);
            _interopMock.Verify(
                x => x.GetString(DataHandle, "DECIMALVALUE", It.IsAny <char[]>(), stringLength + 1, out discard, out errorInfo),
                Times.Once);
            result.Should().NotBeNull();
            result.DecimalValue.Should().Be(value);
        }
Example #4
0
 public void StringToDecimal(DecimalModel sampleData)
 {
     Assert.Equal(sampleData.Expected, sampleData.Actual.ToDecimal());
 }