public async Task Get_StateUnderTest_ExpectedBehavior()
        {
            // Arrange
            var unitUnderTest = CreateGarmentExpenditureGoodController();

            _mockGarmentExpenditureGoodRepository
            .Setup(s => s.Read(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>()))
            .Returns(new List <GarmentExpenditureGoodReadModel>().AsQueryable());

            Guid ExpenditureGoodGuid = Guid.NewGuid();

            _mockGarmentExpenditureGoodRepository
            .Setup(s => s.Find(It.IsAny <IQueryable <GarmentExpenditureGoodReadModel> >()))
            .Returns(new List <GarmentExpenditureGood>()
            {
                new GarmentExpenditureGood(ExpenditureGoodGuid, null, null, new UnitDepartmentId(1), null, null, "RONo", "article", new GarmentComodityId(1), null, null, new BuyerId(1), null, null, DateTimeOffset.Now, null, null, 0, null, false)
            });

            Guid ExpenditureGoodItemGuid = Guid.NewGuid();
            GarmentExpenditureGoodItem garmentExpenditureGoodItem = new GarmentExpenditureGoodItem(ExpenditureGoodItemGuid, ExpenditureGoodGuid, new Guid(), new SizeId(1), null, 1, 0, new UomId(1), null, null, 1, 1);

            _mockGarmentExpenditureGoodItemRepository
            .Setup(s => s.Query)
            .Returns(new List <GarmentExpenditureGoodItemReadModel>()
            {
                garmentExpenditureGoodItem.GetReadModel()
            }.AsQueryable());


            // Act
            var result = await unitUnderTest.Get();

            // Assert
            Assert.Equal((int)HttpStatusCode.OK, GetStatusCode(result));
        }
 public GarmentExpenditureGoodItemDto(GarmentExpenditureGoodItem garmentExpenditureGoodItem)
 {
     Id = garmentExpenditureGoodItem.Identity;
     ExpenditureGoodId   = garmentExpenditureGoodItem.ExpenditureGoodId;
     FinishedGoodStockId = garmentExpenditureGoodItem.FinishedGoodStockId;
     Size          = new SizeValueObject(garmentExpenditureGoodItem.SizeId.Value, garmentExpenditureGoodItem.SizeName);
     Quantity      = garmentExpenditureGoodItem.Quantity;
     Uom           = new Uom(garmentExpenditureGoodItem.UomId.Value, garmentExpenditureGoodItem.UomUnit);
     Description   = garmentExpenditureGoodItem.Description;
     BasicPrice    = garmentExpenditureGoodItem.BasicPrice;
     Price         = garmentExpenditureGoodItem.Price;
     ReturQuantity = garmentExpenditureGoodItem.ReturQuantity;
 }
        public async Task <GarmentExpenditureGood> Handle(PlaceGarmentExpenditureGoodCommand request, CancellationToken cancellationToken)
        {
            request.Items = request.Items.ToList();

            GarmentComodityPrice garmentComodityPrice = _garmentComodityPriceRepository.Query.Where(a => a.IsValid == true && a.UnitId == request.Unit.Id && a.ComodityId == request.Comodity.Id).Select(s => new GarmentComodityPrice(s)).Single();

            GarmentExpenditureGood garmentExpenditureGood = new GarmentExpenditureGood(
                Guid.NewGuid(),
                GenerateExpenditureGoodNo(request),
                request.ExpenditureType,
                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,
                new BuyerId(request.Buyer.Id),
                request.Buyer.Code,
                request.Buyer.Name,
                request.ExpenditureDate,
                request.Invoice,
                request.ContractNo,
                request.Carton,
                request.Description,
                request.IsReceived
                );

            Dictionary <string, double> finStockToBeUpdated = new Dictionary <string, double>();
            Dictionary <Guid, double>   finstockQty         = new Dictionary <Guid, double>();

            foreach (var item in request.Items)
            {
                if (item.isSave)
                {
                    double StockQty = 0;
                    var    garmentFinishingGoodStock = _garmentFinishedGoodStockRepository.Query.Where(x => x.SizeId == item.Size.Id && x.UomId == item.Uom.Id && x.RONo == request.RONo && x.UnitId == request.Unit.Id && x.Quantity > 0).OrderBy(a => a.CreatedDate).ToList();

                    double qty = item.Quantity;
                    foreach (var finishedGood in garmentFinishingGoodStock)
                    {
                        if (!finstockQty.ContainsKey(finishedGood.Identity))
                        {
                            finstockQty.Add(finishedGood.Identity, finishedGood.Quantity);
                        }
                        string key = finishedGood.Identity.ToString() + "~" + item.Description;
                        if (qty > 0)
                        {
                            double remainQty = finstockQty[finishedGood.Identity] - qty;
                            if (remainQty < 0)
                            {
                                qty -= finstockQty[finishedGood.Identity];
                                finStockToBeUpdated.Add(key, 0);
                                finstockQty[finishedGood.Identity] = 0;
                            }
                            else if (remainQty == 0)
                            {
                                finStockToBeUpdated.Add(key, 0);
                                finstockQty[finishedGood.Identity] = remainQty;
                                break;
                            }
                            else if (remainQty > 0)
                            {
                                finStockToBeUpdated.Add(key, remainQty);
                                finstockQty[finishedGood.Identity] = remainQty;
                                break;
                            }
                        }
                    }
                }
            }

            foreach (var finStock in finStockToBeUpdated)
            {
                var keyString = finStock.Key.Split("~");

                var garmentFinishingGoodStockItem = _garmentFinishedGoodStockRepository.Query.Where(x => x.Identity == Guid.Parse(keyString[0])).Select(s => new GarmentFinishedGoodStock(s)).Single();

                var item = request.Items.Where(a => new SizeId(a.Size.Id) == garmentFinishingGoodStockItem.SizeId && new UomId(a.Uom.Id) == garmentFinishingGoodStockItem.UomId && a.Description == keyString[1]).Single();

                item.Price = (item.BasicPrice + ((double)garmentComodityPrice.Price * 1)) * item.Quantity;
                var qty = garmentFinishingGoodStockItem.Quantity - finStock.Value;

                GarmentExpenditureGoodItem garmentExpenditureGoodItem = new GarmentExpenditureGoodItem(
                    Guid.NewGuid(),
                    garmentExpenditureGood.Identity,
                    garmentFinishingGoodStockItem.Identity,
                    new SizeId(item.Size.Id),
                    item.Size.Size,
                    qty,
                    0,
                    new UomId(item.Uom.Id),
                    item.Uom.Unit,
                    item.Description,
                    garmentFinishingGoodStockItem.BasicPrice,
                    (garmentFinishingGoodStockItem.BasicPrice + (double)garmentComodityPrice.Price) * qty
                    );

                await _garmentExpenditureGoodItemRepository.Update(garmentExpenditureGoodItem);

                GarmentFinishedGoodStockHistory garmentFinishedGoodStockHistory = new GarmentFinishedGoodStockHistory(
                    Guid.NewGuid(),
                    garmentFinishingGoodStockItem.Identity,
                    Guid.Empty,
                    Guid.Empty,
                    garmentExpenditureGood.Identity,
                    garmentExpenditureGoodItem.Identity,
                    Guid.Empty,
                    Guid.Empty,
                    Guid.Empty,
                    Guid.Empty,
                    "OUT",
                    garmentExpenditureGood.RONo,
                    garmentExpenditureGood.Article,
                    garmentExpenditureGood.UnitId,
                    garmentExpenditureGood.UnitCode,
                    garmentExpenditureGood.UnitName,
                    garmentExpenditureGood.ComodityId,
                    garmentExpenditureGood.ComodityCode,
                    garmentExpenditureGood.ComodityName,
                    garmentExpenditureGoodItem.SizeId,
                    garmentExpenditureGoodItem.SizeName,
                    garmentExpenditureGoodItem.UomId,
                    garmentExpenditureGoodItem.UomUnit,
                    garmentExpenditureGoodItem.Quantity,
                    garmentExpenditureGoodItem.BasicPrice,
                    garmentExpenditureGoodItem.Price
                    );
                await _garmentFinishedGoodStockHistoryRepository.Update(garmentFinishedGoodStockHistory);

                garmentFinishingGoodStockItem.SetQuantity(finStock.Value);
                garmentFinishingGoodStockItem.SetPrice((garmentFinishingGoodStockItem.BasicPrice + (double)garmentComodityPrice.Price) * (finStock.Value));
                garmentFinishingGoodStockItem.Modify();

                await _garmentFinishedGoodStockRepository.Update(garmentFinishingGoodStockItem);
            }

            await _garmentExpenditureGoodRepository.Update(garmentExpenditureGood);

            _storage.Save();

            return(garmentExpenditureGood);
        }
