public void InsertNewDetectedPlate_WhenConfidenceNotCorrect_ShouldThrowError() { //Arrange var fakeIQueryable = new List <DetectedLicensePlate>().AsQueryable(); var fakeDbSet = A.Fake <DbSet <DetectedLicensePlate> >(); var fakeHucaresContext = A.Fake <HucaresContext>(); A.CallTo(() => fakeHucaresContext.DetectedLicensePlates) .Returns(fakeDbSet); var fakeDbContextFactory = A.Fake <IDbContextFactory>(); A.CallTo(() => fakeDbContextFactory.BuildHucaresContext()) .Returns(fakeHucaresContext); var fakeMissingPlateHelper = A.Fake <IMissingPlateHelper>(); var detectedPlateHelper = new DetectedPlateHelper(fakeDbContextFactory, fakeMissingPlateHelper); //Act and Assert Assert.Throws <ArgumentException>(() => detectedPlateHelper.InsertNewDetectedPlate( "ABC001", new DateTime(2018, 09, 29), 1, "http://localhost:6969/images/cam01_21080929_235959", 101)); A.CallTo(() => fakeDbContextFactory.BuildHucaresContext()) .MustNotHaveHappened(); }
public IHttpActionResult AddDLP([FromBody] DemonstrationDlpInput input) { var imageLocation = ImageManipulator.SaveImage(input.CamId, input.DetectedDateTime, input.Img); var fileInfo = new FileInfo(imageLocation); var newLocation = ImageManipulator.MoveFileToPerm(fileInfo, input.DetectedDateTime); var imgUrl = LocationToUrlConverter.ConvertPathToUrl(fileInfo.Name, input.DetectedDateTime); var result = DetectedPlateHelper.InsertNewDetectedPlate(input.PlateNumber, input.DetectedDateTime, input.CamId, imgUrl, input.Confidence); return(Json(result)); }
public IHttpActionResult GenerateFakeDLPData() { var detectedPlateHelper = new DetectedPlateHelper(); detectedPlateHelper.InsertNewDetectedPlate("JEZ123", new DateTime(2018, 10, 22), 1, "ipfs://hucares.io/detections/camera/28/20181022", 0.86); detectedPlateHelper.InsertNewDetectedPlate("JEZ123", new DateTime(2018, 10, 22), 2, "ipfs://hucares.io/detections/camera/23/20181022", 0.92); detectedPlateHelper.InsertNewDetectedPlate("JEZ123", new DateTime(2018, 10, 22), 1, "ipfs://hucares.io/detections/camera/28/20181022", 0.73); detectedPlateHelper.InsertNewDetectedPlate("BDI911", new DateTime(2018, 10, 20), 1, "ipfs://hucares.io/detections/camera/28/20181022", 0.71); detectedPlateHelper.InsertNewDetectedPlate("BDI911", new DateTime(2018, 10, 21), 1, "ipfs://hucares.io/detections/camera/28/20181022", 0.98); detectedPlateHelper.InsertNewDetectedPlate("BDI911", new DateTime(2018, 10, 22), 1, "ipfs://hucares.io/detections/camera/28/20181022", 0.95); detectedPlateHelper.InsertNewDetectedPlate("BDI911", new DateTime(2018, 10, 23), 2, "ipfs://hucares.io/detections/camera/23/20181022", 0.78); detectedPlateHelper.InsertNewDetectedPlate("HAH666", new DateTime(2018, 10, 25), 2, "ipfs://hucares.io/detections/camera/23/20181022", 0.999); return(Json("Fake DLP data generated")); }
public void InsertNewDetectedPlate_WhenAllInfoCorrect_ShouldSucceedAndReturn() { //Arrange var fakeIQueryable = new List <DetectedLicensePlate>().AsQueryable(); var fakeDbSet = A.Fake <DbSet <DetectedLicensePlate> >(); var fakeHucaresContext = A.Fake <HucaresContext>(); A.CallTo(() => fakeHucaresContext.DetectedLicensePlates) .Returns(fakeDbSet); var fakeDbContextFactory = A.Fake <IDbContextFactory>(); A.CallTo(() => fakeDbContextFactory.BuildHucaresContext()) .Returns(fakeHucaresContext); var fakeMissingPlateHelper = A.Fake <IMissingPlateHelper>(); var detectedPlateHelper = new DetectedPlateHelper(fakeDbContextFactory, fakeMissingPlateHelper); //Act var expectedDetectedPlate = new DetectedLicensePlate() { PlateNumber = "ABC001", DetectedDateTime = new DateTime(2018, 09, 29), CamId = 1, ImgUrl = "http://localhost:6969/images/cam01_21080929_235959", Confidence = 75.75 }; var result = detectedPlateHelper.InsertNewDetectedPlate(expectedDetectedPlate.PlateNumber, expectedDetectedPlate.DetectedDateTime, expectedDetectedPlate.CamId, expectedDetectedPlate.ImgUrl, expectedDetectedPlate.Confidence); //Assert A.CallTo(() => fakeDbContextFactory.BuildHucaresContext()) .MustHaveHappenedOnceExactly(); A.CallTo(() => fakeDbSet.Add(result)) .MustHaveHappened(); A.CallTo(() => fakeHucaresContext.SaveChanges()) .MustHaveHappenedOnceExactly(); result.ShouldBe(expectedDetectedPlate); }