Ejemplo n.º 1
0
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddControllersWithViews().AddNewtonsoftJson();

            // We only need one instance for the business rules.
            services.AddSingleton <IBusinessRules>(br => {
                var config = new RoiBusinessRules();
                // We are using the Options Pattern (https://docs.microsoft.com/en-us/aspnet/core/fundamentals/configuration/options?view=aspnetcore-3.1)
                Configuration.GetSection(RoiBusinessRules.RoiConfiguration).Bind(config);

                return(config);
            });

            services.AddSingleton <IExchangeRatesProvider, ExchangeRateServiceClient.ExchangeRateServiceClient>();

            services.AddScoped <ICurrencyConverter, CurrencyConverter>();
            services.AddScoped <IRoiCalculator, RoiCalculator>();


            // In production, the React files will be served from this directory
            services.AddSpaStaticFiles(configuration =>
            {
                configuration.RootPath = "ReactApp/build";
            });
        }
        public static IBusinessRules GetTestBusinessRules()
        {
            var businessRules = new RoiBusinessRules()
            {
                BaseCurrency = TestConstants.BaseCurrency, BaseFee = TestConstants.BaseFee, TargetCurrency = TestConstants.TargetCurrency
            };
            var houseMarketReturnTiers = new List <InvestmentOptionRule>()
            {
                new InvestmentOptionRule()
                {
                    From = 0,
                    To   = 0.5,
                    Roi  = 0.1, // 10%
                    Fee  = 0.1
                },
                new InvestmentOptionRule()
                {
                    From = 0.5,
                    To   = 1,
                    Roi  = 0.20, // 20%
                    Fee  = 0
                }
            };
            var cashDepositReturnTiers = new List <InvestmentOptionRule>()
            {
                new InvestmentOptionRule()
                {
                    From = 0,
                    To   = 1,
                    Roi  = 0.025, // 2.5%
                    Fee  = 0.01   // 1% of ROI
                }
            };

            var investmentOptions = new List <InvestmentOption>()
            {
                new InvestmentOption()
                {
                    Id    = 1,
                    Name  = "House market",
                    Rules = houseMarketReturnTiers
                },
                new InvestmentOption()
                {
                    Id    = 2,
                    Name  = "Cash deposits",
                    Rules = cashDepositReturnTiers
                },
            };

            businessRules.InvestmentBusinessRules = investmentOptions;

            return(businessRules);
        }