Esempio n. 1
0
        public void ShouldValidateWhenLowerRangeIsZero()
        {
            _optionsMonitorMock.Setup(o => o.CurrentValue).Returns(new AppSettings()
            {
                MaximumDonationAmount = "100000"
            });

            var amountValidationResult = AmountValidator.ValidateAmount(_optionsMonitorMock.Object, 5);

            Assert.AreEqual(ValidationResult.Success, amountValidationResult);
        }
Esempio n. 2
0
        public void ShouldReturnValidationErrorWhenAmountIsOutOfRangeButMaximumAmountIsNotDefined()
        {
            _optionsMonitorMock.Setup(o => o.CurrentValue).Returns(new AppSettings()
            {
                MinimumDonationAmount = "3"
            });

            var expectedValidationError = new ValidationResult("Donation amount can not be smaller than 3");

            var amountValidationResult = AmountValidator.ValidateAmount(_optionsMonitorMock.Object, 1);

            Assert.AreEqual(expectedValidationError.ErrorMessage, amountValidationResult.ErrorMessage);
        }
Esempio n. 3
0
        private ObjectResult ValidateOperation(decimal donationAmount)
        {
            var appSettingsValidationResult = AppSettingsValidator.ValidateAppSettings(_appSettings);

            if (appSettingsValidationResult.Count > 0)
            {
                return(StatusCode(500, new ValidationResult("Internal Server Error: Definition of one or more configuration settings of the application are invalid.")));
            }

            var requestValidationResult = AmountValidator.ValidateAmount(_appSettings, donationAmount);

            if (requestValidationResult != null)
            {
                return(StatusCode(400, requestValidationResult));
            }

            return(StatusCode(200, null));
        }