public IActionResult Submit(Submission submission) { SubmitStates state = _giveAway.Submit(submission); //If a problem with the data was identified in the domain //the error will be passed along, otherwise users will be //shown all submissions if (state == SubmitStates.Success) { return(Redirect("./index")); } else { TempData["ErrorState"] = state.ToString(); return(Redirect("./submit")); } }
public void SubmitTest() { Assert.AreEqual(SubmitStates.Success, controller.Submit(sub1)); var AllSubmissions = controller.AllSubmissions(); Assert.That(AllSubmissions, Is.EquivalentTo(new Submission[] { sub1 })); //Test that two submission with the same code cannot be added Assert.AreEqual(SubmitStates.Duplicate, controller.Submit(dub1)); AllSubmissions = controller.AllSubmissions(); Assert.That(AllSubmissions, Is.EquivalentTo(new Submission[] { sub1 })); //Tests email (More test confirming the whole range of mails would be appropriate, same goes for later test) Assert.AreEqual(SubmitStates.InvalidInformation, controller.Submit(weirdEmail)); AllSubmissions = controller.AllSubmissions(); Assert.That(AllSubmissions, Is.EquivalentTo(new Submission[] { sub1 })); //Tests phonenumber Assert.AreEqual(SubmitStates.InvalidInformation, controller.Submit(incorrectNumber)); AllSubmissions = controller.AllSubmissions(); Assert.That(AllSubmissions, Is.EquivalentTo(new Submission[] { sub1 })); //Tests missing firstname Assert.AreEqual(SubmitStates.InvalidInformation, controller.Submit(missingFirstName)); AllSubmissions = controller.AllSubmissions(); Assert.That(AllSubmissions, Is.EquivalentTo(new Submission[] { sub1 })); //Tests missing surname Assert.AreEqual(SubmitStates.InvalidInformation, controller.Submit(missingLastName)); AllSubmissions = controller.AllSubmissions(); Assert.That(AllSubmissions, Is.EquivalentTo(new Submission[] { sub1 })); }