public void Should_return_404_after_get_to_edit_with_invalid_id() { // Arrange // Act var result = _controller.Edit(0) as HttpStatusCodeResult; // Assert Assert.That(result, Is.Not.Null, "Controller returned Http Status"); Assert.That(result.StatusCode, Is.EqualTo(404), "Controller returned 404"); }
public async Task edit_get_returns_person() { //Arrange _service.Setup(p => p.Get(_testid)).Returns(_person); //Act var result = await _controller.Edit(_testid) as PartialViewResult; //Assert Assert.IsNotNull(result); Assert.IsInstanceOfType(result.ViewData.Model, typeof(Machete.Web.ViewModel.Person)); }
public void EditNotExitedPersonReturnView() { var controller = new PersonController(); var result = controller.Edit(id: Guid.Empty); Assert.IsInstanceOfType(result, typeof(HttpNotFoundResult)); }
public void TestEditPerson() { var context = new FakePersonSharingContext(); context.Persons = new[] { new Person { personId = 1, imie = "Kasia", nazwisko = "Kowalska", pesel = "56457866", adresId = 1 }, new Person { personId = 2, imie = "Basia", nazwisko = "Kowalska", pesel = "56457867", adresId = 2 }, new Person { personId = 3, imie = "Masia", nazwisko = "Kowalska", pesel = "56457868", adresId = 3 } }.AsQueryable(); Person person = new Person(); person.personId = 1; person.imie = "Kasia"; var controller = new PersonController(context); var result = controller.Edit(person) as RedirectToRouteResult; Assert.AreEqual("All", result.RouteValues["Action"]); Assert.AreEqual("Person", result.RouteValues["Controller"]); }
public void TestEditPersonViewMoq() { Person person = new Person(); person.imie = "Basia"; person.nazwisko = "Kowalska"; Mock <IPersonSharingContext> context = new Mock <IPersonSharingContext>(); context.Setup(x => x.FindPersonById(2)).Returns(person); var controller = new PersonController(context.Object); var result = controller.Edit(2); ViewResult p = (ViewResult)controller.Edit(2); var view = p.ViewName; Assert.AreEqual("Edit", view); }
public void EditExitedPersonReturnView() { var id = PersonHelper.PersonModelList.First().Id; var controller = new PersonController(); var result = controller.Edit(id: id); Assert.IsInstanceOfType(result, typeof(ViewResult)); }
public void PersonController_Edit() { // Arrange PersonController controller = new PersonController(); // Act // this person does not exist - will redirect to error page var result = (RedirectToRouteResult)controller.Edit(0); // Assert Assert.IsTrue(result.RouteValues["action"].ToString() == "FatalError"); }
public void EditViewModelNotNull() { var person = new PersonDTO(); var mock = new Mock <IService>(); mock.Setup(a => a.GetPerson(person.Id)).Returns(new PersonDTO()); var controller = new PersonController(mock.Object); var result = controller.Edit(person.Id) as ViewResult; Assert.IsNotNull(result.Model); }
public void EditShouldReturlHttpResultWhenIdNotFound() { var controller = new PersonController(_context.Object, _badgeRepo.Object, _personRepo.Object, _recognitionRepo.Object); Person notFound = null; _personRepo.Setup(x => x.Get(2)).Returns(notFound); var result = controller.Edit(2); Assert.IsInstanceOfType(result, typeof(HttpNotFoundResult)); }
public void TestEditPersonView() { var context = new FakePersonSharingContext(); context.Persons = new[] { new Person { personId = 1, imie = "Kasia", nazwisko = "Kowalska", pesel = "56457866", adresId = 1 }, new Person { personId = 2, imie = "Basia", nazwisko = "Kowalska", pesel = "56457867", adresId = 2 }, new Person { personId = 3, imie = "Masia", nazwisko = "Kowalska", pesel = "56457868", adresId = 3 } }.AsQueryable(); var controller = new PersonController(context); var result = controller.Edit(2); ViewResult p = (ViewResult)controller.Edit(2); var view = p.ViewName; Assert.AreEqual("Edit", view); }
public void EditPostAction_RedirectToIndexView() { var personViewModel = new PersonViewModel(); var person = new PersonDTO(); var mock = new Mock <IService>(); mock.Setup(x => x.SavePerson(person)).Verifiable(); var controller = new PersonController(mock.Object); var result = controller.Edit(personViewModel) as RedirectToRouteResult; Assert.IsNotNull(result); Assert.AreEqual("Index", result.RouteValues["action"]); }
public void TestEditHttpMoq() { Person person = new Person(); person.imie = "Basia"; person.nazwisko = "Kowalska"; Mock <IPersonSharingContext> context = new Mock <IPersonSharingContext>(); context.Setup(x => x.FindPersonById(2)).Returns(person); var controller = new PersonController(context.Object); var result = controller.Edit(25); Assert.AreEqual(typeof(HttpNotFoundResult), result.GetType()); }
public void Edit_Returns_NotFoundResult() { // Arrange var entity = GetPersonEntity(); var mockRepo = new Mock <IPersonRepository>(); mockRepo.Setup(repo => repo.GetById(entity.Id)).Returns(entity); var controller = new PersonController(mockRepo.Object, CreateMapper()); // Act var result = controller.Edit(2); // Assert var notFoundResult = Assert.IsType <NotFoundResult>(result); }
public void EditPost_Returns_RedirectToActionResult() { // Arrange var mockRepo = new Mock <IPersonRepository>(); var controller = new PersonController(mockRepo.Object, CreateMapper()); var model = CreateModel(); // Act var result = controller.Edit(model.Id, model); // Assert var redirectToActionResult = Assert.IsType <RedirectToActionResult>(result); Assert.Null(redirectToActionResult.ControllerName); Assert.Equal(nameof(controller.Index), redirectToActionResult.ActionName); }
public void TestEditPersonModelNotValid() { Person person = new Person(); person.imie = "Basia"; person.nazwisko = "Kowalska"; person.personId = 5; Mock <IPersonSharingContext> context = new Mock <IPersonSharingContext>(); context.Setup(x => x.FindPersonById(2)).Returns(person); var controller = new PersonController(context.Object); controller.ViewData.ModelState.AddModelError("imie", "Podaj imię"); var result = (ViewResult)controller.Edit(person); Assert.AreEqual("Edit", result.ViewName); }
public void EditPost_Returns_BadRequestResult() { // Arrange var mockRepo = new Mock <IPersonRepository>(); var controller = new PersonController(mockRepo.Object, CreateMapper()); controller.ModelState.AddModelError("Code", "Required"); var model = CreateModel(); // Act var result = controller.Edit(model.Id, model); // Assert var badRequestResult = Assert.IsType <BadRequestObjectResult>(result); Assert.IsType <SerializableError>(badRequestResult.Value); }
public void PersonEdit() { // Arrange PersonController controller = new PersonController(); // Act RedirectToRouteResult routeResult = controller.Edit(new Models.Person { PersonID = testPersonID, FirstName = "Firstname_Updated", MiddleName = "Middlename", LastName = "LastName" }) as RedirectToRouteResult; // Assert Assert.IsNotNull(routeResult); Assert.AreEqual(routeResult.RouteValues["action"], "Details"); Models.Person person = controller.GetPerson(testPersonID); Assert.AreEqual("Firstname_Updated", person.FirstName); }
public void edit_get_returns_person() { //Arrange var pp = new Machete.Web.ViewModel.Person(); map.Setup(x => x.Map <Domain.Person, Machete.Web.ViewModel.Person>(It.IsAny <Domain.Person>())) .Returns(pp); _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, def.Object, map.Object); //Act var result = (PartialViewResult)_ctrlr.Edit(testid); //Assert Assert.IsInstanceOfType(result.ViewData.Model, typeof(Web.ViewModel.Person)); }
public void TestEditPersonMoq() { Person person = new Person(); person.imie = "Basia"; person.nazwisko = "Kowalska"; person.personId = 5; Mock <IPersonSharingContext> context = new Mock <IPersonSharingContext>(); context.Setup(x => x.FindPersonById(2)).Returns(person); context.Setup(x => x.SaveChanges()).Returns(0); var controller = new PersonController(context.Object); person.personId = 2; var result = controller.Edit(person) as RedirectToRouteResult; Assert.AreEqual("All", result.RouteValues["Action"]); Assert.AreEqual("Person", result.RouteValues["Controller"]); }
public void Edit_Returns_ViewResult() { // Arrange var entity = GetPersonEntity(); var mockRepo = new Mock <IPersonRepository>(); mockRepo.Setup(repo => repo.GetById(entity.Id)).Returns(entity); var controller = new PersonController(mockRepo.Object, CreateMapper()); // Act var result = controller.Edit(entity.Id); // Assert var viewResult = Assert.IsType <ViewResult>(result); var model = Assert.IsAssignableFrom <Person>(viewResult.ViewData.Model); Assert.Equal(entity.Id, model.Id); Assert.Equal(entity.Code, model.Code); Assert.Equal(entity.Name, model.Name); }
public void TestEditHttp() { var context = new FakePersonSharingContext(); context.Persons = new[] { new Person { personId = 1, imie = "Kasia", nazwisko = "Kowalska", pesel = "56457866", adresId = 1 }, new Person { personId = 2, imie = "Basia", nazwisko = "Kowalska", pesel = "56457867", adresId = 2 }, new Person { personId = 3, imie = "Masia", nazwisko = "Kowalska", pesel = "56457868", adresId = 3 } }.AsQueryable(); var controller = new PersonController(context); var result = controller.Edit(25); Assert.AreEqual(typeof(HttpNotFoundResult), result.GetType()); }
public void edit_post_invalid_throws_exception() { //Arrange var person = new Person(); int testid = 12345; // // Mock service and setup SavePerson mock _serv.Setup(p => p.Save(person, "UnitTest")); _serv.Setup(p => p.Get(testid)).Returns(person); // // Mock HttpContext so that ModelState and FormCollection work fakeform.Remove("firstname1"); _ctrlr.ValueProvider = fakeform.ToValueProvider(); // //Act _ctrlr.Edit(testid, "UnitTest"); //Assert //IDictionary<string, object> data = new RouteValueDictionary(result.Data); //Assert.AreEqual("Controller UpdateModel failure on recordtype: person", data["status"]); }
public void 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, def.Object, map.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 async Task Edit_EditViewPersonWithPhotos() { // Arrange var dbContext = serviceProvider.GetRequiredService <StoreDbContext>(); CreateTestPersonWithPhotos(dbContext); var controller = new PersonController(dbContext); // Act var result = await controller.Edit(1); // Assert var viewResult = Assert.IsType <ViewResult>(result); Assert.Null(viewResult.ViewName); Assert.NotNull(viewResult.ViewData); var viewModel = Assert.IsType <PersonViewModel>(viewResult.ViewData.Model); Assert.Equal(1, viewModel.Id); Assert.Equal(4, viewModel.PhotosList.Count); }
public void EditTest() { long id = 1; var um = new FakeUserManager(); Mock <IUnitOfWork> uow = new Mock <IUnitOfWork>(); uow.Setup(x => x.PersonRepository.GetAll()).Returns(_fakePersons); uow.Setup(x => x.PersonRepository.GetByKey(id)).Returns(_fakePersons.Where(x => x.Id == id).FirstOrDefault()); uow.Setup(x => x.FileRepository.Delete(1)); uow.Setup(x => x.PersonRoleRepository.GetAll()).Returns(new List <PersonRole>() { new PersonRole() { Id = 1, PersonId = 1, FilmRoleId = 1, FilmId = 1 } }); uow.Setup(x => x.FilmRoleRepository.GetAll()).Returns(new List <FilmRole>() { new FilmRole() { Id = 1, Name = "role" } }); uow.Setup(x => x.FilmRepository.GetByKey(id)).Returns(new Film() { Id = id, Title = "title" }); uow.Setup(x => x.FileRepository.GetByKey(id)).Returns(new Models.File()); Mock <IHostingEnvironment> env = new Mock <IHostingEnvironment>(); PersonService ps = new PersonService(uow.Object); PersonController PC = new PersonController(uow.Object, env.Object, ps, um); Directory.CreateDirectory("D:\\storage\\1"); using (StreamWriter SW = new StreamWriter("D:\\storage\\0\\anonym.jpg")) { SW.Write("smth"); } var result = PC.Edit(id) as ViewResult; result.Model.Should().NotBeNull(); //////////////////////////////////////// var fileMock = new Mock <IFormFile>(); var physicalFile = new FileInfo("filePath"); var ms = new MemoryStream(); var fileName = physicalFile.Name; //Setup mock file using info from physical file fileMock.Setup(_ => _.FileName).Returns(fileName); fileMock.Setup(_ => _.Length).Returns(ms.Length); fileMock.Setup(_ => _.OpenReadStream()).Returns(ms); fileMock.Setup(_ => _.ContentDisposition).Returns(string.Format("inline; filename={0}", fileName)); //////////////////////////////////////// PersonViewModel pvm = new PersonViewModel() { Id = id, Name = "name", Surname = "surname", BirthDate = DateTime.Today, Country = "Ukraine", Photo = fileMock.Object }; var result2 = PC.Edit(pvm) as ViewResult; uow.Verify(x => x.Save()); }
public void Should_return_404_after_get_to_edit_with_invalid_id() { _controller.Edit(0).AssertHttpStatusReturned(404); }
public void EditGET_GivenPatientId_DefaultViewShouldBeReturned() { var result = _personController.Edit(A <Guid> ._) as ViewResult; result.ViewName.Should().BeEmpty(); }