public async Task Get_StateUnderTest_ExpectedBehavior() { // Arrange var unitUnderTest = CreateGarmentCuttingOutController(); _mockGarmentCuttingOutRepository .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(); _mockGarmentCuttingOutRepository .Setup(s => s.Find(It.IsAny <IQueryable <GarmentCuttingOutReadModel> >())) .Returns(new List <GarmentCuttingOut>() { new GarmentCuttingOut(cuttingOutGuid, null, null, new UnitDepartmentId(1), null, null, DateTimeOffset.Now, "RONo", null, new UnitDepartmentId(1), null, null, new GarmentComodityId(1), null, null) }); Guid cuttingOutItemGuid = Guid.NewGuid(); GarmentCuttingOutItem garmentCuttingOutItem = new GarmentCuttingOutItem(cuttingOutItemGuid, cuttingOutGuid, Guid.NewGuid(), Guid.NewGuid(), new ProductId(1), null, null, null, 1); _mockGarmentCuttingOutItemRepository .Setup(s => s.Query) .Returns(new List <GarmentCuttingOutItemReadModel>() { garmentCuttingOutItem.GetReadModel() }.AsQueryable()); _mockGarmentCuttingOutItemRepository .Setup(s => s.Find(It.IsAny <IQueryable <GarmentCuttingOutItemReadModel> >())) .Returns(new List <GarmentCuttingOutItem>() { new GarmentCuttingOutItem(cuttingOutItemGuid, cuttingOutGuid, Guid.NewGuid(), Guid.NewGuid(), new ProductId(1), null, null, null, 1) }); GarmentCuttingOutDetail garmentCuttingOutDetail = new GarmentCuttingOutDetail(Guid.NewGuid(), cuttingOutItemGuid, new SizeId(1), null, null, 1, 1, new UomId(1), null, 1, 1); _mockGarmentCuttingOutDetailRepository .Setup(s => s.Query) .Returns(new List <GarmentCuttingOutDetailReadModel>() { garmentCuttingOutDetail.GetReadModel() }.AsQueryable()); _mockGarmentCuttingOutDetailRepository .Setup(s => s.Find(It.IsAny <IQueryable <GarmentCuttingOutDetailReadModel> >())) .Returns(new List <GarmentCuttingOutDetail>() { new GarmentCuttingOutDetail(Guid.NewGuid(), cuttingOutItemGuid, new SizeId(1), null, null, 1, 1, new UomId(1), null, 1, 1) }); // Act var result = await unitUnderTest.Get(); // Assert Assert.Equal((int)HttpStatusCode.OK, GetStatusCode(result)); }
public async Task Get_with_Keyword_No_Order() { // Arrange var unitUnderTest = CreateGarmentCuttingOutController(); Guid id = Guid.NewGuid(); _mockGarmentCuttingOutRepository .Setup(s => s.Read(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>())) .Returns(new List <GarmentCuttingOutReadModel>().AsQueryable()); _mockGarmentCuttingOutRepository .Setup(s => s.Find(It.IsAny <IQueryable <GarmentCuttingOutReadModel> >())) .Returns(new List <GarmentCuttingOut>() { new GarmentCuttingOut(id, "cutOutNo", "cuttingOutType", new UnitDepartmentId(1), "unitFromCode", "unitFromName", DateTimeOffset.Now, "RONo", "article", new UnitDepartmentId(1), "unitCode", "unitName", new GarmentComodityId(1), "comodityCode", "comodityName") }); GarmentCuttingOutItem garmentCuttingOutItem = new GarmentCuttingOutItem(id, id, Guid.NewGuid(), Guid.NewGuid(), new ProductId(1), null, null, null, 1); _mockGarmentCuttingOutItemRepository .Setup(s => s.Query) .Returns(new List <GarmentCuttingOutItemReadModel>() { garmentCuttingOutItem.GetReadModel() }.AsQueryable()); _mockGarmentCuttingOutItemRepository .Setup(s => s.Find(It.IsAny <IQueryable <GarmentCuttingOutItemReadModel> >())) .Returns(new List <GarmentCuttingOutItem>() { new GarmentCuttingOutItem(id, id, id, id, new ProductId(1), "productCode", "productName", "designColor", 1) }); GarmentCuttingOutDetail garmentCuttingOutDetail = new GarmentCuttingOutDetail(id, id, new SizeId(1), "sizeName", "color", 1, 1, new UomId(1), "cuttingOutUomUnit", 1, 1); _mockGarmentCuttingOutDetailRepository .Setup(s => s.Query) .Returns(new List <GarmentCuttingOutDetailReadModel>() { garmentCuttingOutDetail.GetReadModel() }.AsQueryable()); _mockGarmentCuttingOutDetailRepository .Setup(s => s.Find(It.IsAny <IQueryable <GarmentCuttingOutDetailReadModel> >())) .Returns(new List <GarmentCuttingOutDetail>() { new GarmentCuttingOutDetail(id, id, new SizeId(1), "sizename", "color", 1, 1, new UomId(1), "cuttingOutUomUnit", 1, 1) }); // Act var result = await unitUnderTest.Get(1, 25, "{}", new List <string>(), "productCode", "{}"); // Assert Assert.Equal((int)HttpStatusCode.OK, GetStatusCode(result)); }
public GarmentCuttingOutDetailDto(GarmentCuttingOutDetail 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; }
public void should_success_instantiate() { Guid id = Guid.NewGuid(); GarmentCuttingOutDetail detail = new GarmentCuttingOutDetail(new GarmentCuttingOutDetailReadModel(id)); detail.SetCuttingOutQuantity(2); detail.SetColor("BLUE"); detail.SetRemainingQuantity(4); detail.SetSizeId(new SizeId(1)); detail.SetSizeName("NewName"); detail.SetPrice(2); detail.Modify(); Assert.NotNull(detail); }
public async Task <GarmentCuttingOut> Handle(PlaceGarmentCuttingOutCommand request, CancellationToken cancellationToken) { request.Items = request.Items.Where(item => item.IsSave == true && item.Details.Count() > 0).ToList(); GarmentCuttingOut garmentCuttingOut = new GarmentCuttingOut( 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 UnitDepartmentId(request.Unit.Id), request.Unit.Code, request.Unit.Name, new GarmentComodityId(request.Comodity.Id), request.Comodity.Code, request.Comodity.Name ); GarmentSewingDO garmentSewingDO = new GarmentSewingDO( Guid.NewGuid(), GenerateSewingDONo(request), garmentCuttingOut.Identity, new UnitDepartmentId(request.UnitFrom.Id), request.UnitFrom.Code, request.UnitFrom.Name, new UnitDepartmentId(request.Unit.Id), request.Unit.Code, request.Unit.Name, request.RONo, request.Article, new GarmentComodityId(request.Comodity.Id), request.Comodity.Code, request.Comodity.Name, request.CuttingOutDate.GetValueOrDefault() ); Dictionary <Guid, double> cuttingInDetailToBeUpdated = new Dictionary <Guid, double>(); foreach (var item in request.Items) { GarmentCuttingOutItem garmentCuttingOutItem = new GarmentCuttingOutItem( 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) { GarmentCuttingOutDetail garmentCuttingOutDetail = new GarmentCuttingOutDetail( Guid.NewGuid(), garmentCuttingOutItem.Identity, new SizeId(detail.Size.Id), detail.Size.Size, detail.Color.ToUpper(), 0, detail.CuttingOutQuantity, new UomId(detail.CuttingOutUom.Id), detail.CuttingOutUom.Unit, detail.BasicPrice, detail.Price ); if (cuttingInDetailToBeUpdated.ContainsKey(item.CuttingInDetailId)) { cuttingInDetailToBeUpdated[item.CuttingInDetailId] += detail.CuttingOutQuantity; } else { cuttingInDetailToBeUpdated.Add(item.CuttingInDetailId, detail.CuttingOutQuantity); } await _garmentCuttingOutDetailRepository.Update(garmentCuttingOutDetail); GarmentComodityPrice garmentComodityPrice = _garmentComodityPriceRepository.Query.Where(a => a.IsValid == true && a.UnitId == request.Unit.Id && a.ComodityId == request.Comodity.Id).OrderBy(o => o.ModifiedDate).Select(s => new GarmentComodityPrice(s)).Last(); double price = (detail.BasicPrice + ((double)garmentComodityPrice.Price * 25 / 100)) * detail.CuttingOutQuantity; GarmentSewingDOItem garmentSewingDOItem = new GarmentSewingDOItem( Guid.NewGuid(), garmentSewingDO.Identity, garmentCuttingOutDetail.Identity, garmentCuttingOutItem.Identity, new ProductId(item.Product.Id), item.Product.Code, item.Product.Name, item.DesignColor, new SizeId(detail.Size.Id), detail.Size.Size, detail.CuttingOutQuantity, new UomId(detail.CuttingOutUom.Id), detail.CuttingOutUom.Unit, detail.Color.ToUpper(), detail.CuttingOutQuantity, detail.BasicPrice, price ); await _garmentSewingDOItemRepository.Update(garmentSewingDOItem); } 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); } await _garmentCuttingOutRepository.Update(garmentCuttingOut); await _garmentSewingDORepository.Update(garmentSewingDO); _storage.Save(); return(garmentCuttingOut); }