Example #1
0
        public ActionResult AddOrUpdate(ClassroomModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var isCreated = model.Id == Guid.Empty;
            var classroom = new Classrooms();

            if (!isCreated)
            {
                classroom = ClassroomRepository.GetById(model.Id);
            }

            classroom.Title            = model.Title;
            classroom.Establishment_Id = model.Establishment_Id;
            classroom.Establishments   = EstablishmentRepository.GetById(model.Establishment_Id);
            classroom.User_Id          = model.UserId;
            classroom.Users            = UserRepository.GetById(model.UserId);
            classroom.Year_Id          = model.YearId;
            classroom.Years            = YearRepository.GetById(model.YearId);

            if (isCreated)
            {
                ClassroomRepository.Add(classroom);
            }
            ClassroomRepository.Save();

            return(Redirect(Url.Action("Get", "Classroom", new { id = classroom.Id })));
        }
Example #2
0
        public async Task ShouldGetSavedEstablishment()
        {
            var options = new DbContextOptionsBuilder <WhereToBiteContext>()
                          .UseInMemoryDatabase("test3")
                          .Options;

            var whereToBiteContext = new WhereToBiteContext(options);

            var establishmentRepository = new EstablishmentRepository(whereToBiteContext);

            var expectedEstablishment = new Establishment(1,
                                                          "test",
                                                          "Restaurant",
                                                          string.Empty,
                                                          "Pass",
                                                          Point.Empty);

            await whereToBiteContext.Establishments.AddAsync(expectedEstablishment);

            await whereToBiteContext.SaveChangesAsync();

            var actual = await establishmentRepository.GetAsync(expectedEstablishment.Id, CancellationToken.None);

            Assert.Equal(expectedEstablishment.Address, actual.Address);
            Assert.Equal(expectedEstablishment.Name, actual.Name);
            Assert.Equal(expectedEstablishment.Type, actual.Type);
            Assert.Equal(expectedEstablishment.EstablishmentStatus, actual.EstablishmentStatus);
        }
Example #3
0
        public ActionResult AddOrUpdate(EstablishmentModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var isCreated     = model.Id == Guid.Empty;
            var establishment = new Establishments();

            if (!isCreated)
            {
                establishment = EstablishmentRepository.GetById(model.Id);
            }

            establishment.Name        = model.Name;
            establishment.Academie_Id = model.AcademyId;
            establishment.Academies   = AcademyRepository.GetByName(model.Academy);
            establishment.Address     = model.Address;
            establishment.PostCode    = model.PostCode;
            establishment.Town        = model.Town;
            establishment.User_Id     = model.UserId;
            establishment.Users       = UserRepository.GetById(model.UserId);

            if (isCreated)
            {
                EstablishmentRepository.Add(establishment);
            }
            EstablishmentRepository.Save();

            return(Redirect(Url.Action("Get", "Establishment", new { id = establishment.Id })));
        }
Example #4
0
        public ActionResult GetAll()
        {
            var models = EstablishmentRepository.All()
                         .OrderBy(e => e.Academies.Name)
                         .Select(e => EstablishmentModel.ToModel(e));

            return(View(models));
        }
Example #5
0
        public EstablishmentController()
        {
            var entities = new Entities.Entities();

            EstablishmentRepository = new EstablishmentRepository(entities);
            AcademyRepository       = new AcademyRepository(entities);
            UserRepository          = new UserRepository(entities);
        }
