public IActionResult Create([FromBody] BWQInstructions newmodel) { if (ModelState.IsValid) { _context.BWQInstructions.Add(newmodel); _context.SaveChanges(); return(CreatedAtRoute("GetBWQInstructions", new { id = newmodel.BWQInstructionsID }, newmodel)); } else { return(BadRequest()); } }
public void BWQInstructions() { ILogger <BWQInstructionsController> _testlogger = null; using (var context = new AppDbContext(options, null)) { var controller = new BWQInstructionsController(context, _testlogger, null); // Get all var result = controller.Get(); // Assert var okResult = Assert.IsAssignableFrom <IEnumerable <BWQInstructions> >(result); var pgcount = okResult.ToList().Count; Assert.Equal(2, pgcount); // Get by ID var result1 = controller.Get(1); var okResult1 = Assert.IsAssignableFrom <BWQInstructions>(result1); //var thisresult1 = okResult1.FirstOrDefault(); Assert.Equal("Instructions 1", result1.Instructions); // test update var pg1 = new BWQInstructions { BWQInstructionsID = 1, BWQEntitiesID = 1, BWQDispositionsID = 1, BWQFieldSelectID = 1, Instructions = "Instructions 1 upd" }; //controller.UpdateEntry(pg1); var result3 = controller.Get(1); //var thisresult3 = result3.FirstOrDefault(); Assert.Equal("Instructions 1", result3.Instructions); // test delete var result4 = controller.Get(2); //var thisresult4 = result4.FirstOrDefault(); Assert.Equal("Instructions 2", result4.Instructions); IActionResult result5 = controller.Delete(2); var viewResult = Assert.IsType <Microsoft.AspNetCore.Mvc.OkResult>(result5); var result6 = controller.Get(2); Assert.Null(result6); } }
public void BWQInstructions() { IQueryable <BWQInstructions> BWQInstructionsBWQInstructions = Enumerable.Empty <BWQInstructions>().AsQueryable(); BWQInstructions ct = new BWQInstructions { BWQInstructionsID = 1, CreatedBy = "Test BWQInstructions" }; Mock <IBWQInstructionsRepository> BWQInstructionsService = new Mock <IBWQInstructionsRepository>(); BWQInstructionsData binsdata = new BWQInstructionsData(); IConfiguration configuration = null; try { BWQInstructionsService.Setup(x => x.GetAll()).Returns(BWQInstructionsBWQInstructions); BWQInstructionsService.Setup(x => x.Get(It.IsAny <int>())).Returns(ct); BWQInstructionsService.Setup(x => x.Add(It.IsAny <BWQInstructions>())).Returns(ct); BWQInstructionsService.Setup(x => x.Delete(It.IsAny <BWQInstructions>())).Verifiable(); BWQInstructionsService.Setup(x => x.UpdateInstruction(It.IsAny <BWQInstructionsData>(), It.IsAny <IConfiguration>())).Returns(ct); var BWQInstructionsObject = BWQInstructionsService.Object; var p1 = BWQInstructionsObject.GetAll(); var p2 = BWQInstructionsObject.Get(1); var p3 = BWQInstructionsObject.UpdateInstruction(binsdata, configuration); var p4 = BWQInstructionsObject.Add(ct); BWQInstructionsObject.Delete(ct); Assert.IsAssignableFrom <IQueryable <BWQInstructions> >(p1); Assert.IsAssignableFrom <BWQInstructions>(p2); Assert.Equal("Test BWQInstructions", p2.CreatedBy); Assert.IsAssignableFrom <object>(p3); BWQInstructionsService.VerifyAll(); BWQInstructionsObject.Dispose(); } finally { BWQInstructionsService = null; } }
internal void PopulateData() { using (var context = new AppDbContext(options, null)) { if (context.Collection.Count() < 1) { var p1 = new Collection { CollectionID = 1, CollectionName = "collection type 1", }; var p2 = new Collection { CollectionID = 2, CollectionName = "collection type 2", }; context.Collection.Add(p1); context.Collection.Add(p2); context.SaveChanges(); } if (context.CollectionItem.Count() < 1) { var p1 = new CollectionItem { CollectionItemID = 1, CollectionID = 1, ItemText = "collectionitem type 1", }; var p2 = new CollectionItem { CollectionItemID = 2, CollectionID = 1, ItemText = "collectionitem type 2", }; context.CollectionItem.Add(p1); context.CollectionItem.Add(p2); if (context.Collection.Count() < 1) { var p3 = new Collection { CollectionID = 1, CollectionName = "collection type 1", }; } context.SaveChanges(); } if (context.BWQStatusType.Count() < 1) { var p1 = new BWQStatusType { BWQStatusTypeID = 1, BwqStatusTypeDescription = "bwqstatus type 1", }; var p2 = new BWQStatusType { BWQStatusTypeID = 2, BwqStatusTypeDescription = "bwqstatus type 2", }; context.BWQStatusType.Add(p1); context.BWQStatusType.Add(p2); context.SaveChanges(); } if (context.BWQFieldSelect.Count() < 1) { var p1 = new BWQFieldSelect { BWQFieldSelectID = 1, FieldDisplayName = "fieldselect type 1", }; var p2 = new BWQFieldSelect { BWQFieldSelectID = 2, FieldDisplayName = "fieldselect type 2", }; context.BWQFieldSelect.Add(p1); context.BWQFieldSelect.Add(p2); context.SaveChanges(); } if (context.BWQDispositions.Count() < 1) { var p1 = new BWQDispositions { BWQDispositionsID = 1, BWQDispositionsDescription = "bwqdisposition type 1", }; var p2 = new BWQDispositions { BWQDispositionsID = 2, BWQDispositionsDescription = "bwqdisposition type 2", }; context.BWQDispositions.Add(p1); context.BWQDispositions.Add(p2); context.SaveChanges(); } if (context.BWQEntities.Count() < 1) { var p1 = new BWQEntities { BWQEntitiesID = 1, BWQID = 1, EntityName = "bwqentity type 1", }; var p2 = new BWQEntities { BWQEntitiesID = 2, BWQID = 1, EntityName = "bwqentity type 2", }; context.BWQEntities.Add(p1); context.BWQEntities.Add(p2); if (context.BWQ.Count() < 1) { var p3 = new BWQ { BWQID = 1, BatchName = "bwqbatch 1", }; } context.SaveChanges(); } if (context.BWQ.Count() < 1) { var p1 = new BWQ { BWQID = 1, BatchName = "bwqbatch 1", }; var p2 = new BWQ { BWQID = 2, BatchName = "bwqbatch 2", }; context.BWQ.Add(p1); context.BWQ.Add(p2); context.SaveChanges(); } if (context.BWQInstructions.Count() < 1) { var p1 = new BWQInstructions { BWQInstructionsID = 1, BWQEntitiesID = 1, BWQDispositionsID = 1, BWQFieldSelectID = 1, Instructions = "Instructions 1" }; var p2 = new BWQInstructions { BWQInstructionsID = 2, BWQEntitiesID = 1, BWQDispositionsID = 1, BWQFieldSelectID = 1, Instructions = "Instructions 2" }; context.BWQInstructions.Add(p1); context.BWQInstructions.Add(p2); if (context.BWQEntities.Count() < 1) { var p3 = new BWQEntities { BWQEntitiesID = 1, BWQID = 1, EntityName = "bwqentity type 1", }; context.BWQEntities.Add(p3); } if (context.BWQDispositions.Count() < 1) { var p4 = new BWQDispositions { BWQDispositionsID = 1, BWQDispositionsDescription = "bwqdisposition type 1", }; context.BWQDispositions.Add(p4); } if (context.BWQFieldSelect.Count() < 1) { var p5 = new BWQFieldSelect { BWQFieldSelectID = 1, FieldDisplayName = "fieldselect type 1", }; context.BWQFieldSelect.Add(p5); } context.SaveChanges(); } } }
public IActionResult Create([FromBody] BWQInstructions newentry) { BWQInstructions result = _repository.Add(newentry); return(Helper.CheckResult(result)); }
public IActionResult Get(int id) { BWQInstructions data = _repository.GetIdIncluding(id); return(Helper.CheckResult(data)); }