public async Task <IActionResult> Post([FromBody] PlaceGarmentPreparingCommand command)
        {
            try
            {
                VerifyUser();

                var garmentPreparingValidation = _garmentPreparingRepository.Find(o => o.UENId == command.UENId && o.UENNo == command.UENNo && o.UnitId == command.Unit.Id &&
                                                                                  o.ProcessDate == command.ProcessDate && o.RONo == command.RONo && o.Article == command.Article && o.IsCuttingIn == command.IsCuttingIn).Select(o => new GarmentPreparingDto(o)).FirstOrDefault();
                if (garmentPreparingValidation != null)
                {
                    return(BadRequest(new
                    {
                        code = HttpStatusCode.BadRequest,
                        error = "Data sudah ada"
                    }));
                }

                var order = await Mediator.Send(command);

                await PutGarmentUnitExpenditureNoteCreate(command.UENId);

                return(Ok(order.Identity));
            }
            catch (Exception ex)
            {
                return(StatusCode((int)HttpStatusCode.InternalServerError, ex.Message));
            }
        }
        public async Task Post_Return_InternalServerError()
        {
            // Arrange
            var id            = Guid.NewGuid();
            var unitUnderTest = CreateGarmentPreparingController();

            PlaceGarmentPreparingCommand command = new PlaceGarmentPreparingCommand();

            command.UENId = 1;

            _mockGarmentPreparingRepository
            .Setup(s => s.Find(It.IsAny <Expression <Func <GarmentPreparingReadModel, bool> > >()))
            .Returns(new List <GarmentPreparing>()
            {
            });

            _MockMediator
            .Setup(s => s.Send(It.IsAny <PlaceGarmentPreparingCommand>(), It.IsAny <CancellationToken>()))
            .Throws(new Exception());

            // Act
            var result = await unitUnderTest.Post(command);

            // Assert
            Assert.Equal((int)HttpStatusCode.InternalServerError, GetStatusCode(result));
        }
        public async Task Post_Return_BadRequest()
        {
            // Arrange
            var id            = Guid.NewGuid();
            var unitUnderTest = CreateGarmentPreparingController();

            PlaceGarmentPreparingCommand command = new PlaceGarmentPreparingCommand();

            command.UENId = 1;

            _mockGarmentPreparingRepository
            .Setup(s => s.Find(It.IsAny <Expression <Func <GarmentPreparingReadModel, bool> > >()))
            .Returns(new List <GarmentPreparing>()
            {
                new GarmentPreparing(id, 1, "uenNo", new UnitDepartmentId(1), "unitCode", "unitName", DateTimeOffset.Now, "roNo", "article", true, new Domain.Shared.ValueObjects.BuyerId(1), null, null)
            });



            // Act
            var result = await unitUnderTest.Post(command);

            // Assert
            Assert.Equal((int)HttpStatusCode.BadRequest, GetStatusCode(result));
        }