Example #6
0
        public async Task ShouldPersistEstablishment()
        {
            var options = new DbContextOptionsBuilder <WhereToBiteContext>()
                          .UseInMemoryDatabase("test2")
                          .Options;

            var whereToBiteContext = new WhereToBiteContext(options);

            var establishmentRepository = new EstablishmentRepository(whereToBiteContext);

            var expectedEstablishment = new Establishment(1,
                                                          "test",
                                                          "Restaurant",
                                                          string.Empty,
                                                          "Pass",
                                                          Point.Empty);

            var infraction = new Infraction("M - Minor", "Ticket", DateTime.Now, "", 0m);
            var inspection = new Inspection("Pass", DateTime.Now);

            inspection.AddNewInfractions(new[] { infraction });
            var inspections = new[] { inspection };


            expectedEstablishment.AddNewInspections(inspections);

            await establishmentRepository.AddIfNotExistsAsync(expectedEstablishment, CancellationToken.None);

            await establishmentRepository.UnitOfWork.SaveEntitiesAsync();

            var actualEstablishment = whereToBiteContext.Establishments.FirstOrDefault();

            Assert.NotNull(actualEstablishment);
            Assert.Equal(expectedEstablishment.DineSafeId, actualEstablishment.DineSafeId);
            Assert.Equal(expectedEstablishment.Name, actualEstablishment.Name);
            Assert.Equal(expectedEstablishment.Type, actualEstablishment.Type);
            Assert.Equal(expectedEstablishment.EstablishmentStatus, actualEstablishment.EstablishmentStatus);

            Assert.NotEmpty(actualEstablishment.Inspections);

            var expectedInspection = expectedEstablishment.Inspections.FirstOrDefault();
            var actualInspection   = actualEstablishment.Inspections.FirstOrDefault();

            Assert.NotNull(expectedInspection);
            Assert.NotNull(actualInspection);

            Assert.Equal(expectedInspection.InspectionStatus, actualInspection.InspectionStatus);

            var expectedInfraction = expectedInspection.Infractions.FirstOrDefault();
            var actualInfraction   = actualInspection.Infractions.FirstOrDefault();

            Assert.NotNull(expectedInfraction);
            Assert.NotNull(actualInfraction);

            Assert.Equal(expectedInfraction.InfractionAction, actualInfraction.InfractionAction);
            Assert.Equal(expectedInfraction.Severity, actualInfraction.Severity);
            Assert.Equal(expectedInfraction.AmountFined, actualInfraction.AmountFined);
        }
Example #7
0
        public async Task ShouldGetEstablishmentsWithinRadius()
        {
            var options = new DbContextOptionsBuilder <WhereToBiteContext>()
                          .UseInMemoryDatabase("test4")
                          .Options;

            var whereToBiteContext = new WhereToBiteContext(options);

            var establishmentRepository = new EstablishmentRepository(whereToBiteContext);

            var expectedEstablishment = new Establishment(
                1,
                "test",
                "Restaurant",
                string.Empty,
                "Pass",
                new Point(-79.45886, 43.65493));

            var expectedInspection = new Inspection(InspectionStatus.Pass.ToString(), DateTime.Today.AddDays(-10));

            var expectedInfraction = new Infraction(
                "C - Crucial",
                "Ticket",
                expectedInspection.Date,
                "Fine",
                10000.00m);

            var expectedInfractionTwo = new Infraction(
                "M - Minor",
                "Ticket",
                expectedInspection.Date,
                "Fine",
                10.00m);

            expectedInspection.AddNewInfractions(new [] { expectedInfraction, expectedInfractionTwo });

            expectedEstablishment.AddNewInspections(new [] { expectedInspection });

            await whereToBiteContext.Establishments.AddAsync(expectedEstablishment);

            await whereToBiteContext.SaveChangesAsync();

            var actual = await establishmentRepository.GetAllWithinRadiusAsync(
                1000,
                new Point(-79.46377746577373, 43.655427942971166),
                CancellationToken.None);

            var actualEstablishment = Assert.Single(actual);

            Assert.NotNull(actualEstablishment);
            Assert.Equal(expectedEstablishment.Address, actualEstablishment.Address);
            Assert.Equal(expectedEstablishment.Name, actualEstablishment.Name);
            Assert.Equal(expectedEstablishment.Type, actualEstablishment.Type);
            Assert.Equal(expectedEstablishment.EstablishmentStatus, actualEstablishment.EstablishmentStatus);
            Assert.Equal(
                expectedInfraction.AmountFined + expectedInfractionTwo.AmountFined,
                actualEstablishment.Inspections.Select(x => x.Infractions.Sum(infraction => infraction.AmountFined)).Sum());
        }
