protected void ValidatePosition(InvoicePosition position) { if (string.IsNullOrWhiteSpace(position.Name)) { throw new MissingPositionNameException(); } if (position.NetValue <= 0) { throw new PositionNetValueMustBePositiveException(); } if (position.GrossValue <= 0) { throw new PositionGrossValueMustBePositiveException(); } if (position.VatRate >= 0 && position.VatRate < 1) { throw new WrongVatRateException(position.VatRate); } var grossValue = VatValueCalculator.CalculateGrossValue(position.NetValue, position.VatRate); if (position.GrossValue != grossValue) { throw new WrongPositionGrossValueException(position.NetValue, position.VatRate, position.GrossValue); } }
public void should_calculate_proper_value() { const decimal netValue = 15; const decimal vatRate = 0.23m; var expectedValue = 18.45M; var calculatedValue = VatValueCalculator.CalculateGrossValue(netValue, vatRate); Assert.AreEqual(expectedValue, calculatedValue); }
public void calculates_proper_value_for_23_percent() { var expectedValue = 18.45M; const decimal vatRate = 0.23M; // Arrange decimal netValue = 15; // Act var calculatedValue = VatValueCalculator.CalculateGrossValue(netValue, vatRate); // Assert Assert.That(expectedValue, Is.Not.EqualTo(calculatedValue)); }