Esempio n. 4
0
        public async Task Handle_StateUnderTest_ExpectedBehavior()
        {
            // Arrange
            Guid preparingItemGuid = Guid.NewGuid();
            PlaceGarmentPreparingCommandHandler unitUnderTest         = CreatePlaceGarmentPreparingCommandHandler();
            CancellationToken            cancellationToken            = CancellationToken.None;
            PlaceGarmentPreparingCommand placeGarmentPreparingCommand = new PlaceGarmentPreparingCommand()
            {
                UENId       = 1,
                UENNo       = "test",
                RONo        = "RONo",
                Unit        = new UnitDepartment(1, "UnitCode", "UnitName"),
                Article     = "Test",
                ProcessDate = DateTimeOffset.Now,
                IsCuttingIn = false,
                Buyer       = new Domain.Shared.ValueObjects.Buyer(1, "buy", "buy"),
                Items       = new List <GarmentPreparingItemValueObject>
                {
                    new GarmentPreparingItemValueObject
                    {
                        UENItemId         = 1,
                        Product           = new Product(1, "ProductCode", "ProductName"),
                        DesignColor       = "test",
                        Quantity          = 1,
                        Uom               = new Uom(1, "UomUnit"),
                        FabricType        = "Test",
                        RemainingQuantity = 1,
                        BasicPrice        = 1,
                        ROSource          = "ro"
                    }
                },
            };

            //_mockPreparingRepository
            //    .Setup(s => s.Find(It.IsAny<Expression<Func<GarmentPreparingReadModel, bool>>>()))
            //    .Returns(new List<GarmentPreparing>());

            _mockPreparingRepository
            .Setup(s => s.Update(It.IsAny <GarmentPreparing>()))
            .Returns(Task.FromResult(It.IsAny <GarmentPreparing>()));

            _mockPreparingItemRepository
            .Setup(s => s.Update(It.IsAny <GarmentPreparingItem>()))
            .Returns(Task.FromResult(It.IsAny <GarmentPreparingItem>()));


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

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

            // Assert
            result.Should().NotBeNull();
        }
        public void Place_HaveError()
        {
            // Arrange
            var unitUnderTest = new PlaceGarmentPreparingCommand();

            // Action
            var validator = GetValidationRules();
            var result    = validator.TestValidate(unitUnderTest);

            // Assert
            result.ShouldHaveError();
        }
        public void Place_NotHaveError()
        {
            // Arrange
            Guid id            = Guid.NewGuid();
            var  unitUnderTest = new PlaceGarmentPreparingCommand()
            {
                Article         = "Article",
                IsCuttingIn     = true,
                ProcessDate     = DateTimeOffset.Now,
                ExpenditureDate = DateTimeOffset.Now,
                RONo            = "RONo",
                Unit            = new UnitDepartment()
                {
                    Id   = 1,
                    Code = "Code",
                    Name = "Name"
                },
                UENId = 1,
                UENNo = "UENNo",
                Items = new List <GarmentPreparingItemValueObject>()
                {
                    new GarmentPreparingItemValueObject()
                    {
                        BasicPrice         = 1,
                        DesignColor        = "DesignColor",
                        FabricType         = "FabricType",
                        GarmentPreparingId = id,
                        Product            = new Product()
                        {
                            Id   = 1,
                            Code = "Code",
                            Name = "Name"
                        },
                        Quantity          = 1,
                        RemainingQuantity = 2,
                        UENItemId         = 1,
                        Uom = new Uom()
                        {
                            Id   = 1,
                            Unit = "Unit"
                        }
                    }
                }
            };
            // Act
            var validator = GetValidationRules();
            var result    = validator.TestValidate(unitUnderTest);

            // Assert
            result.ShouldNotHaveError();
        }
        public void Place_HaveError_Date()
        {
            // Arrange
            var validator     = GetValidationRules();
            var unitUnderTest = new PlaceGarmentPreparingCommand();

            unitUnderTest.ProcessDate     = DateTimeOffset.Now.AddDays(-7);
            unitUnderTest.ExpenditureDate = DateTimeOffset.Now;

            // Action
            var result = validator.TestValidate(unitUnderTest);

            // Assert
            result.ShouldHaveError();
        }
        public async Task Post_StateUnderTest_ExpectedBehavior()
        {
            // Arrange
            var unitUnderTest = CreateGarmentPreparingController();

            PlaceGarmentPreparingCommand command = new PlaceGarmentPreparingCommand();

            command.UENId = 1;

            _mockGarmentPreparingRepository
            .Setup(s => s.Find(It.IsAny <Expression <Func <GarmentPreparingReadModel, bool> > >()))
            .Returns(new List <GarmentPreparing>());

            _MockMediator
            .Setup(s => s.Send(It.IsAny <PlaceGarmentPreparingCommand>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(new GarmentPreparing(Guid.NewGuid(), 0, null, new UnitDepartmentId(1), null, null, DateTimeOffset.Now, "RONo", null, false, new Domain.Shared.ValueObjects.BuyerId(1), null, null));

            // Act
            var result = await unitUnderTest.Post(command);

            // Assert
            Assert.Equal((int)HttpStatusCode.OK, GetStatusCode(result));
        }