public IList <Product> GetAll()
        {
            //  Calculation model: base costs per month 5 € + consumption costs 22 cent/kWh
            //  Examples:
            //  • Consumption = 3500 kWh / year => Annual costs = 830 €/ year(5€ *12 months = 60 € base
            //    costs + 3500 kWh / year * 22 cent / kWh = 770 € consumption costs)
            //  • Consumption = 4500 kWh / year => Annual costs = 1050 €/ year(5€ *12 months = 60 € base
            //    costs + 4500 kWh / year * 22 cent / kWh = 990 € consumption costs)
            //  • Consumption = 6000 kWh / year => Annual costs = 1380 €/ year(5€ *12 months = 60 € base
            //    costs + 6000 kWh / year * 22 cent / kWh = 1320 € consumption costs)
            var modelBasic = new CalculationModelBasicElectricityTariff(22, 5);
            var productA   = new Product("Basic electricity tariff", modelBasic);


            //  Calculation model: 800 € for up to 4000 kWh / year and above 4000 kWh / year additionally 30 cent / kWh.
            //  Examples:
            //  • Consumption = 3500 kWh / year => Annual costs = 800 €/ year
            //  • Consumption = 4500 kWh / year => Annual costs = 950 €/ year(800€ +500 kWh * 30 cent / kWh
            //    = 150 € additional consumption costs)
            //  • Consumption = 6000 kWh / year => Annual costs = 1400 €/ year(800€ +2000 kWh * 30
            //    cent / kWh = 600 € additional consumption costs)
            var modelPackaged = new CalculationModelPackagedTariff(30, 800, 4000);
            var productB      = new Product("Packaged tariff", modelPackaged);

            return(new List <Product> {
                productA, productB
            });
        }
        public void ShouldReturnSuccessWhenCalculationModelIsNotNull()
        {
            var model   = new CalculationModelPackagedTariff(30, 800, 4000);
            var product = new Product("Packaged tariff", model);

            Assert.IsTrue(product.Valid);
        }
示例#3
0
        public void ShouldReturnSuccessWhenBasicCostsPerYearIsValid(int basicCostsPerYear)
        {
            var basicCostsPerYearDec = (decimal)basicCostsPerYear;
            var model = new CalculationModelPackagedTariff(30, basicCostsPerYearDec, 4000);

            Assert.IsTrue(model.Valid);
        }
示例#4
0
        public ICommandResult Handle(CreatePackagedTariffProductCommand command)
        {
            if (Invalid)
            {
                AddNotifications(command);
                return(new CommandResult(false, "An error occurred, It was not possible to create the product."));
            }

            command.Validate();
            if (command.Invalid)
            {
                AddNotifications(command);
                return(new CommandResult(false, "Please inform all the fields"));
            }

            // Creating new product
            var model   = new CalculationModelPackagedTariff(command.CentkWh, command.BasicCostsPerYear, command.BasicConsumption);
            var product = new Product(command.Name, model);

            // Adding notifications
            AddNotifications(model);
            AddNotifications(product);

            // Verifying if is valid
            if (Invalid)
            {
                AddNotifications(command);
                return(new CommandResult(false, "An error occurred, It was not possible to create the product."));
            }

            // Saving
            _repository.Save(product);

            // Retornar o resultado positivo
            return(new CommandResult(true, "Product successfuly created."));
        }
示例#5
0
        public void ShouldReturnSuccessWhenBasicConsumptionIsValid(int basicConsumption)
        {
            var model = new CalculationModelPackagedTariff(30, 800, basicConsumption);

            Assert.IsTrue(model.Valid);
        }