Example #8
0
        public ClassroomController()
        {
            var entities = new Entities.Entities();

            ClassroomRepository     = new ClassroomRepository(entities);
            EstablishmentRepository = new EstablishmentRepository(entities);
            UserRepository          = new UserRepository(entities);
            YearRepository          = new YearRepository(entities);
        }
Example #9
0
        public async Task ShouldReturnEstablishmentInspections()
        {
            var options = new DbContextOptionsBuilder <WhereToBiteContext>()
                          .UseInMemoryDatabase("test5")
                          .Options;

            var whereToBiteContext = new WhereToBiteContext(options);

            var establishmentRepository = new EstablishmentRepository(whereToBiteContext);

            var expectedEstablishment = new Establishment(
                1,
                "test",
                "Restaurant",
                string.Empty,
                "Pass",
                new Point(-79.45886, 43.65493));

            var expectedInspection = new Inspection(InspectionStatus.Pass.ToString(), DateTime.Today.AddDays(-10));

            var expectedInfraction = new Infraction(
                "C - Crucial",
                "Ticket",
                expectedInspection.Date,
                "Fine",
                10000.00m);

            var expectedInfractionTwo = new Infraction(
                "M - Minor",
                "Ticket",
                expectedInspection.Date,
                "Fine",
                10.00m);

            expectedInspection.AddNewInfractions(new [] { expectedInfraction, expectedInfractionTwo });

            expectedEstablishment.AddNewInspections(new [] { expectedInspection });

            await whereToBiteContext.Establishments.AddAsync(expectedEstablishment);

            await whereToBiteContext.SaveChangesAsync();

            // act
            var actual = await establishmentRepository.GetInspectionsAsync(1, CancellationToken.None);

            Assert.NotNull(actual);
            var actualInspection = Assert.Single(actual);

            Assert.NotNull(actualInspection);
            Assert.Equal(expectedInspection.Date, actualInspection.Date);
            Assert.Equal(expectedInspection.Id, actualInspection.Id);
            Assert.Equal(expectedInspection.InspectionStatus, actualInspection.InspectionStatus);
            Assert.Equal(expectedInspection.Infractions.Count, actualInspection.Infractions.Count);
        }
Example #10
0
        public void ShouldCreateInstance()
        {
            var options = new DbContextOptionsBuilder <WhereToBiteContext>()
                          .UseInMemoryDatabase("test1")
                          .Options;

            var whereToBiteContext = new WhereToBiteContext(options);

            var establishmentRepository = new EstablishmentRepository(whereToBiteContext);

            Assert.NotNull(establishmentRepository);
        }
Example #11
0
 public ActionResult GetByFilter(string filter)
 {
     filter = filter.ToUpper();
     return(Json(EstablishmentRepository.All()
                 .Where(e =>
                        e.Name.ToUpper().Contains(filter) ||
                        e.Town.ToUpper().Contains(filter) ||
                        e.Academies.Name.ToUpper().Contains(filter) ||
                        e.Address.ToUpper().Contains(filter) ||
                        e.PostCode.Contains(filter) ||
                        e.Town.ToUpper().Contains(filter))
                 .Select(e => e.Id), JsonRequestBehavior.AllowGet));
 }
Example #12
0
        public ActionResult AddOrUpdate(Guid?id, Guid?academyId)
        {
            var model = new EstablishmentModel();

            model.UserId = GlobalVariables.UserId;
            if (id.HasValue)
            {
                model = EstablishmentModel.ToModel(EstablishmentRepository.GetById(id.Value));
            }
            if (academyId.HasValue)
            {
                model.AcademyId = academyId.Value;
            }

            return(View(model));
        }
