public static cIndividualController GetController(IIndividualRepository repository) { cIndividualController controller = new cIndividualController(repository); controller.ControllerContext = new ControllerContext() { Controller = controller, RequestContext = new RequestContext(new MockHttpContext(), new RouteData()) }; return(controller); }
public void Initialize() { _repo = (InMemoryIndividualRepository)Harness.GetRepo(); _repo.Add(new cIndividual { ID = 1, Firstname = "Phillipe", Surname = "Coutinho" }); _repo.Add(new cIndividual { ID = 2, Firstname = "Bob", Surname = "Lalana" }); _repo.Add(new cIndividual { ID = 4, Firstname = "Simon", Surname = "Mignolet" }); _repo.Add(new cIndividual { ID = 5, Firstname = "Robert", Surname = "Firmino" }); _controller = Harness.GetController(_repo); IList <cMatter> oMatters = new List <cMatter>(); oMatters.Add(new cMatter { ID = "1", Description = "Test1" }); oMatters.Add(new cMatter { ID = "2", Description = "Test2" }); cCDD_Details oCDD = new cCDD_Details { ID = 1, CDDStatus = eCDDStatus.Complete }; IList <cEntityRelationship> oER = new List <cEntityRelationship>(); oER.Add(new cEntityRelationship { ID = 1, entityA_ID = 1, entityB_ID = 2, relType = eRelType.Director }); cIndividual indiv = new cIndividual(); indiv.ID = 3; indiv.Firstname = "Adam"; indiv.Surname = "Lalana"; indiv.Matters = oMatters; indiv.CDD_Details = oCDD; indiv.IsA = oER; _repo.Add(indiv); }
public void Create_Post_PutsValidContactIntoRepository() { // Arrange InMemoryIndividualRepository repository = new InMemoryIndividualRepository(); cIndividualController controller = Harness.GetController(repository); cIndividual indiv = GetIndividual(); // Act controller.Create(indiv); // Assert IEnumerable <cIndividual> individuals = repository.GetAllIndividuals(); Assert.IsTrue(individuals.Contains(indiv)); }
public void Create_Post_ReturnsViewIfModelStateIsNotValid() { // Arrange cIndividualController controller = Harness.GetController(new InMemoryIndividualRepository()); // Simply executing a method during a unit test does just that - executes a method, and no more. // The MVC pipeline doesn't run, so binding and validation don't run. controller.ModelState.AddModelError("", "mock error message"); cIndividual model = GetIndividual(1, "", "", DateTime.Now, "", ""); // Act var result = (ViewResult)controller.Create(model); // Assert Assert.AreEqual("Create", result.ViewName); }
public void Initialize() { _repo = (InMemoryIndividualRepository)Harness.GetRepo(); _repo.Add(new cIndividual { ID = 1, Firstname = "Phillipe", Surname = "Coutinho" }); _repo.Add(new cIndividual { ID = 1, Firstname = "Bob", Surname = "Lalana" }); _repo.Add(new cIndividual { ID = 1, Firstname = "Adam", Surname = "Lalana" }); _repo.Add(new cIndividual { ID = 1, Firstname = "Simon", Surname = "Mignolet" }); _repo.Add(new cIndividual { ID = 1, Firstname = "Robert", Surname = "Firmino" }); _controller = Harness.GetController(_repo); }