Beispiel #1
0
        public async Task <IActionResult> UpdateDates([FromBody] UpdateDatesGarmentSewingInCommand 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());
        }
        public async Task Put_Dates_StateUnderTest_ExpectedBehavior_BadRequest()
        {
            // Arrange
            var           unitUnderTest = CreateGarmentSewingInController();
            Guid          sewingOutGuid = Guid.NewGuid();
            List <string> ids           = new List <string>();

            ids.Add(sewingOutGuid.ToString());

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

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

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

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

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

            // Assert
            Assert.Equal((int)HttpStatusCode.BadRequest, GetStatusCode(result1));
        }
Beispiel #3
0
        public async Task Handle_StateUnderTest_ExpectedBehavior()
        {
            // Arrange
            Guid          guid = Guid.NewGuid();
            List <string> Ids  = new List <string>();

            Ids.Add(guid.ToString());
            UpdateDatesGarmentSewingInCommandHandler unitUnderTest = CreateUpdateDatesGarmentSewingInCommandHandler();
            CancellationToken cancellationToken = CancellationToken.None;
            UpdateDatesGarmentSewingInCommand UpdateGarmentSewingInCommand = new UpdateDatesGarmentSewingInCommand(
                Ids, DateTimeOffset.Now);

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

            _mockSewingInRepository
            .Setup(s => s.Update(It.IsAny <GarmentSewingIn>()))
            .Returns(Task.FromResult(It.IsAny <GarmentSewingIn>()));

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

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

            // Assert
            result.Should().BeGreaterThan(0);
        }
        public async Task Put_Dates_StateUnderTest_ExpectedBehavior()
        {
            // Arrange
            var           unitUnderTest = CreateGarmentSewingInController();
            Guid          sewingOutGuid = Guid.NewGuid();
            List <string> ids           = new List <string>();

            ids.Add(sewingOutGuid.ToString());

            UpdateDatesGarmentSewingInCommand command = new UpdateDatesGarmentSewingInCommand(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));
        }