Beispiel #1
0
        public void should_success_instantiate()
        {
            Guid            id   = Guid.NewGuid();
            GarmentSewingDO item = new GarmentSewingDO(new GarmentSewingDOReadModel(id));

            item.Modify();
            Assert.NotNull(item);
        }
Beispiel #2
0
 public GarmentSewingDOListDto(GarmentSewingDO garmentSewingDO)
 {
     Id           = garmentSewingDO.Identity;
     SewingDONo   = garmentSewingDO.SewingDONo;
     CuttingOutId = garmentSewingDO.CuttingOutId;
     UnitFrom     = new UnitDepartment(garmentSewingDO.UnitFromId.Value, garmentSewingDO.UnitFromCode, garmentSewingDO.UnitFromName);
     Unit         = new UnitDepartment(garmentSewingDO.UnitId.Value, garmentSewingDO.UnitCode, garmentSewingDO.UnitName);
     RONo         = garmentSewingDO.RONo;
     Article      = garmentSewingDO.Article;
     Comodity     = new GarmentComodity(garmentSewingDO.ComodityId.Value, garmentSewingDO.ComodityCode, garmentSewingDO.ComodityName);
     SewingDODate = garmentSewingDO.SewingDODate;
     CreatedBy    = garmentSewingDO.AuditTrail.CreatedBy;
     Items        = new List <GarmentSewingDOItemDto>();
 }
Beispiel #3
0
        public async Task Handle_StateUnderTest_ExpectedBehavior()
        {
            // Arrange
            Guid id = Guid.NewGuid();
            PlaceGarmentSewingDOCommandHandler unitUnderTest = CreatePlaceGarmentSewingDOCommandHandler();
            CancellationToken cancellationToken = CancellationToken.None;

            _mockGarmentSewingDOItemRepository
            .Setup(s => s.Update(It.IsAny <GarmentSewingDOItem>()))
            .Returns(Task.FromResult(It.IsAny <GarmentSewingDOItem>()));

            GarmentSewingDO garmentSewingDO = new GarmentSewingDO(id, "sewingDONo", id, new UnitDepartmentId(1), "unitFromCode", "unitFromName", new UnitDepartmentId(1), "unitCode", "unitName", "roNo", "article", new GarmentComodityId(1), "comodityCode", "comodityName", DateTimeOffset.Now);

            _mockGarmentSewingDORepository
            .Setup(s => s.Query)
            .Returns(new List <GarmentSewingDOReadModel>
            {
                garmentSewingDO.GetReadModel()
            }.AsQueryable());

            _mockGarmentSewingDORepository
            .Setup(s => s.Update(It.IsAny <GarmentSewingDO>()))
            .Returns(Task.FromResult(It.IsAny <GarmentSewingDO>()));

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

            // Act
            PlaceGarmentSewingDOCommand request = new PlaceGarmentSewingDOCommand()
            {
                Article  = "Article",
                Comodity = new GarmentComodity()
                {
                    Id   = 1,
                    Code = "Code",
                    Name = "Name"
                },
                CuttingOutId = id,
                RONo         = "RONo",
                SewingDODate = DateTimeOffset.Now,
                SewingDONo   = "SewingDONo",
                Unit         = new UnitDepartment()
                {
                    Id   = 1,
                    Code = "Code",
                    Name = "Name"
                },
                UnitFrom = new UnitDepartment()
                {
                    Id   = 1,
                    Code = "Code",
                    Name = "Name"
                },
                Items = new List <GarmentSewingDOItemValueObject>()
                {
                    new GarmentSewingDOItemValueObject()
                    {
                        Color              = "Color",
                        BasicPrice         = 1,
                        CuttingOutDetailId = id,
                        CuttingOutItemId   = id,
                        DesignColor        = "DesignColor",
                        Id      = id,
                        Price   = 1,
                        Product = new Product()
                        {
                            Id   = 1,
                            Code = "Code",
                            Name = "Name"
                        },
                        Quantity          = 1,
                        RemainingQuantity = 1,
                        SewingDOId        = id,
                        Size = new SizeValueObject()
                        {
                            Id   = 1,
                            Size = "1"
                        },
                        Uom = new Uom()
                        {
                            Id   = 1,
                            Unit = "Unit"
                        }
                    }
                }
            };
            var result = await unitUnderTest.Handle(request, cancellationToken);

            // Assert
            result.Should().NotBeNull();
        }
Beispiel #4
0
        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);
        }