Example #13
0
        public IEnumerable <ValidationResult> Validate(ValidationContext validationContext)
        {
            var establishmentRepository = new EstablishmentRepository(new Entities.Entities());
            var establishment           = establishmentRepository.GetByName(Name);

            if (establishment != null && establishment.Id != Id && establishment.Academies.Name != Academy)
            {
                yield return(new ValidationResult("Cette établissement est déjà présent dans cette académie.", new[] { "Name" }));
            }

            var isPostCode = ValidationHelper.IsValidPostCode(PostCode);

            if (!isPostCode)
            {
                yield return(new ValidationResult("Le code postal ne possède pas le bon format", new[] { "PostCode" }));
            }
        }
        private DineSafeDataExtractor CreateDineSafeDataExtractor(bool haveUpdate = false)
        {
            var repository = new EstablishmentRepository(_whereToBiteContext);
            var dineSafeDataExtractorLogger = NullLogger <DineSafeDataExtractor> .Instance;
            var dineSafeSettings            = Options.Create(new DineSafeSettings
            {
                MetadataUrl           = "http://localhost/metadataHost",
                DineSafeId            = Guid.Empty,
                DineSafeLastUpdateUrl = "http://localhost/lastUpdateHost"
            });
            var packageId = Guid.NewGuid();
            var client    = new FakeDineSafeClient(packageId);

            var memoryCache = new FakeMemoryCache(haveUpdate ? DateTime.Now.AddDays(-2) : DateTime.Now);

            var actual =
                new DineSafeDataExtractor(repository, dineSafeSettings, dineSafeDataExtractorLogger, client, memoryCache);

            return(actual);
        }
Example #15
0
        public async Task Repository_Establishments_GetRating_Return_Percentage()
        {
            //Mock Api service
            var estabRepo = new Mock <IApi <EstablishmentsViewModel> >();

            estabRepo.Setup(x => x.GetAsync(Uri, string.Empty)).Returns(Task.FromResult(_model));

            //Mock ICache for testing
            var cacheMock = new Mock <ICache>();

            cacheMock.Setup(x => x.Get <EstablishmentsViewModel>(It.IsAny <string>())).Returns(new EstablishmentsViewModel());
            cacheMock.Setup(x => x.Add(It.IsAny <string>(), It.IsAny <EstablishmentsViewModel>(), It.IsAny <DateTime>())).Verifiable();

            var repo   = new EstablishmentRepository(new Mock <ILog>().Object, cacheMock.Object, estabRepo.Object);
            var result = await repo.GetRating(Uri, _queryString, _ratingKeyValues, string.Empty);

            //Enumate to list to aviod null exception
            var resultList = result as IList <RatingViewModel> ?? result.ToList();

            Assert.IsNotNull(result);
            Assert.AreEqual(_model.Establishments.Count(), resultList.Count());
            Assert.That(resultList.All(x => x.Percentage == (decimal)1 / 6));//make sure percentages are correct
        }
Example #16
0
        public async Task ShouldThrowIfCenterIsNull()
        {
            var options = new DbContextOptionsBuilder <WhereToBiteContext>()
                          .UseInMemoryDatabase("test5")
                          .Options;

            var whereToBiteContext = new WhereToBiteContext(options);

            var establishmentRepository = new EstablishmentRepository(whereToBiteContext);

            var expectedEstablishment = new Establishment(1,
                                                          "test",
                                                          "Restaurant",
                                                          string.Empty,
                                                          "Pass",
                                                          new Point(-79.45886, 43.65493));

            await whereToBiteContext.Establishments.AddAsync(expectedEstablishment);

            await whereToBiteContext.SaveChangesAsync();

            await Assert.ThrowsAsync <ArgumentNullException>(() => establishmentRepository.GetAllWithinRadiusAsync(1000, null !, CancellationToken.None));
        }
Example #17
0
 public ActionResult Delete(Guid id)
 {
     EstablishmentRepository.Delete(id);
     EstablishmentRepository.Save();
     return(Redirect(Url.Action("GetAll", "Establishment")));
 }
Example #18
0
        public ActionResult Get(Guid id)
        {
            var model = EstablishmentModel.ToModel(EstablishmentRepository.GetById(id));

            return(View(model));
        }