public void CreateInspectionTest() { List <DamageDTO> damages = this.CreateDamages(); UserDTO user = this.CreateUser(); VehicleDTO vehicle = this.CreateVehicle(); InspectionDTO inspection = new InspectionDTO(); inspection.Damages = damages; inspection.CreatorUserName = user.UserName; inspection.Date = DateTime.Now; inspection.Location = "Puerto 1"; inspection.IdVehicle = vehicle.Vin; UserDTO userDTO = this.CreateUser(); Guid token = Guid.NewGuid(); var mockInspectionService = new Mock <InspectionService>(); mockInspectionService.Setup(b => b.CreateInspection(inspection)).Verifiable(); var mockUserService = new Mock <UserService>(); mockUserService.Setup(us => us.GetUserLoggedIn(token)).Returns(userDTO); InspectionController inspectionController = new InspectionController(mockInspectionService.Object, mockUserService.Object); inspectionController.Request = createInspectionControllerRequest(); this.addTokenHeaderToRequest(inspectionController.Request, token); ResponseMessageResult response = (ResponseMessageResult)inspectionController.Post(inspection); Assert.AreEqual(HttpStatusCode.OK, response.Response.StatusCode); }
public void ErrorCreateInspectionWithoutTokenTest() { InspectionDTO inspection = new InspectionDTO(); var mockInspectionService = new Mock <InspectionService>(); mockInspectionService.Setup(b => b.CreateInspection(inspection)).Verifiable(); InspectionController inspectionController = new InspectionController(mockInspectionService.Object, null); inspectionController.Request = createInspectionControllerRequest(); ResponseMessageResult response = (ResponseMessageResult)inspectionController.Post(inspection); Assert.AreEqual(HttpStatusCode.BadRequest, response.Response.StatusCode); }
public void ErrorCreateInspectionBadTokenTest() { InspectionDTO inspection = new InspectionDTO(); Guid token = Guid.NewGuid(); var mockInspectionService = new Mock <InspectionService>(); mockInspectionService.Setup(b => b.CreateInspection(inspection)).Verifiable(); var mockUserService = new Mock <UserService>(); mockUserService.Setup(us => us.GetUserLoggedIn(token)).Throws(new UserNotExistException()); InspectionController inspectionController = new InspectionController(mockInspectionService.Object, mockUserService.Object); inspectionController.Request = createInspectionControllerRequest(); ResponseMessageResult response = (ResponseMessageResult)inspectionController.Post(inspection); Assert.AreEqual(HttpStatusCode.BadRequest, response.Response.StatusCode); }