public async Task<HttpResponseMessage> AddOrUpdateAsync(QuantityConditionViewModel postedData) { var mapper = GetMapper(); QuantityCondition quantityCondition = mapper.Map<QuantityCondition>(postedData); var resultValue = await quantityConditionBusiness.AddOrUpdateQuantityConditionAsync(quantityCondition); if (!resultValue.ReturnStatus) { return CreateErrorResponse(resultValue); } postedData.Id = resultValue.ResultValue.Id; var goodsQ = resultValue.ResultValue.GoodsQuantityConditions.FirstOrDefault(); if (goodsQ != null) { var viewGoodsQ = postedData.GoodsQuantityConditions.First(); viewGoodsQ.Id = goodsQ.Id; foreach (var branchQ in goodsQ.BranchQuantityConditions) { viewGoodsQ.BranchQuantityConditions.Single(x => x.BranchId == branchQ.BranchId).Id = branchQ.Id; } } return CreateViewModelResponse(postedData, resultValue); }
public async Task GetQuantityConditionAsync_RealData_ByCreateInstance_Test() { //Arrange var quantityConditionBS = _kernel.Get <IQuantityConditionBS>(); QuantityConditionServiceController controller = new QuantityConditionServiceController(quantityConditionBS); controller.Request = new HttpRequestMessage(); controller.Request.SetConfiguration(new System.Web.Http.HttpConfiguration()); //Act var result = await controller.GetQuantityConditionAsync(3045); QuantityConditionViewModel vModel = new QuantityConditionViewModel(); bool checkGetResult = result.TryGetContentValue(out vModel); //Assert Assert.IsTrue(checkGetResult); Assert.AreEqual(vModel.GoalCategoryName, "16 قلم اکتور کو"); Assert.AreEqual(vModel.GoodsQuantityConditions.Count, 15); Assert.AreEqual(vModel.GoodsQuantityConditions[0].BranchQuantityConditions.Count, 25); Assert.AreEqual(vModel.GoodsQuantityConditions[0].QuantityConditionId, vModel.Id); Assert.AreEqual(vModel.GoodsQuantityConditions[0].BranchQuantityConditions[0].GoodsQuantityConditionId, vModel.GoodsQuantityConditions[0].Id); }
public async Task<HttpResponseMessage> GetQuantityConditionAsync(int goalId) { IBusinessResultValue<QuantityCondition> loadResultValue = await quantityConditionBusiness.LoadQuantityConditionAsync(goalId); if (!loadResultValue.ReturnStatus) { return CreateErrorResponse(loadResultValue); } QuantityConditionViewModel result = new QuantityConditionViewModel(); var mapper = GetMapper(); result = mapper.Map<QuantityConditionViewModel>(loadResultValue.ResultValue); return CreateViewModelResponse(result, loadResultValue); }
public async Task GetQuantityConditionAsync_CreateMockData_ByCreateInstance_Test() { //Arrange QuantityCondition quantityCondition = new QuantityCondition(); quantityCondition.Goal = new Goal() { Id = 10, GoalGoodsCategory = new GoalGoodsCategory() { Name = "GoalGoodsCategory_Test" } }; quantityCondition.GoalId = 10; quantityCondition.Quantity = 20; quantityCondition.ExtraEncouragePercent = 1.3M; GoodsQuantityCondition qoodsQuantityCondition = new GoodsQuantityCondition(); qoodsQuantityCondition.Quantity = 30; qoodsQuantityCondition.Goods = new Goods() { EnName = "Drug No 1" }; qoodsQuantityCondition.BranchQuantityConditions.Add(new BranchQuantityCondition() { Quantity = 40, Branch = new Branch() { Name = "Branch 1" } }); qoodsQuantityCondition.BranchQuantityConditions.Add(new BranchQuantityCondition() { Quantity = 50, Branch = new Branch() { Name = "Branch 2" } }); quantityCondition.GoodsQuantityConditions.Add(qoodsQuantityCondition); var quantityConditionBusinessService = _kernel.GetMock <IQuantityConditionBS>(); var businessResultValue = _kernel.Get <IBusinessResultValue <QuantityCondition> >(); businessResultValue.ReturnStatus = true; businessResultValue.ResultValue = quantityCondition; quantityConditionBusinessService.Setup(x => x.LoadQuantityConditionAsync(It.IsAny <int>())) .ReturnsAsync(businessResultValue); QuantityConditionServiceController controller = new QuantityConditionServiceController(quantityConditionBusinessService.Object); controller.Request = new HttpRequestMessage(); controller.Request.SetConfiguration(new System.Web.Http.HttpConfiguration()); //Act var result = await controller.GetQuantityConditionAsync(10); QuantityConditionViewModel vModel = new QuantityConditionViewModel(); bool checkGetResult = result.TryGetContentValue(out vModel); //Assert Assert.IsTrue(checkGetResult); Assert.AreEqual(vModel.GoalCategoryName, quantityCondition.Goal.GoalGoodsCategory.Name); Assert.AreEqual(vModel.GoodsQuantityConditions.Count, quantityCondition.GoodsQuantityConditions.Count); }