예제 #1
0
        public void CalculateNetSalary_ShouldReturnNetSalaryWithIncomeTaxAndMaxSocialContributionsTax_IfGrossSalaryIsAboveMaxGrossSalary()
        {
            //Arrange
            double grossSalaryAboveMax = GlobalConstants.MaxGrossSalaryForSocialContributions + 1;

            double incomeTax = (grossSalaryAboveMax - GlobalConstants.MinGrossSalary) * GlobalConstants.IncomeTaxPercent / 100;
            var    mockedIncomeTaxCalculator = new Mock <IIncomeTaxCalculator>();

            mockedIncomeTaxCalculator.Setup(x => x.CalculateIncomeTax(grossSalaryAboveMax)).Returns(incomeTax);

            double socialContributions = (GlobalConstants.MaxGrossSalaryForSocialContributions - GlobalConstants.MinGrossSalary) * GlobalConstants.SocialContributionsPercent / 100;
            var    mockedSocialContributionsCalculator = new Mock <ISocialContributionsCalculator>();

            mockedSocialContributionsCalculator.Setup(x => x.CalculateSocialContributions(grossSalaryAboveMax)).Returns(socialContributions);

            NetSalaryCalculator netSalaryCalculator = new NetSalaryCalculator(mockedIncomeTaxCalculator.Object, mockedSocialContributionsCalculator.Object);

            double expectedNetSalary = grossSalaryAboveMax - incomeTax - socialContributions;

            //Action
            double resultNetSalary = netSalaryCalculator.CalculateNetSalary(grossSalaryAboveMax);

            //Assert
            Assert.AreEqual(expectedNetSalary, resultNetSalary, $"Result net salary is not equal to {expectedNetSalary}");
        }
예제 #2
0
        static void Main(string[] args)
        {
            decimal grossSalary = 0m;

            Console.WriteLine("Please input gross salary. Gross salary should be number between 0 to {0}", decimal.MaxValue);
            string userInput = Console.ReadLine();

            while (!decimal.TryParse(userInput, out grossSalary) || grossSalary < 0)
            {
                Console.WriteLine("Please input valid gross salary. Valid gross salary should be number between 0 to {0}", decimal.MaxValue);
                userInput = Console.ReadLine();
            }

            const decimal belowTaxSalaryLevel                 = 1000;
            const decimal higherSalaryLevel                   = 3000;
            const int     percentOfIncomeTaxation             = 10;
            const int     percentOfSocialContributionTaxation = 15;

            var rules = new ITaxationRule[]
            {
                new IncomeTaxationRule(belowTaxSalaryLevel, percentOfIncomeTaxation),
                new SocialContributionTaxationRule(belowTaxSalaryLevel, higherSalaryLevel, percentOfSocialContributionTaxation)
            };

            NetSalaryCalculator salaryCalculator = new NetSalaryCalculator(rules);
            var netSalary = salaryCalculator.CalculateNetSalary(grossSalary);

            Console.WriteLine("Net salary after taxes is {0}", netSalary);
        }
예제 #3
0
        public void SalaryAfterCalculationShouldBeTheSame()
        {
            var grossSalary = 2000;

            NetSalaryCalculator salaryCalculator = new NetSalaryCalculator();
            var calculatedSalary = salaryCalculator.CalculateNetSalary(grossSalary);

            Assert.AreEqual(grossSalary, calculatedSalary);
        }
예제 #4
0
        public void ForNegativeSalaryShouldThrowArgumentException()
        {
            var grossSalary = -100;

            NetSalaryCalculator salaryCalculator = new NetSalaryCalculator();

            Assert.Catch <ArgumentException>(() =>
            {
                salaryCalculator.CalculateNetSalary(grossSalary);
            });
        }
예제 #5
0
        public void SalaryAfterCalculationShouldBeTenPercentLower()
        {
            var grossSalary = 2000;

            NetSalaryCalculator salaryCalculator = new NetSalaryCalculator(new MockTaxationRule());
            var calculatedSalary = salaryCalculator.CalculateNetSalary(grossSalary);

            decimal expectedSalary = 1800m;

            Assert.AreEqual(expectedSalary, calculatedSalary);
        }
        static void Main(string[] args)
        {
            INetSalaryCalculator netSalaryCalculator = new NetSalaryCalculator();

            Console.Write("Input gross salary: ");
            double grossSalary = double.Parse(Console.ReadLine());

            double netSalary = netSalaryCalculator.CalculateNetSalary(grossSalary);

            Console.WriteLine($"Net salary: {netSalary}");
        }
예제 #7
0
        public void CalculateNetSalary_ShouldThrowArgumentException_IfGrossSalaryIsNegative()
        {
            //Arrange
            double grossSalaryNegative = -1;

            var mockedIncomeTaxCalculator           = new Mock <IIncomeTaxCalculator>();
            var mockedSocialContributionsCalculator = new Mock <ISocialContributionsCalculator>();

            NetSalaryCalculator netSalaryCalculator = new NetSalaryCalculator(mockedIncomeTaxCalculator.Object, mockedSocialContributionsCalculator.Object);

            //Action
            var exception = Assert.Throws <ArgumentException>(() => netSalaryCalculator.CalculateNetSalary(grossSalaryNegative));

            //Assert
            Assert.That(exception.Message, Is.EqualTo(GlobalConstants.NegativeGrossSalaryMessage));
        }
예제 #8
0
        public void CalculateNetSalary_ShouldReturnGrossSalary_IfIncomeTaxIs0AndSocialContributionsIs0()
        {
            //Arrange
            double grossSalaryBelowMin = GlobalConstants.MinGrossSalary - 1;

            var mockedIncomeTaxCalculator = new Mock <IIncomeTaxCalculator>();

            mockedIncomeTaxCalculator.Setup(x => x.CalculateIncomeTax(grossSalaryBelowMin)).Returns(0);

            var mockedSocialContributionsCalculator = new Mock <ISocialContributionsCalculator>();

            mockedSocialContributionsCalculator.Setup(x => x.CalculateSocialContributions(grossSalaryBelowMin)).Returns(0);

            NetSalaryCalculator netSalaryCalculator = new NetSalaryCalculator(mockedIncomeTaxCalculator.Object, mockedSocialContributionsCalculator.Object);

            //Action
            double resultNetSalary = netSalaryCalculator.CalculateNetSalary(grossSalaryBelowMin);

            //Assert
            Assert.AreEqual(grossSalaryBelowMin, resultNetSalary, $"Result net salary is not equal to {grossSalaryBelowMin}");
        }