Пример #1
0
        /// <summary>
        /// Load your modules or register your services here!
        /// </summary>
        /// <param name="kernel">The kernel.</param>
        private static void RegisterServices(IKernel kernel)
        {
            kernel.Bind <ApplicationUserManager>().ToMethod(context =>
            {
                return(HttpContext.Current.GetOwinContext().GetUserManager <ApplicationUserManager>());
            }).InSingletonScope();

            kernel.Bind <ISettingsService>().To <SettingsService>().InSingletonScope();

            kernel.Bind <IFinanceService>().To <FinanceService>().InSingletonScope();

            kernel.Bind <ICatalogService>().ToMethod(context =>
            {
                string appDataPath = HttpContext.Current.Server.MapPath("~/App_Data");
                string file        = System.Text.RegularExpressions.Regex.Replace(WebConfigurationManager.AppSettings["catalog:path"], @"\|DataDirectory\|", appDataPath, System.Text.RegularExpressions.RegexOptions.IgnoreCase);

                return(CatalogService.Create(file));
            }).InSingletonScope();

            kernel.Bind <IShoppingCartService>().ToMethod(context =>
            {
                ApplicationDbContext dbContext = HttpContext.Current.GetOwinContext().Get <ApplicationDbContext>();
                return(ShoppingCartService.Create(dbContext));
            });

            kernel.Bind <IErpService>().To <ErpService>();
        }
Пример #2
0
        private static async Task InitCatalogs()
        {
            var kinds = Enum.GetValues(typeof(CatalogKind));

            foreach (var kind in kinds)
            {
                var catalogKind = (CatalogKind)kind;

                var catalog = await CatalogService.GetByKind(catalogKind);

                if (catalog == null)
                {
                    catalog = await CatalogService.Create(catalogKind);

                    switch (catalogKind)
                    {
                    case CatalogKind.Cargo:
                    {
                        await InitCargoCatalogItems(catalog.Id);

                        break;
                    }

                    case CatalogKind.Vehicle:
                    {
                        await InitVehicleCatalogItems(catalog.Id);

                        break;
                    }
                    }
                }
            }
        }
Пример #3
0
        public IActionResult Create([FromBody] CatalogDto catalog)
        {
            if (catalogService.Create(catalog))
            {
                return(NoContent());
            }

            return(BadRequest());
        }
Пример #4
0
        public ActionResult CreatePost(CatalogIndexView vm)
        {
            if (ModelState.IsValid)
            {
                _catalogService.Create(vm.AddCatalog);
            }

            vm.Catalogs = _catalogService.FindAll();

            return(View("Index", vm));
        }
Пример #5
0
        public void GeneralStats_Should_Be_One()
        {
            //Arrange
            var unit = new Unit
            {
                available     = true,
                id            = "001-001-001",
                originalPrice = new Price {
                    value = 100, currency = "EUR", formatted = "€100"
                },
                price = new Price {
                    value = 100, currency = "EUR", formatted = "€100"
                },
                size  = "38",
                stock = 5
            };
            var pc = new ProductCreate
            {
                Color      = "red",
                Id         = "001",
                ModelId    = "001-001",
                Genders    = new int[] { 0 },
                Name       = "test",
                Season     = "Winter",
                SeasonYear = "2018",
                Units      = new Unit[] { unit }
            };

            string uniqueDatabaseName = $"CatalogTestDb_{Guid.NewGuid()}";
            var    options            = new DbContextOptionsBuilder <CatalogContext>()
                                        .UseInMemoryDatabase(databaseName: uniqueDatabaseName)
                                        .Options;

            using (var context = new CatalogContext(options))
            {
                var service = new CatalogService(context);
                //Act
                var validationResults = service.Create(pc);

                //Assert
                Assert.AreEqual(0, validationResults.Count());

                //Act
                var actual = service.GeneralStats();

                //Assert
                Assert.AreEqual(1, actual.ProductCount);
                Assert.AreEqual(1, actual.ProductsWithOneUnit.Count());
                Assert.AreEqual(1, actual.UnitCount);
            }
        }