Beispiel #1
0
        public UpdateProductTests()
        {
            _context = ProductCatalogContextFactory.Create();
            var mapper = MapperFactory.Create();

            _handler = new UpdateProductHandler(_context, mapper);
        }
 public ProductCategoriesRepository(
     ILoggerFactory loggerFactory,
     ProductCatalogContext dbContext)
 {
     _logger    = loggerFactory.GetLogger(this);
     _dbContext = dbContext;
 }
Beispiel #3
0
 List <PriceCatalog> IRepository <PriceCatalog> .GetById(string id)
 {
     using (var productContext = new ProductCatalogContext())
     {
         return(productContext.PricingCatalog.Where(x => x.productId == id).ToList());
     }
 }
Beispiel #4
0
        public static void SeedProductCatalogData(ProductCatalogContext context)
        {
            if (context.Products.Count() < 10)
            {
                var random = new Randomizer();

                var testProductCategories = new Faker <ProductCategory>("ar")
                                            .RuleFor(x => x.Id, x => Guid.NewGuid())
                                            .RuleFor(x => x.Created, x => DateTime.UtcNow)
                                            .RuleFor(x => x.CreatedBy, x => "Seeder")
                                            .RuleFor(x => x.Name, x => x.Company.CompanyName())
                                            .RuleFor(x => x.PhotoUrl, x => x.Image.PlaceholderUrl(200, 200, "Brimo Product Category", "#607d8b"));

                var testBrands = new Faker <Brand>("ar")
                                 .RuleFor(x => x.Id, x => Guid.NewGuid())
                                 .RuleFor(x => x.Created, x => DateTime.UtcNow)
                                 .RuleFor(x => x.CreatedBy, x => "Seeder")
                                 .RuleFor(x => x.Name, x => x.Commerce.Department())
                                 .RuleFor(x => x.PhotoUrl, x => x.Image.PlaceholderUrl(200, 200, "Brimo Brand", "#eeeeee"));

                var testUnits = new Faker <Unit>("ar")
                                .RuleFor(x => x.Id, x => Guid.NewGuid())
                                .RuleFor(x => x.Created, x => DateTime.UtcNow)
                                .RuleFor(x => x.CreatedBy, x => "Seeder")
                                .RuleFor(x => x.ContentCount, x => x.Random.Int(1, 2000))
                                .RuleFor(x => x.Count, x => x.Random.Int(1, 2000))
                                .RuleFor(x => x.IsAvailable, x => x.Random.Bool(0.7f))
                                .RuleFor(x => x.Price, x => x.Random.Float(10, 1000))
                                .RuleFor(x => x.SellingPrice, x => x.Random.Float(100, 10000))
                                .RuleFor(x => x.Weight, x => x.Random.Float(1, 200))
                                .RuleFor(x => x.Name, x => x.Company.CompanyName());

                var brands            = testBrands.Generate(100);
                var productCategories = testProductCategories.Generate(100);

                var testProducts = new Faker <Product>("ar")
                                   .RuleFor(x => x.Name, x => x.Commerce.ProductName())
                                   .RuleFor(x => x.Created, x => DateTime.UtcNow)
                                   .RuleFor(x => x.CreatedBy, x => "Seeder")
                                   .RuleFor(x => x.PhotoUrl, x => x.Image.PlaceholderUrl(200, 200, "Brimo Product", "#9e9e9e"))
                                   .RuleFor(x => x.AvailableToSell, x => x.Random.Bool(0.7f))
                                   .RuleFor(x => x.Barcode, x => x.Commerce.Ean13())
                                   .RuleFor(x => x.Units, x => testUnits.Generate(4))
                                   .RuleFor(x => x.Brand, x => random.ListItem(brands))
                                   .RuleFor(x => x.ProductCategory, x => random.ListItem(productCategories));

                var products = testProducts.Generate(2000);
                context.Products.AddRange(products);
                context.SaveChanges();
            }
        }
Beispiel #5
0
        public static ProductCatalogContext Create()
        {
            var options = new DbContextOptionsBuilder <ProductCatalogContext>()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString())
                          .Options;

            // Seed in-mem test database
            var context = new ProductCatalogContext(options);

            context.Database.EnsureCreated();
            context.Categories.AddRange(Fixture.Categories);
            context.Products.AddRange(Fixture.Products);
            context.SaveChanges();

            return(context);
        }
