/// <summary> /// 增加产品信息 /// </summary> /// <param name="inputDtos"></param> /// <returns></returns> public async Task <OperationResult> Add(params ProductInfoInputDto[] inputDtos) { inputDtos.CheckNotNull("inputDtos"); foreach (var dtoData in inputDtos) { if (string.IsNullOrEmpty(dtoData.ProductCode)) { return(new OperationResult(OperationResultType.Error, "请正确填写产品编号!")); } if (string.IsNullOrEmpty(dtoData.ProductName)) { return(new OperationResult(OperationResultType.Error, "请正确填写产品名称!")); } if (ProductInfoRepository.CheckExists(x => x.ProductCode == dtoData.ProductCode)) { return(new OperationResult(OperationResultType.Error, "该产品编号已存在,无法保存!")); } if (ProductInfoRepository.CheckExists(x => x.ProductName == dtoData.ProductName)) { return(new OperationResult(OperationResultType.Error, "该产品名称已存在,无法保存!")); } dtoData.ProductType = ProductTypeInfoRepository.TrackEntities.Where(m => m.Id == dtoData.ProductType_Id).FirstOrDefault(); if (Equals(dtoData.ProductType, null)) { return(new OperationResult(OperationResultType.Error, "对应的产品类别不存在,无法保存!")); } } ProductInfoRepository.UnitOfWork.BeginTransaction(); var result = await ProductInfoRepository.InsertAsync(inputDtos); ProductInfoRepository.UnitOfWork.Commit(); return(result); }
public void TestInitialize() { _fakeProductInfoRepository = new FakeProductInfoRepository() { QuantityAvailable = 0, Price = 65 }; _vendingMachine = new VendingMachine(_fakeProductInfoRepository); }
protected VendingMachineState(StateContext context, List <Coin> returnTray, List <Coin> coinSlot, ProductInfoRepository productInfoRepository, List <string> output, List <Coin> vault) { Context = context; CoinSlot = coinSlot; ProductInfoRepository = productInfoRepository; Output = output; Vault = vault; ReturnTray = returnTray; }
public void Dispense(string sku) { if (ProductInfoRepository.GetQuantityAvailable(sku) == 0) { Context.State = new SoldOutState(this); return; } DispenseCallback(sku); }
public VendingMachine(ProductInfoRepository productInfoRepository) { // Machine is preloaded, should probably inject the vault var vault = new List <Coin>(); vault.AddRange(Enumerable.Repeat(Coin.Quarter, 10)); vault.AddRange(Enumerable.Repeat(Coin.Dime, 10)); vault.AddRange(Enumerable.Repeat(Coin.Nickel, 10)); State = new NoMoneyState(this, new List <Coin>(), new List <Coin>(), productInfoRepository, new List <string>(), vault); }
/// <summary> /// 物理删除产品信息 /// </summary> /// <param name="ids"></param> /// <returns></returns> public async Task <OperationResult> Delete(params Guid[] ids) { ids.CheckNotNull("ids"); foreach (var id in ids) { int count = ProductionRuleInfoRepository.Entities.Where(m => m.Product.Id == id).Count(); if (count > 0) { return(new OperationResult(OperationResultType.Error, "产品数据关联配方信息,不能被删除。")); } } ProductInfoRepository.UnitOfWork.BeginTransaction(); var result = await ProductInfoRepository.DeleteAsync(ids); ProductInfoRepository.UnitOfWork.Commit(); return(result); }
protected override void DispenseCallback(string sku) { var priceInCents = ProductInfoRepository.GetPrice(sku); var currentTotal = CurrentTotal(); if (currentTotal < priceInCents) { Context.State = new PriceState(this, priceInCents.Value); } else { Output.Add(sku); ProductInfoRepository.DecrementProductCount(sku); Vault.AddRange(CoinSlot); CoinSlot.Clear(); Refund(currentTotal, priceInCents); Context.State = new ThankYouState(this); } }
public PriceState(StateContext context, List <Coin> returnTray, List <Coin> coinSlot, ProductInfoRepository productInfoRepository, List <string> output, List <Coin> vault, int priceInCents) : base(context, returnTray, coinSlot, productInfoRepository, output, vault) { _priceInCents = priceInCents; }
public async Task TestWholeInfrastructureBeingHere() { //PLEASE TAKE CARE IF THE CONFIG MATCHES YOUR OWN MONGODB SETTINGS! var mongoConfig = new MongoConfig("mongodb://localhost", "test-blog"); var databaseProvider = Factory.CreateDatabaseProvider(mongoConfig); var transactionProvider = Factory.CreateTransactionProvider(databaseProvider); var productRepository = new ProductRepository(transactionProvider, databaseProvider); var productInfoRepository = new ProductInfoRepository(transactionProvider, databaseProvider, productRepository); var recipeRepository = new RecipeRepository(transactionProvider, databaseProvider, productRepository); var storageRepository = new StorageRepository(transactionProvider, databaseProvider); // Clear database :) await deleteAllItemsFromDatabase(productRepository, productInfoRepository, recipeRepository, storageRepository); var ingredient = new Ingredient { Amount = 100, Name = "Wirkstoff A", Unit = DBI_Apotheke.Core.Workloads.Modules.Unit.MG }; var idPi = new ObjectId(); var list = new List <Ingredient>(); list.Add(ingredient); var productInfo = new ProductInfo { Brand = "Aspiring", Id = idPi, Ingredients = list, Name = "AspirinComplex" }; productInfo = await productInfoRepository.InsertItem(productInfo); var product1 = new Product { Amount = 200, Id = new ObjectId(), Price = 20, ProductInfoId = productInfo.Id, PZN = 01, Unit = DBI_Apotheke.Core.Workloads.Modules.Unit.G }; var product2 = new Product { Amount = 200, Id = new ObjectId(), Price = 10, ProductInfoId = productInfo.Id, PZN = 02, Unit = DBI_Apotheke.Core.Workloads.Modules.Unit.G }; var recipe = new Recipe { Address = "Burger Sta?e", Id = new ObjectId(), Issuer = "Kirchi", Name = "Elias", PZNs = new List <int>() { 1, 2 } }; product1 = await productRepository.InsertItem(product1); product2 = await productRepository.InsertItem(product2); recipe = await recipeRepository.InsertItem(recipe); var storage1 = new Storage { Id = new ObjectId(), Amount = 100, PZN = 1, StorageSite = "Hamburg" }; var storage2 = new Storage { Id = new ObjectId(), Amount = 100, PZN = 2, StorageSite = "Hamburg" }; storage1 = await storageRepository.InsertItem(storage1); storage2 = await storageRepository.InsertItem(storage2); _testOutputHelper.WriteLine("Test if everything was received!"); _testOutputHelper.WriteLine("Id: " + productInfo.Id.ToString() + " Object: " + productInfo.ToString()); _testOutputHelper.WriteLine("Id: " + product1.Id.ToString() + " Object: " + product1.ToString()); _testOutputHelper.WriteLine("Id: " + product2.Id.ToString() + " Object: " + product2.ToString()); _testOutputHelper.WriteLine("Id: " + product1.Id.ToString() + " Object: " + product1.ToString()); _testOutputHelper.WriteLine("Id: " + recipe.Id.ToString() + " Object: " + recipe.ToString()); _testOutputHelper.WriteLine("Id: " + storage1.Id.ToString() + " Object: " + storage1.ToString()); _testOutputHelper.WriteLine("Id: " + storage2.Id.ToString() + " Object: " + storage2.ToString()); var productsInfoByIngreadients = await productInfoRepository.GetByIngredient("Wirkstoff A"); var productsInfo = await productInfoRepository.GetAllItems(); productsInfoByIngreadients.Should().HaveCount(1); productsInfo.Should().HaveCount(1); productsInfo.Should().BeEquivalentTo(productsInfoByIngreadients); product1 = await productRepository.GetByPzn(recipe.PZNs.IndexOf(0)); product2 = await productRepository.GetByPzn(recipe.PZNs.IndexOf(1)); var products = await productRepository.GetAllItems(); products.Should().HaveCount(2); products.Should().BeEquivalentTo(new List <Product> { product1, product2 }); var actualRecipe = await recipeRepository.GetItemById(recipe.Id); actualRecipe.Should().BeEquivalentTo(recipe); var totalPrice = await recipeRepository.GetTotalPrice(actualRecipe !); totalPrice.Should().BeApproximately(30, 0.1); var actualStorage = await storageRepository.GetItemById(storage1.Id); actualStorage.Should().BeEquivalentTo(storage1); var actualStorage2 = await storageRepository.GetItemById(storage2.Id); actualStorage2.Should().BeEquivalentTo(storage2); actualStorage = await storageRepository.GetByPzn(product1.PZN); actualStorage.Should().BeEquivalentTo(storage1); actualStorage2 = await storageRepository.GetByPzn(product2.PZN); actualStorage2.Should().BeEquivalentTo(storage2); }
private static async Task deleteAllItemsFromDatabase(ProductRepository productRepository, ProductInfoRepository productInfoRepository, RecipeRepository recipeRepository, StorageRepository storageRepository) { foreach (var p in await productRepository.GetAllItems()) { if (p != null) { await productRepository.DeleteItem(p.Id); } } foreach (var p in await productInfoRepository.GetAllItems()) { if (p != null) { await productInfoRepository.DeleteItem(p.Id); } } foreach (var p in await recipeRepository.GetAllItems()) { if (p != null) { await recipeRepository.DeleteItem(p.Id); } } foreach (var p in await storageRepository.GetAllItems()) { if (p != null) { await storageRepository.DeleteItem(p.Id); } } }
public void TestInitialize() { _productInfoRepository = new InMemoryProductInfoRepository(); _context = new VendingMachine(_productInfoRepository); }
/// <summary> /// 检查实体是否存在 /// </summary> /// <param name="predicate"></param> /// <param name="id"></param> /// <returns></returns> public bool CheckExists(Expression <Func <ProductInfo, bool> > predicate, Guid id) { return(ProductInfoRepository.CheckExists(predicate, id)); }
protected override void DispenseCallback(string sku) { var priceInCents = ProductInfoRepository.GetPrice(sku) ?? 0; Context.State = new PriceState(this, priceInCents); }
public NoMoneyState(StateContext context, List <Coin> returnTray, List <Coin> coinSlot, ProductInfoRepository productInfoRepository, List <string> output, List <Coin> vault) : base(context, returnTray, coinSlot, productInfoRepository, output, vault) { }
public ModifyProductInfo() { repository = DbFactory.Repository <ProductInfoRepository>(false); }