public async Task <IActionResult> Create([Bind("ID,Title,Details,Worker,CreateDate")] Case @case) { if (ModelState.IsValid) { @case.WorkerID = HttpContext.User.FindFirst(ClaimTypes.NameIdentifier).Value; _caseService.Add(@case); return(RedirectToAction(nameof(Index))); } return(View(@case)); }
public void Add_CaseNotCreated_CaseIsCreated() { Case caseToAdd = new Case { Title = "Add Test Case", Details = "Details", WorkerID = "worker1id", DateReviewed = null, DateApproved = null, Status = CaseStatus.Pending }; _caseService.Add(caseToAdd); //Get all cases since we don't know ID of the newly created case var cases = _caseService.GetAll(); var addedCase = cases.FirstOrDefault(x => x.Title == "Add Test Case"); Assert.IsNotNull(addedCase); }
public CaseUnitTests() { var options = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase(databaseName: "TestCasesDB") .Options; var context = new ApplicationDbContext(options); _caseService = new CaseService(context); Case caseToAdd = new Case { ID = 1, Title = "Test Case 1", Details = "", WorkerID = "worker1id", DateReviewed = null, DateApproved = null, Status = CaseStatus.Pending }; context.Add(caseToAdd); _caseService.Add(caseToAdd); }