public async Task Get_Return_Success() { // Arrange var unitUnderTest = CreateGarmentSubconCuttingOutController(); var id = Guid.NewGuid(); _mockSubconCuttingOutRepository .Setup(s => s.Read(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>())) .Returns(new List <GarmentCuttingOutReadModel>().AsQueryable()); _mockSubconCuttingOutRepository .Setup(s => s.Find(It.IsAny <IQueryable <GarmentCuttingOutReadModel> >())) .Returns(new List <GarmentSubconCuttingOut>() { new GarmentSubconCuttingOut(id, "productCode", "cutOutType", new UnitDepartmentId(1), "unitFromCode", "unitFromName", DateTimeOffset.Now, "RONo", "article", new GarmentComodityId(1), "comodityCode", "comodityName", 1, 1, "remark") }); GarmentSubconCuttingOutItem garmentCuttingOutItem = new GarmentSubconCuttingOutItem(id, id, id, id, new ProductId(1), "productCode", "productName", "designColor", 1); _mockSubconCuttingOutItemRepository .Setup(s => s.Query) .Returns(new List <GarmentCuttingOutItemReadModel>() { garmentCuttingOutItem.GetReadModel() }.AsQueryable()); _mockSubconCuttingOutItemRepository .Setup(s => s.Find(It.IsAny <IQueryable <GarmentCuttingOutItemReadModel> >())) .Returns(new List <GarmentSubconCuttingOutItem>() { new GarmentSubconCuttingOutItem(id, id, id, id, new ProductId(1), "productCode", "productName", "designColor", 1) }); GarmentSubconCuttingOutDetail garmentCuttingOutDetail = new GarmentSubconCuttingOutDetail(id, id, new SizeId(1), "sizeName", "color", 1, 1, new UomId(1), "cuttingOutUomUnit", 1, 1, "remark"); _mockSubconCuttingOutDetailRepository .Setup(s => s.Query) .Returns(new List <GarmentCuttingOutDetailReadModel>() { garmentCuttingOutDetail.GetReadModel() }.AsQueryable()); _mockSubconCuttingOutDetailRepository .Setup(s => s.Find(It.IsAny <IQueryable <GarmentCuttingOutDetailReadModel> >())) .Returns(new List <GarmentSubconCuttingOutDetail>() { new GarmentSubconCuttingOutDetail(id, id, new SizeId(1), "sizeName", "color", 1, 1, new UomId(1), "cuttingOutUomUnit", 1, 1, "remark") }); // Act var orderData = new { article = "desc", }; string order = JsonConvert.SerializeObject(orderData); var result = await unitUnderTest.Get(1, 25, order, new List <string>(), "productCode", "{}"); // Assert Assert.Equal((int)HttpStatusCode.OK, GetStatusCode(result)); }
public async Task Get_StateUnderTest_ExpectedBehavior() { // Arrange var unitUnderTest = CreateGarmentSubconCuttingOutController(); _mockSubconCuttingOutRepository .Setup(s => s.Read(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>())) .Returns(new List <GarmentCuttingOutReadModel>().AsQueryable()); Guid cuttingOutGuid = Guid.NewGuid(); _mockSubconCuttingOutRepository .Setup(s => s.Find(It.IsAny <IQueryable <GarmentCuttingOutReadModel> >())) .Returns(new List <GarmentSubconCuttingOut>() { new GarmentSubconCuttingOut(cuttingOutGuid, null, null, new UnitDepartmentId(1), null, null, DateTimeOffset.Now, "RONo", null, new GarmentComodityId(1), null, null, 1, 1, null) }); Guid cuttingOutItemGuid = Guid.NewGuid(); GarmentSubconCuttingOutItem garmentCuttingOutItem = new GarmentSubconCuttingOutItem(cuttingOutItemGuid, cuttingOutGuid, Guid.NewGuid(), Guid.NewGuid(), new ProductId(1), null, null, null, 1); _mockSubconCuttingOutItemRepository .Setup(s => s.Query) .Returns(new List <GarmentCuttingOutItemReadModel>() { garmentCuttingOutItem.GetReadModel() }.AsQueryable()); _mockSubconCuttingOutItemRepository .Setup(s => s.Find(It.IsAny <IQueryable <GarmentCuttingOutItemReadModel> >())) .Returns(new List <GarmentSubconCuttingOutItem>() { new GarmentSubconCuttingOutItem(cuttingOutItemGuid, cuttingOutGuid, Guid.NewGuid(), Guid.NewGuid(), new ProductId(1), null, null, null, 1) }); GarmentSubconCuttingOutDetail garmentCuttingOutDetail = new GarmentSubconCuttingOutDetail(Guid.NewGuid(), cuttingOutItemGuid, new SizeId(1), null, null, 1, 1, new UomId(1), null, 1, 1, null); _mockSubconCuttingOutDetailRepository .Setup(s => s.Query) .Returns(new List <GarmentCuttingOutDetailReadModel>() { garmentCuttingOutDetail.GetReadModel() }.AsQueryable()); _mockSubconCuttingOutDetailRepository .Setup(s => s.Find(It.IsAny <IQueryable <GarmentCuttingOutDetailReadModel> >())) .Returns(new List <GarmentSubconCuttingOutDetail>() { new GarmentSubconCuttingOutDetail(Guid.NewGuid(), cuttingOutItemGuid, new SizeId(1), null, null, 1, 1, new UomId(1), null, 1, 1, null) }); // Act var result = await unitUnderTest.Get(); // Assert Assert.Equal((int)HttpStatusCode.OK, GetStatusCode(result)); }
public void should_success_instantiate() { Guid id = Guid.NewGuid(); GarmentSubconCuttingOutDetail detail = new GarmentSubconCuttingOutDetail(new GarmentCuttingOutDetailReadModel(id)); detail.SetCuttingOutQuantity(1); detail.SetRemainingQuantity(1); detail.SetColor("Color"); detail.SetSizeId(new SizeId(1)); detail.SetSizeName("SizeName"); detail.Modify(); Assert.NotNull(detail); }
public GarmentSubconCuttingOutDetailDto(GarmentSubconCuttingOutDetail garmentCuttingOutDetail) { Id = garmentCuttingOutDetail.Identity; CutOutItemId = garmentCuttingOutDetail.CutOutItemId; Size = new SizeValueObject(garmentCuttingOutDetail.SizeId.Value, garmentCuttingOutDetail.SizeName); CuttingOutQuantity = garmentCuttingOutDetail.CuttingOutQuantity; CuttingOutUom = new Uom(garmentCuttingOutDetail.CuttingOutUomId.Value, garmentCuttingOutDetail.CuttingOutUomUnit); Color = garmentCuttingOutDetail.Color; RemainingQuantity = garmentCuttingOutDetail.RemainingQuantity; BasicPrice = garmentCuttingOutDetail.BasicPrice; Price = garmentCuttingOutDetail.Price; Remark = garmentCuttingOutDetail.Remark; }
public async Task <GarmentSubconCuttingOut> Handle(PlaceGarmentSubconCuttingOutCommand request, CancellationToken cancellationToken) { request.Items = request.Items.Where(item => item.IsSave == true && item.Details.Count() > 0).ToList(); GarmentSubconCuttingOut garmentCuttingOut = new GarmentSubconCuttingOut( Guid.NewGuid(), GenerateCutOutNo(request), request.CuttingOutType, new UnitDepartmentId(request.UnitFrom.Id), request.UnitFrom.Code, request.UnitFrom.Name, request.CuttingOutDate.GetValueOrDefault(), request.RONo, request.Article, new GarmentComodityId(request.Comodity.Id), request.Comodity.Code, request.Comodity.Name, request.EPOId, request.EPOItemId, request.POSerialNumber ); Dictionary <Guid, double> cuttingInDetailToBeUpdated = new Dictionary <Guid, double>(); Dictionary <string, double> cuttingSubconToBeUpdated = new Dictionary <string, double>(); Dictionary <string, List <Guid> > cuttingSubconToBeUpdatedId = new Dictionary <string, List <Guid> >(); foreach (var item in request.Items) { GarmentSubconCuttingOutItem garmentCuttingOutItem = new GarmentSubconCuttingOutItem( Guid.NewGuid(), item.CuttingInId, item.CuttingInDetailId, garmentCuttingOut.Identity, new ProductId(item.Product.Id), item.Product.Code, item.Product.Name, item.DesignColor, item.TotalCuttingOutQuantity ); foreach (var detail in item.Details) { var detailId = Guid.NewGuid(); GarmentSubconCuttingOutDetail garmentCuttingOutDetail = new GarmentSubconCuttingOutDetail( detailId, garmentCuttingOutItem.Identity, new SizeId(detail.Size.Id), detail.Size.Size, detail.Color, detail.CuttingOutQuantity, detail.CuttingOutQuantity, new UomId(detail.CuttingOutUom.Id), detail.CuttingOutUom.Unit, detail.BasicPrice, detail.Price, detail.Remark.ToUpper() ); string key = request.RONo + "~" + detail.Size.Id.ToString() + "~" + detail.Size.Size + "~" + item.Product.Id.ToString() + "~" + item.Product.Code + "~" + item.Product.Name + "~" + request.Comodity.Id.ToString() + "~" + request.Comodity.Code + "~" + request.Comodity.Name + "~" + item.DesignColor + "~" + detail.Remark.ToUpper() + "~" + detail.BasicPrice; if (cuttingSubconToBeUpdated.ContainsKey(key)) { cuttingSubconToBeUpdated[key] += detail.CuttingOutQuantity; cuttingSubconToBeUpdatedId[key].Add(detailId); } else { cuttingSubconToBeUpdated.Add(key, detail.CuttingOutQuantity); cuttingSubconToBeUpdatedId.Add(key, new List <Guid> { detailId }); } if (cuttingInDetailToBeUpdated.ContainsKey(item.CuttingInDetailId)) { cuttingInDetailToBeUpdated[item.CuttingInDetailId] += detail.CuttingOutQuantity; } else { cuttingInDetailToBeUpdated.Add(item.CuttingInDetailId, detail.CuttingOutQuantity); } await _garmentCuttingOutDetailRepository.Update(garmentCuttingOutDetail); } await _garmentCuttingOutItemRepository.Update(garmentCuttingOutItem); } foreach (var cuttingInDetail in cuttingInDetailToBeUpdated) { var garmentCuttingInDetail = _garmentCuttingInDetailRepository.Query.Where(x => x.Identity == cuttingInDetail.Key).Select(s => new GarmentCuttingInDetail(s)).Single(); garmentCuttingInDetail.SetRemainingQuantity(garmentCuttingInDetail.RemainingQuantity - cuttingInDetail.Value); garmentCuttingInDetail.Modify(); await _garmentCuttingInDetailRepository.Update(garmentCuttingInDetail); } foreach (var subconCutting in cuttingSubconToBeUpdated) { var RONo = subconCutting.Key.Split("~")[0]; var SizeId = subconCutting.Key.Split("~")[1]; var SizeName = subconCutting.Key.Split("~")[2]; var ProductId = subconCutting.Key.Split("~")[3]; var ProductCode = subconCutting.Key.Split("~")[4]; var ProductName = subconCutting.Key.Split("~")[5]; var ComodityId = subconCutting.Key.Split("~")[6]; var ComodityCode = subconCutting.Key.Split("~")[7]; var ComodityName = subconCutting.Key.Split("~")[8]; var designColor = subconCutting.Key.Split("~")[9]; var remark = subconCutting.Key.Split("~")[10]; var basicPrice = subconCutting.Key.Split("~")[11]; GarmentSubconCutting garmentSubconCutting = _garmentSubconCuttingRepository.Query.Where(a => a.RONo == RONo && a.SizeId == Convert.ToInt32(SizeId) && a.ComodityId == Convert.ToInt32(ComodityId) && a.ProductId == Convert.ToInt32(ProductId) && a.Remark == remark && a.DesignColor == designColor && a.BasicPrice == Convert.ToDouble(basicPrice)).Select(a => new GarmentSubconCutting(a)).FirstOrDefault(); if (garmentSubconCutting == null) { garmentSubconCutting = new GarmentSubconCutting( Guid.NewGuid(), request.RONo, new SizeId(Convert.ToInt32(SizeId)), SizeName, subconCutting.Value, new ProductId(Convert.ToInt32(ProductId)), ProductCode, ProductName, new GarmentComodityId(Convert.ToInt32(ComodityId)), ComodityCode, ComodityName, designColor, remark, Convert.ToDouble(basicPrice) ); await _garmentSubconCuttingRepository.Update(garmentSubconCutting); } else { garmentSubconCutting.SetQuantity(garmentSubconCutting.Quantity + subconCutting.Value); garmentSubconCutting.Modify(); await _garmentSubconCuttingRepository.Update(garmentSubconCutting); } foreach (var detailId in cuttingSubconToBeUpdatedId[subconCutting.Key] ?? new List <Guid>()) { GarmentSubconCuttingRelation garmentSubconCuttingRelation = new GarmentSubconCuttingRelation(Guid.NewGuid(), garmentSubconCutting.Identity, detailId); await _garmentSubconCuttingRelationRepository.Update(garmentSubconCuttingRelation); } } await _garmentCuttingOutRepository.Update(garmentCuttingOut); _storage.Save(); return(garmentCuttingOut); }