Beispiel #5
0
        public async Task Handle_StateUnderTest_ExpectedBehavior()
        {
            // Arrange
            Guid cuttingInGuid        = Guid.NewGuid();
            Guid cuttingOutGuid       = Guid.NewGuid();
            Guid cuttingInDetailGuid  = Guid.NewGuid();
            Guid sewingDOGuid         = Guid.NewGuid();
            Guid cuttingOutDetailGuid = Guid.NewGuid();
            Guid cuttingOutItemGuid   = Guid.NewGuid();
            RemoveGarmentCuttingOutCommandHandler unitUnderTest = CreateRemoveGarmentCuttingOutCommandHandler();
            CancellationToken cancellationToken = CancellationToken.None;
            RemoveGarmentCuttingOutCommand RemoveGarmentCuttingOutCommand = new RemoveGarmentCuttingOutCommand(cuttingOutGuid);

            _mockCuttingOutRepository
            .Setup(s => s.Query)
            .Returns(new List <GarmentCuttingOutReadModel>()
            {
                new GarmentCuttingOutReadModel(cuttingOutGuid)
            }.AsQueryable());
            _mockCuttingOutItemRepository
            .Setup(s => s.Find(It.IsAny <Expression <Func <GarmentCuttingOutItemReadModel, bool> > >()))
            .Returns(new List <GarmentCuttingOutItem>()
            {
                new GarmentCuttingOutItem(cuttingOutItemGuid, cuttingInGuid, cuttingInDetailGuid, cuttingOutGuid, new ProductId(1), null, null, null, 0)
            });

            _mockCuttingOutDetailRepository
            .Setup(s => s.Find(It.IsAny <Expression <Func <GarmentCuttingOutDetailReadModel, bool> > >()))
            .Returns(new List <GarmentCuttingOutDetail>()
            {
                new GarmentCuttingOutDetail(cuttingOutDetailGuid, Guid.Empty, new SizeId(1), null, null, 0, 0, new UomId(1), null, 0, 0)
            });

            _mockCuttingInDetailRepository
            .Setup(s => s.Query)
            .Returns(new List <GarmentCuttingInDetailReadModel>
            {
                new GarmentCuttingInDetailReadModel(cuttingInDetailGuid)
            }.AsQueryable());

            GarmentSewingDO garmentSewingDO = new GarmentSewingDO(
                sewingDOGuid, null, cuttingOutGuid, new UnitDepartmentId(1), null, null, new UnitDepartmentId(1), null,
                null, null, null, new GarmentComodityId(1), null, null, DateTimeOffset.Now);

            _mockSewingDORepository
            .Setup(s => s.Query)
            .Returns(new List <GarmentSewingDOReadModel>
            {
                garmentSewingDO.GetReadModel()
            }.AsQueryable());

            //_mockSewingDORepository
            //    .Setup(s => s.Query)
            //    .Returns(new List<GarmentSewingDOReadModel>()
            //    {
            //        new GarmentSewingDOReadModel(sewingDOGuid)
            //    }.AsQueryable());
            _mockSewingDOItemRepository
            .Setup(s => s.Find(It.IsAny <Expression <Func <GarmentSewingDOItemReadModel, bool> > >()))
            .Returns(new List <GarmentSewingDOItem>()
            {
                new GarmentSewingDOItem(Guid.Empty, sewingDOGuid, cuttingOutDetailGuid, cuttingOutItemGuid, new ProductId(1), null, null, null, new SizeId(1), null, 0, new UomId(1), null, null, 0, 0, 0)
            });

            _mockCuttingOutRepository
            .Setup(s => s.Update(It.IsAny <GarmentCuttingOut>()))
            .Returns(Task.FromResult(It.IsAny <GarmentCuttingOut>()));
            _mockCuttingOutItemRepository
            .Setup(s => s.Update(It.IsAny <GarmentCuttingOutItem>()))
            .Returns(Task.FromResult(It.IsAny <GarmentCuttingOutItem>()));
            _mockCuttingOutDetailRepository
            .Setup(s => s.Update(It.IsAny <GarmentCuttingOutDetail>()))
            .Returns(Task.FromResult(It.IsAny <GarmentCuttingOutDetail>()));
            _mockCuttingInDetailRepository
            .Setup(s => s.Update(It.IsAny <GarmentCuttingInDetail>()))
            .Returns(Task.FromResult(It.IsAny <GarmentCuttingInDetail>()));

            _mockSewingDORepository
            .Setup(s => s.Update(It.IsAny <GarmentSewingDO>()))
            .Returns(Task.FromResult(It.IsAny <GarmentSewingDO>()));
            _mockSewingDOItemRepository
            .Setup(s => s.Update(It.IsAny <GarmentSewingDOItem>()))
            .Returns(Task.FromResult(It.IsAny <GarmentSewingDOItem>()));

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

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

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