public void TestInitialize() { _serv = new Mock<IPersonService>(); lcache = new Mock<ILookupCache>(); dbfactory = new Mock<IDatabaseFactory>(); _ctrlr = new PersonController(_serv.Object, lcache.Object); _ctrlr.SetFakeControllerContext(); fakeform = new FormCollection(); fakeform.Add("ID", "12345"); fakeform.Add("firstname1", "Ronald"); fakeform.Add("lastname1", "Reagan"); // TODO: Include Lookups in Dependency Injection, remove initialize statements Lookups.Initialize(lcache.Object, dbfactory.Object); }
public void PersonController_edit_get_returns_person() { //Arrange _serv = new Mock<IPersonService>(); int testid = 4242; Person fakeperson = new Person(); _serv.Setup(p => p.Get(testid)).Returns(fakeperson); var _ctrlr = new PersonController(_serv.Object, lcache.Object); //Act var result = (PartialViewResult)_ctrlr.Edit(testid); //Assert Assert.IsInstanceOfType(result.ViewData.Model, typeof(Person)); }
public void PersonController_edit_post_valid_updates_model_returns_JSON() { //Arrange _serv = new Mock<IPersonService>(); int testid = 4242; FormCollection fakeform = new FormCollection(); fakeform.Add("ID", testid.ToString()); fakeform.Add("firstname1", "blah"); //Every required field must be populated, fakeform.Add("lastname1", "UnitTest"); //or result will be null. fakeform.Add("gender", "47"); Person fakeperson = new Person(); Person savedperson = new Person(); string user = ""; _serv.Setup(p => p.Get(testid)).Returns(fakeperson); _serv.Setup(x => x.Save(It.IsAny<Person>(), It.IsAny<string>()) ).Callback((Person p, string str) => { savedperson = p; user = str; }); var _ctrlr = new PersonController(_serv.Object, lcache.Object); _ctrlr.SetFakeControllerContext(); _ctrlr.ValueProvider = fakeform.ToValueProvider(); //Act var result = _ctrlr.Edit(testid, "UnitTest") as JsonResult; //Assert IDictionary<string, object> data = new RouteValueDictionary(result.Data); Assert.AreEqual("OK", data["status"]); Assert.AreEqual(fakeperson, savedperson); Assert.AreEqual(savedperson.firstname1, "blah"); Assert.AreEqual(savedperson.lastname1, "UnitTest"); Assert.AreEqual(savedperson.gender, 47); }
public void PersonController_delete_post_returns_JSON() { //Arrange _serv = new Mock<IPersonService>(); int testid = 4242; FormCollection fakeform = new FormCollection(); var _ctrlr = new PersonController(_serv.Object, lcache.Object); _ctrlr.SetFakeControllerContext(); _ctrlr.ValueProvider = fakeform.ToValueProvider(); //Act JsonResult result = _ctrlr.Delete(testid, "UnitTest") as JsonResult; //Assert IDictionary<string, object> data = new RouteValueDictionary(result.Data); Assert.AreEqual("OK", data["status"]); Assert.AreEqual(4242, data["deletedID"]); }