public void Update_the_Data_Of_Report_Should_Not_Be_Same() { fixture.PopulateAll(); var repository = new ReportRepository(fixture.context); var id = ReportEntityTypeConfiguration.ReportSeed.ElementAt(1).Id; var data = ReportEntityTypeConfiguration.ReportSeed.ElementAt(1).Location; var entity = repository.Find(id as object).Result; entity.Location = "Fa"; repository.Update(entity); var entityUpdated = repository.Find(id as object).Result; Assert.NotEqual(data, entityUpdated.Location); }
public HttpResponseMessage GetReport(int id) { using (var repo = new ReportRepository()) { var report = repo.Find(r => r.Id == id) .Select(r => new ReportDTO { Id = r.Id, Description = r.Description, Incident_Time = r.CreatedOn, Mode = r.Mode, Location = new LocationDTO { Cross_Street = r.Address, Lat = r.Lat, Long = r.Long, Narrative = r.Narrative }, Image = r.Image, Modes = new ModesDTO { Personal = r.Mode, //Other = r.CollisionModes.Split(','), }, Infrastructure = r.Infrastructure, Injury = r.Injury, Collision = r.Collision, PropertyDamage = r.PropertyDamage, }) .FirstOrDefault(); return(Request.CreateResponse(HttpStatusCode.OK, report)); } }
public HttpResponseMessage PostImageFile(int id) { if (HttpContext.Current.Request.Files.AllKeys.Any()) { // Get the uploaded image from the Files collection var image = HttpContext.Current.Request.Files["image"]; if (image != null) { // Validate the uploaded image(optional) var rand = new Random(); var unique = rand.Next(1000000).ToString(); var ext = Path.GetExtension(image.FileName).ToLower(); var fileName = string.Format("{0}-{1}{2}", id, unique, ext); if (ext == ".png" || ext == ".jpg") { // Get the complete file path var fileSavePath = Path.Combine(HttpContext.Current.Server.MapPath("~/Images"), fileName); // Save the uploaded file to "Images" folder image.SaveAs(fileSavePath); using (var repo = new ReportRepository()) { var report = repo.Find(r => r.Id == id).FirstOrDefault(); if (report != null) { report.Image = fileName; repo.Commit(); return(Request.CreateResponse(HttpStatusCode.Created)); } else { // delete file // report does not exist return(Request.CreateResponse(HttpStatusCode.BadRequest)); } } } else { // create err invalid file extension (jpg, png) return(Request.CreateResponse(HttpStatusCode.BadRequest)); } } else { // no image posted return(Request.CreateResponse(HttpStatusCode.BadRequest)); } } else { // no image posted return(Request.CreateResponse(HttpStatusCode.BadRequest)); } }
public void Remove_A_Report_When_All_Populated_Should_Be_One() { fixture.PopulateAll(); var repository = new ReportRepository(fixture.context); var id = ReportEntityTypeConfiguration.ReportSeed.ElementAt(1).Id; var entity = repository.Find(id as object).Result; repository.Remove(entity); var entities = repository.Get(); var count = entities.Count(); Assert.Equal(1, count); }
public ReportViewModel GetReportDetailById(int ReportId) { ReportViewModel reportViewModel = new ReportViewModel(); using (var reportRepository = new ReportRepository()) { var reportDetail = reportRepository.Find(x => x.ReportId == ReportId).FirstOrDefault(); if (reportDetail != null) { reportViewModel.ReportId = reportDetail.ReportId; reportViewModel.Name = reportDetail.Name; reportViewModel.Query = reportDetail.Query; reportViewModel.DBConnection = reportDetail.DBConnection; reportViewModel.ParameterList = JsonConvert.DeserializeObject <List <ParameterViewModel> >(reportDetail.Parameter); } } return(reportViewModel); }
public void Controller_Put_Should_Be_badRequest() { var fixture = new DbContextFixture(); var logger = new Mock <ILogger <ReportsController> >().Object; fixture.PopulateAll(); var repository = new ReportRepository(fixture.context); var controller = new ReportsController(logger, repository); var eid = ReportEntityTypeConfiguration.ReportSeed.ElementAt(1).Id; var e = repository.Find(eid as object).Result; e.ContactCount = 4; var delta = new Delta <Report>(typeof(Report)); delta.TrySetPropertyValue(nameof(Report.ContactCount), e.ContactCount as object); ActionResult <Report> result = controller.Put(e.Id, delta); result.Result.Should().BeOfType <BadRequestResult>(); }