Beispiel #6
0
        public void ProductDbOperationsOperations()
        {
            DefaultServices.RegisterDefaultServices();
            ProductCatalogContext ctx = new ProductCatalogContext();
            var     result            = ctx.Product.Where(p => p.Code == "Product1").ToList();
            Product product1          = CommonTestData.GetTestData();
            var     addProductResult1 = ctx.Product.Add(product1);

            ctx.SaveChanges();
            var getProductResult1 = ctx.Product.Where(p => p.Code == product1.Code).ToList().FirstOrDefault();

            Assert.AreEqual(getProductResult1.Name, product1.Name);
            getProductResult1.Name = "ProductNameNew";
            ctx.Product.Update(getProductResult1);
            ctx.SaveChanges();
            var getProductResult2 = ctx.Product.Where(p => p.Code == product1.Code).ToList().FirstOrDefault();

            Assert.AreEqual(getProductResult2.Name, "ProductNameNew");
            ctx.Product.Remove(getProductResult2);
            ctx.SaveChanges();
            var finalProductResult = ctx.Product.Find(getProductResult2.Id);

            Assert.AreEqual(finalProductResult, null);
        }
 public ProductListDataRequestHandler(ProductCatalogContext catalog)
 {
     _context = catalog;
 }
Beispiel #8
0
 public static void Destroy(ProductCatalogContext context)
 {
     context.Database.EnsureDeleted();
     context.Dispose();
 }
 public GetAllQueryHandler(ProductCatalogContext context, IMapper mapper)
 {
     _context = context;
     _mapper  = mapper;
 }
 public GetByCodeQueryHandler(ProductCatalogContext context, ILogger <GetByCodeQueryHandler> logger)
 {
     _context = context;
     _logger  = logger;
 }
 public RegisterNewProductHandler(IMediator mediator, ProductCatalogContext db)
 {
     this.mediator = mediator;
     this.db       = db;
 }
Beispiel #12
0
 public AvailableProductsHandler(ProductCatalogContext db)
 {
     this.db = db;
 }
 public UpdateCategoryTests()
 {
     _context = ProductCatalogContextFactory.Create();
     _handler = new UpdateCategoryHandler(_context);
 }
Beispiel #14
0
 public ProductsController(ProductCatalogContext context, IHubContext <ProductHub> hubContext)
 {
     _context    = context;
     _hubContext = hubContext;
 }
Beispiel #15
0
 public DeleteCategoryHandler(ProductCatalogContext context)
 {
     _context = context;
 }
Beispiel #16
0
 public ProductCatalogController(ProductCatalogContext context, ILogger <ProductCatalogController> logger)
 {
     _logger  = logger;
     _context = context;
 }
Beispiel #17
0
 public ProductRepository(ProductCatalogContext context)
 {
     _context = context ?? throw new ArgumentNullException(nameof(context));
 }
Beispiel #18
0
 public GetAllQueryHandler(ProductCatalogContext context)
 {
     _context = context;
 }
 public ProductDeleteDataRequestHandler(ProductCatalogContext context)
 {
     _context = context;
 }
 public UnitOfWork(ProductCatalogContext context)
 {
     _context = context;
 }
Beispiel #21
0
 public ProductService(ProductCatalogContext context)
 {
     _context = context;
 }
Beispiel #22
0
 public ProductRepository(ProductCatalogContext productCatalogContext)
 {
     _productCatalogContext = productCatalogContext;
 }
Beispiel #23
0
 public UpdateProductHandler(ProductCatalogContext context, IMapper mapper)
 {
     _context = context;
     _mapper  = mapper;
 }
Beispiel #24
0
 public RepositoryBase(ProductCatalogContext context)
 {
     _context = context;
     _set     = context.Set <TEntity>();
 }
Beispiel #25
0
 protected RepositoryBase(ProductCatalogContext context)
 {
     ProductCatalogContext = context;
 }
Beispiel #26
0
 public BookRepository(bool isCachingEnabled, ProductCatalogContext context) : base(false, context)
 {
     _context = context;
 }
Beispiel #27
0
 public RepositoryWrapper(ProductCatalogContext context)
 {
     _productContext = context;
 }
 public DeleteProductHandler(ProductCatalogContext context)
 {
     _context = context;
 }
 public ProductCatalogController(ProductCatalogContext context)
 {
     _context = context;
 }
Beispiel #30
0
 public ProductService(IConfiguration config, ProductCatalogContext context)
 {
     _context = context;
 }