Пример #1
0
        public void Setup()
        {
            var configDictionary = new Dictionary <string, string>
            {
                { "SqlConnectionString", "Server=localhost,1433;Database=Taxation;User Id=TaxUser;Password=TaxP@ss18013" },
                { "FlatValueTax:FlatValue", "10000.0" },
                { "FlatValueTax:MinAnnualIncome", "200000.0" },
                { "FlatValueTax:Rate", "5.0" },
                { "FlatRate", "17.5" }
            };

            var services = new ServiceCollection();

            services.AddLogging();

            IConfiguration configuration = new ConfigurationBuilder()
                                           .AddInMemoryCollection(configDictionary)
                                           .Build();

            services.Configure <Config>(configuration);
            services.AddScoped <IProgressiveTaxRateRepository, ProgressiveTaxRateRepository>();
            var taxCalculation = new TaxCalculationFactory().Create(services);

            services.AddTransient <ITaxCalculation>(x => taxCalculation);
            services.AddScoped <IPostalCodeTaxRepository, PostalCodeTaxRepository>();
            services.AddScoped <ITaxCalculationRepository, TaxCalculationRepository>();
            services.AddScoped <ITaxCalculationService, TaxCalculationService>();
            var serviceProvider = services.BuildServiceProvider();

            var taxCalculationService = serviceProvider.GetService <ITaxCalculationService>();

            _calculateTaxController = new CalculateTaxController(taxCalculationService);
        }
Пример #2
0
        /// <summary>
        /// This method gets called by the runtime and used to add services to the container.
        /// </summary>
        /// <param name="services">IServiceCollection that secifies the contract for a collection of service descriptors.</param>
        public void ConfigureServices(IServiceCollection services)
        {
            // service registration for DI
            services.Configure <Config>(Configuration);
            services.AddScoped <IProgressiveTaxRateRepository, ProgressiveTaxRateRepository>();
            var taxCalculation = new TaxCalculationFactory().Create(services);

            services.AddTransient <ITaxCalculation>(x => taxCalculation);
            services.AddScoped <IPostalCodeTaxRepository, PostalCodeTaxRepository>();
            services.AddScoped <ITaxCalculationRepository, TaxCalculationRepository>();
            services.AddScoped <ITaxCalculationService, TaxCalculationService>();

            services.AddControllers();
            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new OpenApiInfo {
                    Title = "Campbelltech.TaxCalculation.Api", Version = "v1"
                });

                // set the comments path for the Swagger JSON and UI.
                var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";
                var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile);
                c.IncludeXmlComments(xmlPath);
            });
        }