예제 #1
0
 public virtual IActionResult SubmitParcel([FromBody] Parcel parcel)
 {
     try
     {
         var           BLmapped      = _mapper.Map <BL.Parcel>(parcel);
         NewParcelInfo newParcelInfo = _senderLogic.SubmitParcelIntoBL(BLmapped);
         return(StatusCode(200, newParcelInfo));
     }
     catch (BL.BLException exc)
     {
         return(handleReturn(System.Reflection.MethodBase.GetCurrentMethod().Name, exc));
     }
     catch (Exception exc)
     {
         return(handleReturn(System.Reflection.MethodBase.GetCurrentMethod().Name, exc));
     }
 }
예제 #2
0
        public void TransitionParcel_Should_Return_StatusCode_200_When_Succeeds()
        {
            // Arrange
            //var controller = new LogisticsPartnerApi(_mockPartner.Object, _mockSender.Object, _mapper, new LoggerFactory().CreateLogger<LogisticsPartnerApi>());
            var           parcel     = new Parcel();
            var           trackingId = "PYJRB4HZ6";
            NewParcelInfo p          = new NewParcelInfo()
            {
                TrackingId = trackingId
            };

            _mockSender.Setup(x => x.SubmitParcelIntoBL(It.IsAny <BL.Parcel>())).Returns(p);
            _mockPartner.Setup(x => x.TransferParcelPartner(It.IsAny <string>(), It.IsAny <string>()));

            // Act
            var result = (ObjectResult)_controller.TransitionParcel(parcel, trackingId);

            // Assert
            Assert.AreEqual(200, result.StatusCode);
        }
        public void SubmitParcel_Should_Return_StatusCode_400_When_unsuccessfully_submitted_parcel()
        {
            // Arrange
            BL.Parcel     parcelBL   = new BL.Parcel();
            var           trackingId = "PYJRB4HZ6";
            NewParcelInfo p          = new NewParcelInfo()
            {
                TrackingId = trackingId
            };

            _mock.Setup(x => x.SubmitParcelIntoBL(
                            It.IsAny <BL.Parcel>()))
            .Throws(new Exception());

            // Act
            ObjectResult result = (ObjectResult)_controller.SubmitParcel(parcel);

            // Assert
            Assert.IsInstanceOf <BadRequestObjectResult>(result);
        }
예제 #4
0
        public virtual IActionResult TransitionParcel([FromBody] Parcel parcel, [FromRoute][Required][RegularExpression("^[A-Z0-9]{9}$")] string trackingId)
        {
            try
            {
                var BLmapped = _mapper.Map <BL.Parcel>(parcel);
                BLmapped.TrackingId = trackingId;
                NewParcelInfo newParcelInfo = _senderLogic.SubmitParcelIntoBL(BLmapped);
                //If the trackingId already exists we generate a new one and save the old one into the db
                _recLogic.TransferParcelPartner(newParcelInfo.TrackingId, trackingId);

                return(StatusCode(200, newParcelInfo));
            }
            catch (BL.BLException exc)
            {
                return(handleReturn(System.Reflection.MethodBase.GetCurrentMethod().Name, exc));
            }
            catch (Exception exc)
            {
                return(handleReturn(System.Reflection.MethodBase.GetCurrentMethod().Name, exc));
            }
        }
        public void SubmitParcel_Should_Return_StatusCode_200_When_successfully_submitted_parcel()
        {
            // Arrange
            //var newParcelInfo = Builder<NewParcelInfo>.CreateNew().Build();
            BL.Parcel     parcelBL   = new BL.Parcel();
            var           trackingId = "PYJRB4HZ6";
            NewParcelInfo p          = new NewParcelInfo()
            {
                TrackingId = trackingId
            };

            _mock.Setup(x => x.SubmitParcelIntoBL(
                            It.IsAny <BL.Parcel>()))
            .Returns(p);

            // Act
            ObjectResult result = (ObjectResult)_controller.SubmitParcel(parcel);

            // Assert
            Assert.NotNull(result);
            Assert.AreEqual(200, result.StatusCode);
        }