public void ShouldSetLowerRangeToZeroWhenItsNotPresentInAppSettings() { _optionsMonitorMock.Setup(o => o.CurrentValue).Returns(new AppSettings() { MaximumDonationAmount = "2", }); decimal minimumDonationAmount; decimal maximumDonationAmount; AppSettingsUtils.GetLowerAndHigherRange(_optionsMonitorMock.Object, out minimumDonationAmount, out maximumDonationAmount); Assert.AreEqual(0, minimumDonationAmount); }
public void ShouldGetLowerAndHigherRange() { _optionsMonitorMock.Setup(o => o.CurrentValue).Returns(new AppSettings() { MinimumDonationAmount = "2", MaximumDonationAmount = "100000" }); decimal minimumDonationAmount; decimal maximumDonationAmount; AppSettingsUtils.GetLowerAndHigherRange(_optionsMonitorMock.Object, out minimumDonationAmount, out maximumDonationAmount); Assert.AreEqual(2, minimumDonationAmount); Assert.AreEqual(100000, maximumDonationAmount); }
public static ValidationResult ValidateAmount(IOptionsMonitor <AppSettings> settings, decimal amount) { decimal minimumDonationAmount; decimal maximumDonationAmount; AppSettingsUtils.GetLowerAndHigherRange(settings, out minimumDonationAmount, out maximumDonationAmount); var isLowerRangeValid = amount >= minimumDonationAmount; var largerRangeExists = maximumDonationAmount != 0; var isLargerRangeValid = !largerRangeExists ? true : amount <= maximumDonationAmount; if (isLowerRangeValid && isLargerRangeValid) { return(ValidationResult.Success); } return(new ValidationResult("Donation amount can not be smaller than " + minimumDonationAmount + (largerRangeExists ? (" and can not be larger than " + maximumDonationAmount) : ""))); }