public void GetAllDetectedPlatesByCamera_WithDates_ShouldReturn()
        {
            //Arrange
            var expectedDetectedPlate = new DetectedLicensePlate()
            {
                Id = 0, CamId = 0, DetectedDateTime = new DateTime(2018, 10, 10)
            };

            var fakeDetectedPlateList = new List <DetectedLicensePlate>()
            {
                expectedDetectedPlate,
                new DetectedLicensePlate()
                {
                    Id = 1, CamId = 0, DetectedDateTime = new DateTime(2018, 09, 10)
                },
                new DetectedLicensePlate()
                {
                    Id = 2, CamId = 0, DetectedDateTime = new DateTime(2018, 11, 30)
                },
                new DetectedLicensePlate()
                {
                    Id = 3, CamId = 1, DetectedDateTime = new DateTime(2018, 10, 10)
                }
            };

            var fakeDbSetDetectedPlates = StorageTestsUtil.SetupFakeDbSet(fakeDetectedPlateList.AsQueryable());

            var fakeHucaresContext = A.Fake <HucaresContext>();

            A.CallTo(() => fakeHucaresContext.DetectedLicensePlates)
            .Returns(fakeDbSetDetectedPlates);

            var fakeDbContextFactory = A.Fake <IDbContextFactory>();

            A.CallTo(() => fakeDbContextFactory.BuildHucaresContext())
            .Returns(fakeHucaresContext);

            var fakeMissingPlateHelper = A.Fake <IMissingPlateHelper>();
            var detectedPlateHelper    = new DetectedPlateHelper(fakeDbContextFactory, fakeMissingPlateHelper);

            //Act
            var result = detectedPlateHelper.GetAllDetectedPlatesByCamera(cameraId: expectedDetectedPlate.CamId,
                                                                          startDateTime: new DateTime(2018, 10, 05), endDateTime: new DateTime(2018, 10, 15)).ToList();

            //Assert
            A.CallTo(() => fakeDbContextFactory.BuildHucaresContext()).MustHaveHappened();
            result.Count().ShouldBe(1);
            result.FirstOrDefault().ShouldBe(expectedDetectedPlate);
        }
        public void GetAllDetectedPlatesByCamera_WithStartLaterThanEnd_ShouldThrow()
        {
            //Arrange
            var fakeHucaresContext   = A.Fake <HucaresContext>();
            var fakeDbContextFactory = A.Fake <IDbContextFactory>();

            A.CallTo(() => fakeDbContextFactory.BuildHucaresContext())
            .Returns(fakeHucaresContext);

            var fakeMissingPlateHelper = A.Fake <IMissingPlateHelper>();
            var detectedPlateHelper    = new DetectedPlateHelper(fakeDbContextFactory, fakeMissingPlateHelper);

            //Act & assert
            Assert.Throws <ArgumentException>(() => detectedPlateHelper.GetAllDetectedPlatesByCamera(cameraId: 0,
                                                                                                     startDateTime: new DateTime(2018, 10, 05), endDateTime: new DateTime(2018, 09, 05)));
            A.CallTo(() => fakeDbContextFactory.BuildHucaresContext()).MustNotHaveHappened();
        }
Exemplo n.º 3
0
 public IHttpActionResult GetAllDetectedPlatesByCamera(int cameraId, DateTime?startDateTime = null,
                                                       DateTime?endDateTime = null)
 {
     return(Json(DetectedPlateHelper.GetAllDetectedPlatesByCamera(cameraId, startDateTime, endDateTime)));
 }