public void AlertSourceType() { ILogger <AlertSourceTypeController> _testlogger = null; using (var context = new AppDbContext(options, null)) { var controller = new AlertSourceTypeController(context, _testlogger); // Get all var result = controller.Get(); // Assert var okResult = Assert.IsAssignableFrom <IEnumerable <AlertSourceType> >(result); var pgcount = okResult.ToList().Count; Assert.Equal(2, pgcount); // Get by ID var result1 = controller.Get(1); var okResult1 = Assert.IsAssignableFrom <AlertSourceType>(result1); Assert.Equal("user1", okResult1.CreatedBy); // test update var pg1 = new AlertSourceType { AlertSourceTypeID = 1, CreatedBy = "user1 upd" }; controller.UpdateEntry(pg1); var result3 = controller.Get(1); Assert.NotEqual("user1", result3.CreatedBy); Assert.Equal("user1 upd", result3.CreatedBy); // test delete var result4 = controller.Get(2); Assert.Equal("user1", result4.CreatedBy); var result5 = controller.Delete(2); var viewResult = Assert.IsType <Microsoft.AspNetCore.Mvc.OkResult>(result5); var result6 = controller.Get(2); Assert.Null(result6); } }
internal static string ToSerializedValue(this AlertSourceType value) { switch (value) { case AlertSourceType.Resource: return("Resource"); case AlertSourceType.Device: return("Device"); } return(null); }
public IActionResult Create([FromBody] AlertSourceType newmodel) { if (ModelState.IsValid) { _context.AlertSourceType.Add(newmodel); _context.SaveChanges(); return(CreatedAtRoute("GetAlertSourceType", new { id = newmodel.AlertSourceTypeID }, newmodel)); } else { return(BadRequest()); } }
public IActionResult UpdateEntry([FromBody] AlertSourceType objupd) { var targetObject = _context.AlertSourceType.FirstOrDefault(t => t.AlertSourceTypeID == objupd.AlertSourceTypeID); if (targetObject == null) { return(NotFound()); } _context.Entry(targetObject).CurrentValues.SetValues(objupd); ReturnData ret; ret = _context.SaveData(); if (ret.Message == "Success") { return(Ok()); } return(NotFound(ret)); }
public void AlertSourceType() { IQueryable <AlertSourceType> AlertSourceTypeCollection = Enumerable.Empty <AlertSourceType>().AsQueryable(); AlertSourceType ct = new AlertSourceType { AlertSourceTypeID = 1, AlertTypeDescription = "Test AlertSourceType" }; Mock <IAlertSourceTypeRepository> AlertSourceTypeService = new Mock <IAlertSourceTypeRepository>(); object obj = new object(); try { AlertSourceTypeService.Setup(x => x.GetAll()).Returns(AlertSourceTypeCollection); AlertSourceTypeService.Setup(x => x.Get(It.IsAny <int>())).Returns(ct); AlertSourceTypeService.Setup(x => x.Add(It.IsAny <AlertSourceType>())).Returns(ct); AlertSourceTypeService.Setup(x => x.Delete(It.IsAny <AlertSourceType>())).Verifiable(); AlertSourceTypeService.Setup(x => x.Update(It.IsAny <AlertSourceType>(), It.IsAny <object>())).Returns(ct); var AlertSourceTypeObject = AlertSourceTypeService.Object; var p1 = AlertSourceTypeObject.GetAll(); var p2 = AlertSourceTypeObject.Get(1); var p3 = AlertSourceTypeObject.Update(ct, obj); var p4 = AlertSourceTypeObject.Add(ct); AlertSourceTypeObject.Delete(ct); Assert.IsAssignableFrom <IQueryable <AlertSourceType> >(p1); Assert.IsAssignableFrom <AlertSourceType>(p2); Assert.Equal("Test AlertSourceType", p2.AlertTypeDescription); Assert.Equal("Test AlertSourceType", p3.AlertTypeDescription); AlertSourceTypeService.VerifyAll(); AlertSourceTypeObject.Dispose(); } finally { AlertSourceTypeService = null; } }
internal void PopulateData() { using (var context = new AppDbContext(options, null)) { if (context.AlertJobs.Count() < 1) { var p1 = new AlertJobs { AlertJobsID = 1, CreatedBy = "user1", }; var p2 = new AlertJobs { AlertJobsID = 2, CreatedBy = "user1", }; context.AlertJobs.Add(p1); context.AlertJobs.Add(p2); context.SaveChanges(); } if (context.AlertSchedules.Count() < 1) { var p1 = new AlertSchedules { AlertSchedulesId = 1, CreatedBy = "user1", }; var p2 = new AlertSchedules { AlertSchedulesId = 2, CreatedBy = "user1", }; context.AlertSchedules.Add(p1); context.AlertSchedules.Add(p2); context.SaveChanges(); } if (context.AlertScheduleType.Count() < 1) { var p1 = new AlertScheduleType { AlertScheduleTypeID = 1, CreatedBy = "user1", }; var p2 = new AlertScheduleType { AlertScheduleTypeID = 2, CreatedBy = "user1", }; context.AlertScheduleType.Add(p1); context.AlertScheduleType.Add(p2); context.SaveChanges(); } if (context.AlertSourceType.Count() < 1) { var p1 = new AlertSourceType { AlertSourceTypeID = 1, CreatedBy = "user1", }; var p2 = new AlertSourceType { AlertSourceTypeID = 2, CreatedBy = "user1", }; context.AlertSourceType.Add(p1); context.AlertSourceType.Add(p2); context.SaveChanges(); } if (context.AlertWorkers.Count() < 1) { var p1 = new AlertWorkers { AlertWorkersID = 1, CreatedBy = "user1", }; var p2 = new AlertWorkers { AlertWorkersID = 2, CreatedBy = "user1", }; context.AlertWorkers.Add(p1); context.AlertWorkers.Add(p2); context.SaveChanges(); } if (context.Encoding.Count() < 1) { var p1 = new Encoding { EncodingID = 1, CreatedBy = "user1", }; var p2 = new Encoding { EncodingID = 2, CreatedBy = "user1", }; context.Encoding.Add(p1); context.Encoding.Add(p2); context.SaveChanges(); } } }
public IActionResult Update([FromBody] AlertSourceType editentry) { var result = _repository.Update(editentry, editentry.AlertSourceTypeID); return(Helper.CheckResult(result)); }
public IActionResult Create([FromBody] AlertSourceType newentry) { var result = _repository.Add(newentry); return(Helper.CheckResult(result)); }