public void Test_FormEditJobAssignment_Return_BadRequest_When_JobId_Is_Null()
        {
            // Arrange
            var jobAssignmentRepository = new Mock <IJobAssignmentRepository>();
            var truckDriverRepository   = new Mock <ITruckDriverRepository>();

            var controller = new JobAssignmentController(jobAssignmentRepository.Object, truckDriverRepository.Object);

            // Act
            var result  = controller.FormEditJobAssignment(null) as ActionResult;
            var jobNull = new HttpStatusCodeResult(HttpStatusCode.BadRequest);

            // Assert
            Assert.AreEqual(result.ToString(), jobNull.ToString());
        }
示例#2
0
        public void Test_DetailsStaff_Return_HttpBadRequest_When_StaffId_Equal_Null()
        {
            // Arrange
            var staff           = new Staff();
            var staffRepository = new Mock <IStaffRepository>();

            staffRepository.Setup(e => e.GetStaffById(null)).Returns(staff);
            var controller = new StaffController(staffRepository.Object);

            // Act
            var result      = controller.DetailsStaff(null) as ActionResult;
            var staffIdNull = new HttpStatusCodeResult(HttpStatusCode.BadRequest);

            // Assert
            Assert.AreEqual(result.ToString(), staffIdNull.ToString());
        }
        public void Test_DetailsTruckDriver_Return_HttpBadRequest_When_TruckDrivevrId_Equal_Null()
        {
            // Arrange
            var truckDriver           = new TruckDriver();
            var truckDriverRepository = new Mock <ITruckDriverRepository>();

            truckDriverRepository.Setup(e => e.GetTruckDriverById(null)).Returns(truckDriver);
            var controller = new TruckDriverController(truckDriverRepository.Object);

            // Act
            var result            = controller.DetailsTruckDriver(null) as ActionResult;
            var truckDriverIdNull = new HttpStatusCodeResult(HttpStatusCode.BadRequest);

            // Assert
            Assert.AreEqual(result.ToString(), truckDriverIdNull.ToString());
        }
示例#4
0
        public ActionResult OrderTokens(OrderTokensViewModel orderView)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    throw new Exception("All fields must be filled correctly!");
                }

                PartialUser logged_user = IsLoggedIn();
                if (logged_user == null)
                {
                    throw new Exception("Forbidden access!");
                }

                using (AuctionHouseModel db = new AuctionHouseModel())
                {
                    SystemParameter sp    = db.GetSystemParameters();
                    TokenOrder      order = new TokenOrder
                    {
                        id      = Guid.NewGuid(),
                        orderer = logged_user.email,
                        amount  = (int)orderView.Package,
                        price   = (int)orderView.Package * sp.T,
                        state   = "SUBMITTED"
                    };

                    db.TokenOrders.Add(order);
                    db.SaveChanges();

                    HttpStatusCodeResult service_result = TokenWebService(order.id);
                    if (service_result.StatusCode != 0xca)
                    {
                        throw new Exception(service_result.ToString());
                    }

                    User user = db.FindUser(logged_user.email);
                    user.tokens_amount += order.amount;
                    db.SaveChanges();
                }
            }
            catch (Exception error)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest, error.Message));
            }
            return(null);
        }
        public void Test_FormCreateJobAssignment_Return_HttpBadRequest_When_ShippingId_Equal_Null()
        {
            //Arrage
            var transportationInf = new TransportationInf();
            var mockTruckDriver   = new Mock <ITruckDriverRepository>();
            var mockJob           = new Mock <IJobAssignmentRepository>();

            var mockTrans = new Mock <ITransportationInfRepository>();

            mockTrans.Setup(m => m.GetTransportationInfById(null)).Returns(transportationInf);

            var controller = new TransportationInfController(mockTrans.Object, mockJob.Object, mockTruckDriver.Object);

            // Act
            var result         = controller.FormCreateJobAssignment(null) as ActionResult;
            var shippingIdNull = new HttpStatusCodeResult(HttpStatusCode.BadRequest);

            // Assert
            Assert.AreEqual(result.ToString(), shippingIdNull.ToString());
        }