public void GetTax_WhenBothAmountAndLowerBoundAreZero_ReturnZero()
        {
            var taxBand = TaxBand.Create(20, "band1");
            var tax     = taxBand.GetTax(0, 0);

            tax.Should().Be(0);
        }
        public void GetTax_WhenUpperBoundIsNull_ReturnsProductOfRateAndDifferenceOfAmountAndLowerBound()
        {
            var taxBand = TaxBand.Create(20, "band1");
            var tax     = taxBand.GetTax(2000m, 10000m);

            tax.Should().Be((10000m - 2000) * (20 / 100m));
        }
        public void GetTax_WhenLowerBoundLargerThanAmount_ReturnZero(decimal lowerBound, decimal amount)
        {
            var taxBand = TaxBand.Create(20, "band1", 10000);
            var tax     = taxBand.GetTax(lowerBound, amount);

            tax.Should().Be(0);
        }
        public void GetTax_WhenAmountLargerThanUpperBound_ReturnsProductOfRateAndDifferenceOfUpperBoundAndLowerBound()
        {
            var taxBand = TaxBand.Create(20, "band1", 10000);
            var tax     = taxBand.GetTax(2000, 12000);

            tax.Should().Be((10000m - 2000) * (20 / 100m));
        }
        public void GetTax_WhenAmountLessThanOrEqualToUpperBound_ReturnsProductOfRateAndDifferenceOfAmountAndLowerBound(decimal amount)
        {
            var taxBand = TaxBand.Create(20, "band1", 10000);
            var tax     = taxBand.GetTax(2000, amount);

            tax.Should().Be((amount - 2000) * (20 / 100m));
        }
        public void CompareTo_Test(decimal?upperBound1, decimal?upperBound2, int expectedResult)
        {
            var taxBand1 = TaxBand.Create(20, "band1", upperBound1);
            var taxBand2 = TaxBand.Create(20, "band2", upperBound2);

            var result = taxBand1.CompareTo(taxBand2);

            result.Should().Be(expectedResult);
        }
Exemple #7
0
        public void IntegrationTest_WithMockProvider()
        {
            (var taxBandProviderMock, _, _) = GetMocks();

            var band1 = TaxBand.Create(0, "band1", 12_500m);
            var band2 = TaxBand.Create(20, "band2", 50_000m);
            var band3 = TaxBand.Create(40, "band3", 150_000m);
            var band4 = TaxBand.Create(45, "band4");

            var taxBands = new List <TaxBand>()
            {
                band1, band2, band3, band4
            };

            taxBandProviderMock.Setup(x => x.GetAll()).Returns(taxBands);

            var service = new CalculateTaxService(taxBandProviderMock.Object, new TaxBandHelper());

            (var tax, _) = service.GetTax(52_000m);

            tax.Should().Be(8_300m);
        }
        public void GetTax_WhenLowerBoundLessThanZero_ThrowError()
        {
            var taxBand = TaxBand.Create(20, "band1");

            taxBand.Invoking(x => x.GetTax(-1m, 1m)).Should().Throw <InvalidOperationException>();
        }