Пример #4
0
        public async Task Handle_StateUnderTest_ExpectedBehavior()
        {
            // Arrange
            Guid finStockGuid   = Guid.NewGuid();
            Guid exGoodGuid     = Guid.NewGuid();
            Guid exGoodItemGuid = Guid.NewGuid();
            PlaceGarmentExpenditureGoodReturnCommandHandler unitUnderTest = CreatePlaceGarmentExpenditureGoodReturnCommandHandler();
            CancellationToken cancellationToken = CancellationToken.None;
            PlaceGarmentExpenditureGoodReturnCommand placeGarmentExpenditureGoodReturnCommand = new PlaceGarmentExpenditureGoodReturnCommand()
            {
                RONo      = "RONo",
                Unit      = new UnitDepartment(1, "UnitCode", "UnitName"),
                Article   = "Article",
                Comodity  = new GarmentComodity(1, "ComoCode", "ComoName"),
                Buyer     = new Buyer(1, "buyerCode", "buyerName"),
                ReturDate = DateTimeOffset.Now,
                Items     = new List <GarmentExpenditureGoodReturnItemValueObject>
                {
                    new GarmentExpenditureGoodReturnItemValueObject
                    {
                        Uom = new Uom(1, "UomUnit"),
                        FinishedGoodStockId   = finStockGuid,
                        ExpenditureGoodId     = exGoodGuid,
                        ExpenditureGoodItemId = exGoodItemGuid,
                        Description           = "Color",
                        Size     = new SizeValueObject(1, "Size"),
                        isSave   = true,
                        Quantity = 1,
                    }
                },
            };

            _mockExpenditureGoodReturnRepository
            .Setup(s => s.Query)
            .Returns(new List <GarmentExpenditureGoodReturnReadModel>().AsQueryable());
            _mockFinishedGoodStockRepository
            .Setup(s => s.Query)
            .Returns(new List <GarmentFinishedGoodStockReadModel>()
            {
                new GarmentFinishedGoodStockReadModel(finStockGuid)
            }.AsQueryable());

            GarmentExpenditureGood garmentExpenditureGood = new GarmentExpenditureGood(exGoodGuid, "no", null,
                                                                                       new UnitDepartmentId(placeGarmentExpenditureGoodReturnCommand.Unit.Id), null, null, placeGarmentExpenditureGoodReturnCommand.RONo, null, new GarmentComodityId(1),
                                                                                       null, null, new BuyerId(1), null, null, DateTimeOffset.Now, null, null, 0, null, false);

            GarmentExpenditureGoodItem garmentExpenditureGoodItem = new GarmentExpenditureGoodItem(
                exGoodItemGuid, exGoodGuid, finStockGuid, new SizeId(1), null, 1, 0, new UomId(1), null, "Color", 1, 1);

            _mockExpenditureGoodRepository
            .Setup(s => s.Query)
            .Returns(new List <GarmentExpenditureGoodReadModel>
            {
                garmentExpenditureGood.GetReadModel()
            }.AsQueryable());

            _mockExpenditureGoodItemRepository
            .Setup(s => s.Query)
            .Returns(new List <GarmentExpenditureGoodItemReadModel>
            {
                garmentExpenditureGoodItem.GetReadModel()
            }.AsQueryable());



            GarmentComodityPrice garmentComodity = new GarmentComodityPrice(
                Guid.NewGuid(),
                true,
                DateTimeOffset.Now,
                new UnitDepartmentId(placeGarmentExpenditureGoodReturnCommand.Unit.Id),
                placeGarmentExpenditureGoodReturnCommand.Unit.Code,
                placeGarmentExpenditureGoodReturnCommand.Unit.Name,
                new GarmentComodityId(placeGarmentExpenditureGoodReturnCommand.Comodity.Id),
                placeGarmentExpenditureGoodReturnCommand.Comodity.Code,
                placeGarmentExpenditureGoodReturnCommand.Comodity.Name,
                1000
                );

            _mockComodityPriceRepository
            .Setup(s => s.Query)
            .Returns(new List <GarmentComodityPriceReadModel>
            {
                garmentComodity.GetReadModel()
            }.AsQueryable());

            _mockExpenditureGoodReturnRepository
            .Setup(s => s.Update(It.IsAny <GarmentExpenditureGoodReturn>()))
            .Returns(Task.FromResult(It.IsAny <GarmentExpenditureGoodReturn>()));
            _mockExpenditureGoodReturnItemRepository
            .Setup(s => s.Update(It.IsAny <GarmentExpenditureGoodReturnItem>()))
            .Returns(Task.FromResult(It.IsAny <GarmentExpenditureGoodReturnItem>()));

            _mockFinishedGoodStockRepository
            .Setup(s => s.Update(It.IsAny <GarmentFinishedGoodStock>()))
            .Returns(Task.FromResult(It.IsAny <GarmentFinishedGoodStock>()));

            _mockFinishedGoodStockHistoryRepository
            .Setup(s => s.Update(It.IsAny <GarmentFinishedGoodStockHistory>()))
            .Returns(Task.FromResult(It.IsAny <GarmentFinishedGoodStockHistory>()));

            _mockExpenditureGoodItemRepository
            .Setup(s => s.Update(It.IsAny <GarmentExpenditureGoodItem>()))
            .Returns(Task.FromResult(It.IsAny <GarmentExpenditureGoodItem>()));

            //_mockExpenditureGoodRepository
            //    .Setup(s => s.Update(It.IsAny<GarmentExpenditureGood>()))
            //    .Returns(Task.FromResult(It.IsAny<GarmentExpenditureGood>()));

            _MockStorage
            .Setup(x => x.Save())
            .Verifiable();

            // Act
            var result = await unitUnderTest.Handle(placeGarmentExpenditureGoodReturnCommand, cancellationToken);

            // Assert
            result.Should().NotBeNull();
        }