示例#1
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ProductsDBContext productsDBContext)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseHttpsRedirection();

            app.UseRouting();

            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });

            //to use caching
            app.UseResponseCaching();



            //  productsDBContext.Database.EnsureCreated();
            app.UseSwagger();
            app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "Api for Products"));
        }
示例#2
0
        public ProductsProvider(ProductsDBContext dbContext, ILogger <ProductsProvider> logger, IMapper mapper)
        {
            this.dbContext = dbContext;
            this.logger    = logger;
            this.mapper    = mapper;

            SeedData();
        }
示例#3
0
文件: Startup.cs 项目: jcrpg/coreAPI
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ProductsDBContext productDBContext)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            app.UseSwagger();
            app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "API for Prouct"));

            app.UseMvc();
            productDBContext.Database.EnsureCreated();
        }
 private void CreateProducts(ProductsDBContext dbContext)
 {
     for (int i = 1; i <= 10; i++)
     {
         dbContext.Products.Add(new Product()
         {
             Id        = i,
             Name      = Guid.NewGuid().ToString(),
             Inventory = i + 10,
             Price     = (decimal)(i * 3.14)
         });
     }
     dbContext.SaveChanges();
 }
        public ProductTests()
        {
            // Setup InMemory Database for Unit testing

            #region Setup

            ProductsDBContext context = GetContext();
            _mapperConfiguration = new MapperConfiguration(cfg => { cfg.AddProfile <ProductProfileMap>(); });
            _mapper = _mapperConfiguration.CreateMapper();
            SeedDatabase(context);
            ProductsRepository       productRepository        = new ProductsRepository(context);
            ProductOptionsRepository productOptionsRepository = new ProductOptionsRepository(context);
            _productController = new ProductsController(productRepository, productOptionsRepository, _mapper);

            #endregion
        }
        public async Task GetProductReturnsProductUsingInvalidId()
        {
            var options = new DbContextOptionsBuilder <ProductsDBContext>()
                          .UseInMemoryDatabase(nameof(GetProductReturnsProductUsingInvalidId))
                          .Options;
            var dbContext = new ProductsDBContext(options);

            CreateProducts(dbContext);

            var productProfile = new ProductProfile();
            var configuration  = new MapperConfiguration(cfg => cfg.AddProfile(productProfile));
            var mapper         = new Mapper(configuration);

            var productsProvider = new ProductsProvider(dbContext, null, mapper);

            var product = await productsProvider.GetProductAsync(-1);

            Assert.False(product.IsSuccess);
            Assert.Null(product.Product);
            Assert.NotNull(product.ErrorMessage);
        }
        /// <summary>
        /// Seed data In Memory database.
        /// </summary>
        /// <param name="productRepository">The product repository.</param>
        private void SeedDatabase(ProductsDBContext context)
        {
            // Add products
            context.Products.Add(new Products.Entity.Product {
                Id = 1, Name = "Samsung Galaxy S20", Description = "Latest smartphone from Samsung", Price = 1599.99M, DeliveryPrice = 9.99M
            });
            context.Products.Add(new Products.Entity.Product {
                Id = 2, Name = "Apple iPhone X", Description = "Latest smartphone from Apple", Price = 1999.99M, DeliveryPrice = 19.99M
            });
            context.Products.Add(new Products.Entity.Product {
                Id = 3, Name = "Samsung Galaxy S Fold", Description = "foldable smartphone from Samsung", Price = 1599.99M, DeliveryPrice = 9.99M
            });

            // Add Product Options
            context.ProductOptions.Add(new Products.Entity.ProductOption {
                Id = 1, ProductId = 1, Name = "128 GB Cosmic Gray", Description = "128 GB"
            });
            context.ProductOptions.Add(new Products.Entity.ProductOption {
                Id = 2, ProductId = 1, Name = "256 GB Blood Red", Description = "256 GB"
            });
            context.ProductOptions.Add(new Products.Entity.ProductOption {
                Id = 3, ProductId = 1, Name = "512 GB Cherry Pink", Description = "512 GB"
            });
            context.ProductOptions.Add(new Products.Entity.ProductOption {
                Id = 4, ProductId = 2, Name = "64 GB Black", Description = "64 GB"
            });
            context.ProductOptions.Add(new Products.Entity.ProductOption {
                Id = 5, ProductId = 2, Name = "512 GB Gray", Description = "512 GB Gray"
            });
            context.ProductOptions.Add(new Products.Entity.ProductOption {
                Id = 6, ProductId = 3, Name = "128 GB Gray", Description = "128 GB"
            });
            context.ProductOptions.Add(new Products.Entity.ProductOption {
                Id = 7, ProductId = 3, Name = "256 GB Red", Description = "256 GB"
            });

            context.SaveChanges();
        }
示例#8
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ProductsDBContext productsDbcontext)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
                app.UseHsts();
            }

            app.UseHttpsRedirection();
            app.UseSwagger();
            productsDbcontext.Database.EnsureCreated();

            app.UseSwaggerUI(setupAction =>
            {
                setupAction.SwaggerEndpoint("/swagger/LibraryOpenAPISpecification/swagger.json", "Library API");
                setupAction.RoutePrefix = "";
            });
            app.UseMvc();
        }
示例#9
0
 public ProductsController(ProductsDBContext productsDbContext, ILogger <ProductsController> logger)
 {
     _productsDbContext = productsDbContext;
     _logger            = logger;
 }
示例#10
0
 public OrderController(ProductsDBContext context)
 {
     _context = context;
 }
示例#11
0
 public ProductsRespository(ProductsDBContext productsDBContext)
 {
     _productsDBContext = productsDBContext;
 }
示例#12
0
 public OrderRepository(ProductsDBContext context)
 {
     this.context = context;
     Orders       = context.Order;
 }
示例#13
0
 public ProductsRepository(ProductsDBContext context)
 {
     _context = context;
 }
示例#14
0
 public MealRepository(ProductsDBContext dBContext)
 {
     this.dBContext = dBContext;
 }
示例#15
0
 public ProductDAL(IMapper mapper, ProductsDBContext context)
 {
     _context = context ?? throw new ArgumentNullException(nameof(context));
     _mapper  = mapper ?? throw new ArgumentNullException(nameof(mapper));
 }
 public ProductsController(ProductsDBContext ProductsDBContext)
 {
     productsDBContext = ProductsDBContext;
 }
 public ProductRepository(ProductsDBContext _productsDbContext)
 {
     productsDbContext = _productsDbContext;
 }
 public ProductRepository(ProductsDBContext productsDB)
 {
     productsDBContext = productsDB;
 }
示例#19
0
 public FoodRepository(ProductsDBContext dBContext)
 {
     this.dBContext = dBContext;
 }
示例#20
0
 public ProductsController(ProductsDBContext context)
 {
     _context = context;
 }
示例#21
0
 public ProductController()
 {
     db = new ProductsDBContext();
 }