public async Task Handle_StateUnderTest_ExpectedBehavior()
        {
            // Arrange
            Guid          guid = Guid.NewGuid();
            List <string> Ids  = new List <string>();

            Ids.Add(guid.ToString());
            UpdateDatesGarmentCuttingInCommandHandler unitUnderTest = CreateUpdateDatesGarmentCuttingInCommandHandler();
            CancellationToken cancellationToken = CancellationToken.None;
            UpdateDatesGarmentCuttingInCommand UpdateGarmentCuttingInCommand = new UpdateDatesGarmentCuttingInCommand(
                Ids, DateTimeOffset.Now);

            _mockCuttingInRepository
            .Setup(s => s.Query)
            .Returns(new List <GarmentCuttingInReadModel>()
            {
                new GarmentCuttingInReadModel(guid)
            }.AsQueryable());

            _mockCuttingInRepository
            .Setup(s => s.Update(It.IsAny <GarmentCuttingIn>()))
            .Returns(Task.FromResult(It.IsAny <GarmentCuttingIn>()));

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

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

            // Assert
            result.Should().BeGreaterThan(0);
        }
示例#2
0
        public async Task Put_Dates_StateUnderTest_ExpectedBehavior_BadRequest()
        {
            // Arrange
            var           unitUnderTest = CreateGarmentCuttingInController();
            Guid          sewingOutGuid = Guid.NewGuid();
            List <string> ids           = new List <string>();

            ids.Add(sewingOutGuid.ToString());

            UpdateDatesGarmentCuttingInCommand command = new UpdateDatesGarmentCuttingInCommand(ids, DateTimeOffset.Now.AddDays(3));

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

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

            UpdateDatesGarmentCuttingInCommand command2 = new UpdateDatesGarmentCuttingInCommand(ids, DateTimeOffset.MinValue);

            // Act
            var result1 = await unitUnderTest.UpdateDates(command2);

            // Assert
            Assert.Equal((int)HttpStatusCode.BadRequest, GetStatusCode(result1));
        }
示例#3
0
        public async Task <IActionResult> UpdateDates([FromBody] UpdateDatesGarmentCuttingInCommand command)
        {
            VerifyUser();

            if (command.Date == null || command.Date == DateTimeOffset.MinValue)
            {
                return(BadRequest(new
                {
                    code = HttpStatusCode.BadRequest,
                    error = "Tanggal harus diisi"
                }));
            }
            else if (command.Date.Date > DateTimeOffset.Now.Date)
            {
                return(BadRequest(new
                {
                    code = HttpStatusCode.BadRequest,
                    error = "Tanggal tidak boleh lebih dari hari ini"
                }));
            }

            var order = await Mediator.Send(command);

            return(Ok());
        }
示例#4
0
        public async Task Put_Dates_StateUnderTest_ExpectedBehavior()
        {
            // Arrange
            var           unitUnderTest = CreateGarmentCuttingInController();
            Guid          sewingOutGuid = Guid.NewGuid();
            List <string> ids           = new List <string>();

            ids.Add(sewingOutGuid.ToString());

            UpdateDatesGarmentCuttingInCommand command = new UpdateDatesGarmentCuttingInCommand(ids, DateTimeOffset.Now);

            _MockMediator
            .Setup(s => s.Send(command, It.IsAny <CancellationToken>()))
            .ReturnsAsync(1);

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

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