public IActionResult Index(CreateJobBindModel cjvm) { var currentUser = repository.GetCurrentUser(); if (repository.IsWorker()) { ViewData["Error"] = "You are a worker!"; return(Redirect("/WorkerManagement/Index")); } if (cjvm.Payment == 0) { ViewData["Error"] = "Invalid payment!"; return(View()); } string JobName = cjvm.JobName; string Description = cjvm.Description; decimal Payment = cjvm.Payment; int accountId = (int)currentUser.EmployerAccountId; Job job = new Job { Name = JobName, Description = Description, PayUponCompletion = Payment, JobCreatorId = (int)currentUser.EmployerAccountId }; repository.AddJob(job); return(View()); }
public void ReturnsCorrectlyWhenJobPaymentIsZero() { Mock <IUserAndContextRepository> mockedService = new Mock <IUserAndContextRepository>(); CreateJobBindModel createJobBindModel = new CreateJobBindModel() { Description = "asdfasdf", JobName = "hello", Payment = 0 }; mockedService.Setup(a => a.IsWorker()).Returns(false); CreateJobController createJobController = new CreateJobController(mockedService.Object); ViewResult result = (ViewResult)createJobController.Index(createJobBindModel); Assert.That(result.ViewData["Error"].ToString() == "Invalid payment!"); }
public void ReturnsCorrectlyWhenViewerIsAWorker() { Mock <IUserAndContextRepository> mockedService = new Mock <IUserAndContextRepository>(); CreateJobBindModel createJobBindModel = new CreateJobBindModel() { Description = "asdfasdf", JobName = "hello", Payment = 123 }; mockedService.Setup(a => a.IsWorker()).Returns(true); CreateJobController createJobController = new CreateJobController(mockedService.Object); IActionResult result = createJobController.Index(createJobBindModel); Assert.That(result is RedirectResult); }