public void CreatePOST_GivenValidModel_PatientCommandShouldBeBuilt() { var model = new CreatePatientViewModel(); _personController.Create(model); A.CallTo(() => _patientBuilder.BuildAddPatientCommand(model)).MustHaveHappened(Repeated.Exactly.Once); }
public void Should_ReturnStatusCode201Created_When_CreatingPersonForFirstTime() { // Arrange var person = new PersonFake(); // Action var httpStatusCode = _personController.Create(person); // Assert Assert.AreEqual(StatusCodes.Status201Created, httpStatusCode); }
public async Task create_get_returns_person() { //Arrange //Act var result = await _controller.Create() as PartialViewResult; //Assert Assert.IsNotNull(result); Assert.IsInstanceOfType(result.ViewData.Model, typeof(ViewModel.Person)); }
public void Should_render_edit_view_after_get_to_create() { // Arrange // Act var viewResult = _controller.Create() as ViewResult; // Assert Assert.That(viewResult, Is.Not.Null, "Controller returned view"); Assert.That(viewResult.ViewName, Is.EqualTo("Edit"), "View was Edit"); }
public void Create_BadRequest() { var input = PersonFixtures.Input(); var failedState = new ModelStateDictionary(); failedState.AddModelError("name", "invalid"); validator.Setup(x => x.Validate(input)).Returns(failedState); var response = controller.Create(input); Assert.IsInstanceOf(typeof(BadRequestResult), response); }
public void create_get_returns_person() { //Arrange var p = new Machete.Web.ViewModel.Person(); map.Setup(x => x.Map <Domain.Person, Machete.Web.ViewModel.Person>(It.IsAny <Domain.Person>())) .Returns(p); //Act var result = (PartialViewResult)_ctrlr.Create(); //Assert Assert.IsInstanceOfType(result.ViewData.Model, typeof(Web.ViewModel.Person)); }
public void personAddTest() { var options = new DbContextOptionsBuilder <DatabaseContext>() .UseInMemoryDatabase("person_db") .Options; var context = new DatabaseContext(options); // Arrange var controller = new PersonController(new PersonService(context)); var newPerson = new Person { id = "60", firstname = "Selma", lastname = "Bolatbas", }; // Act var result = controller.Create(newPerson); // Assert var okResult = result.Should().BeOfType <CreatedAtActionResult>().Subject; var person = okResult.Value.Should().BeAssignableTo <Person>().Subject; person.id.Should().Be("61"); }
public async Task GivenGroupsExistInDB_WhenCreateActionIsCalled_ThenViewModelHasGroupsInCreateView() { //Arrange _personRepository.Setup(x => x.GetAllGroups()).ReturnsAsync(new List<GroupEntity> { new GroupEntity { Id = 1, Name = "Group A" }, new GroupEntity { Id = 2, Name = "Group B" } }); var controller = new PersonController(_logger.Object, _personRepository.Object); //Act var result = await controller.Create(); //Assert Assert.IsInstanceOf<ViewResult>(result); var viewResult = (ViewResult)result; var model = (CreateViewModel)viewResult.ViewData.Model; Assert.AreEqual(2, model.Group.Count()); }
public MainWindow() { InitializeComponent(); _controller = new PersonController(); _controller.Create(); DataContext = _controller.ViewModel; }
public void GetCreateShouldReturnView() { var controller = new PersonController(); var result = controller.Create(); Assert.IsInstanceOfType(result, typeof(ViewResult)); }
public void Create() { var um = new FakeUserManager(); Mock <IUnitOfWork> uow = new Mock <IUnitOfWork>(); uow.Setup(x => x.PersonRepository.GetAll()).Returns(_fakePersons); uow.Setup(x => x.FileRepository.Add(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); var fileMock = new Mock <IFormFile>(); var content = "Hello World from a Fake File"; var fileName = "test.pdf"; var ms = new MemoryStream(); var writer = new StreamWriter(ms); writer.Write(content); writer.Flush(); ms.Position = 0; fileMock.Setup(_ => _.OpenReadStream()).Returns(ms); fileMock.Setup(_ => _.FileName).Returns(fileName); fileMock.Setup(_ => _.Length).Returns(ms.Length); PersonViewModel pvm = new PersonViewModel() { BirthDate = DateTime.Today, Id = 3, Country = "Ukraine", Name = "Lag", Surname = "Do", Photo = fileMock.Object }; var result = pc.Create(pvm) as ViewResult; uow.Verify(x => x.Save()); //Should not be in the same UNIT(!) test var result2 = pc.Create() as ViewResult; result2.Should().NotBeNull(); }
public void CreateViewModelNotNull() { var mock = new Mock <IService>(); var controller = new PersonController(mock.Object); var result = controller.Create() as ViewResult; Assert.IsNotNull(result); Assert.AreEqual("Edit", result.ViewName); }
public void PersonController_Create() { // Arrange PersonController controller = new PersonController(); // Act ViewResult result = controller.Create() as ViewResult; // Assert Assert.IsNotNull(result); }
public void Person_Get_Country_DropDown() { // Arrange // Act ViewResult result = objController.Create() as ViewResult; // Assert // Assert.AreEqual(null, result.ViewBag.CountryId); Assert.IsNull(result.ViewBag.CountryId); }
public void Create_Returns_ViewResult() { // Arrange var mockRepo = new Mock <IPersonRepository>(); var controller = new PersonController(mockRepo.Object, CreateMapper()); // Act var result = controller.Create(); // Assert Assert.IsType <ViewResult>(result); }
public void PersonController_CreateWithViewModelUpdate() { // Arrange PersonController controller = new PersonController(); PersonViewModel viewModel = new PersonViewModel(); // Act // viewModel is null - will redirect to error page var result = (RedirectToRouteResult)controller.Create(viewModel); // Assert Assert.IsTrue(result.RouteValues["action"].ToString() == "FatalError"); }
public void TestAdd() { var result = _controller.Create(null).GetAwaiter().GetResult().Result; Assert.IsInstanceOfType(result, typeof(BadRequestObjectResult)); var person = new Person { FirstName = "Joe", LastName = "Smith", BirthDate = new DateTime(1977, 3, 27), StreetAddress = "111 Main Steet", City = "Chicago", State = "IL", ZipCode = "60606", Interests = new List <Interest>() { new Interest { Id = 1, Name = "Fishing" } } }; result = _controller.Create(person).GetAwaiter().GetResult().Result; Assert.IsInstanceOfType(result, typeof(OkObjectResult)); result = _controller.Get().Result; var value = (result as OkObjectResult).Value as IEnumerable <Person>; Assert.AreEqual(value.Count(), 3); result = _controller.Get("Smith").Result; value = (result as OkObjectResult).Value as IEnumerable <Person>; Assert.AreEqual(value.Count(), 1); }
public void CreatePost_Returns_RedirectToActionResult() { // Arrange var mockRepo = new Mock <IPersonRepository>(); var controller = new PersonController(mockRepo.Object, CreateMapper()); // Act var result = controller.Create(CreateModel()); // Assert var redirectToActionResult = Assert.IsType <RedirectToActionResult>(result); Assert.Null(redirectToActionResult.ControllerName); Assert.Equal(nameof(controller.Index), redirectToActionResult.ActionName); }
public void CreatePost_Returns_BadRequestResult() { // Arrange var mockRepo = new Mock <IPersonRepository>(); var controller = new PersonController(mockRepo.Object, CreateMapper()); controller.ModelState.AddModelError("Code", "Required"); // Act var result = controller.Create(CreateModel()); // Assert var badRequestResult = Assert.IsType <BadRequestObjectResult>(result); Assert.IsType <SerializableError>(badRequestResult.Value); }
public void PersonCreate() { // Arrange PersonController controller = new PersonController(); // Act RedirectToRouteResult routeResult = controller.Create(new Models.Person { PersonID = 999999999, FirstName = "Firstname", MiddleName = "Middlename", LastName = "LastName" }) as RedirectToRouteResult; // Assert Assert.IsNotNull(routeResult); Assert.AreEqual(routeResult.RouteValues["action"], "Details"); // Save person id for future tests testPersonID = System.Convert.ToInt16(routeResult.RouteValues["id"]); }
public async Task GivenNewPersonIsTobeAdded_WhenModelStateIsValidAndAllInoutsAreOk_ThenReirectToIndexPage() { //Arrange var createModel = new CreateViewModel { PersonName = "PName", DateAdded = DateTime.Today.AddDays(-20), SelectedGroupId = "1" }; var controller = new PersonController(_logger.Object, _personRepository.Object); //Act var result = await controller.Create(createModel); //Assert Assert.IsInstanceOf<RedirectToActionResult>(result); Assert.AreEqual("Index", ((RedirectToActionResult)result).ActionName); }
public async Task Create_ShouldAddTheProvidedPerson() { // arrange Person person = new Person { FirstName = "Andrew", LastName = "Armstrong" }; dataService.Setup(ds => ds.Add(It.IsAny <Person>())).ReturnsAsync(person); PersonController controller = new PersonController(dataService.Object); // act var actionResult = await controller.Create(person) as CreatedAtActionResult; var createdPerson = actionResult.Value as Person; // assert Assert.IsNotNull(actionResult); Assert.AreEqual((int)HttpStatusCode.Created, actionResult.StatusCode); Assert.AreEqual(person, createdPerson); }
public async Task GivenNewPersonIsTobeAdded_WhenModelStateIsInValid_ThenStayOnCreatePage() { //Arrange var createModel = new CreateViewModel { PersonName = "PName", DateAdded = DateTime.Today.AddDays(-20), SelectedGroupId = "1" }; var controller = new PersonController(_logger.Object, _personRepository.Object); controller.ModelState.AddModelError("some", "error"); //Act var result = await controller.Create(createModel); //Assert Assert.IsInstanceOf<ViewResult>(result); var viewResult = (ViewResult)result; var model = (CreateViewModel)viewResult.ViewData.Model; Assert.AreEqual(2, model.Group.Count()); }
public void Create() { var memoryStore = new List <Person>(); Person personStub = new Person { Id = 1 }; var mock = new Mock <IRepository <Person> >(); mock.Setup(repo => repo.GetAll()).Returns(memoryStore.AsQueryable()); mock.Setup(repo => repo.Create(It.IsAny <Person>())).Returns((Person person) => { person.Id = 1; memoryStore.Add(person); return(person); }); var factoryMock = new Mock <IRepositoryFactory>(); factoryMock.Setup(f => f.GetRepository <Person>()).Returns(mock.Object); _personController = new PersonController(factoryMock.Object); var emptyJson = _personController.GetAll(); Assert.IsNotNull(emptyJson); var emptyStore = emptyJson.Value as List <Person>; Assert.IsNotNull(emptyStore); Assert.AreEqual(emptyStore.Count, 0); var json = _personController.Create(personStub); Assert.IsNotNull(json); var result = json.Value as Person; Assert.NotNull(result); Assert.AreEqual(result.Id, 1); Assert.AreEqual(result.Address, personStub.Address); var notEmptyJson = _personController.GetAll(); Assert.IsNotNull(notEmptyJson); var notEmptyStore = notEmptyJson.Value as List <Person>; Assert.IsNotNull(notEmptyStore); Assert.AreEqual(notEmptyStore.Count, 1); }
public async void Create_Errors() { PersonControllerMockFacade mock = new PersonControllerMockFacade(); var mockResponse = new Mock <CreateResponse <ApiPersonServerResponseModel> >(null as ApiPersonServerResponseModel); var mockRecord = new ApiPersonServerResponseModel(); mockResponse.SetupGet(x => x.Success).Returns(false); mock.ServiceMock.Setup(x => x.Create(It.IsAny <ApiPersonServerRequestModel>())).Returns(Task.FromResult <CreateResponse <ApiPersonServerResponseModel> >(mockResponse.Object)); PersonController controller = new PersonController(mock.ApiSettingsMoc.Object, mock.LoggerMock.Object, mock.TransactionCoordinatorMock.Object, mock.ServiceMock.Object, mock.ModelMapperMock.Object); controller.ControllerContext = new ControllerContext(); controller.ControllerContext.HttpContext = new DefaultHttpContext(); IActionResult response = await controller.Create(new ApiPersonServerRequestModel()); response.Should().BeOfType <ObjectResult>(); (response as ObjectResult).StatusCode.Should().Be((int)HttpStatusCode.UnprocessableEntity); mock.ServiceMock.Verify(x => x.Create(It.IsAny <ApiPersonServerRequestModel>())); }
public async void Create_No_Errors() { PersonControllerMockFacade mock = new PersonControllerMockFacade(); var mockResponse = ValidationResponseFactory <ApiPersonServerResponseModel> .CreateResponse(null as ApiPersonServerResponseModel); mockResponse.SetRecord(new ApiPersonServerResponseModel()); mock.ServiceMock.Setup(x => x.Create(It.IsAny <ApiPersonServerRequestModel>())).Returns(Task.FromResult <CreateResponse <ApiPersonServerResponseModel> >(mockResponse)); PersonController controller = new PersonController(mock.ApiSettingsMoc.Object, mock.LoggerMock.Object, mock.TransactionCoordinatorMock.Object, mock.ServiceMock.Object, mock.ModelMapperMock.Object); controller.ControllerContext = new ControllerContext(); controller.ControllerContext.HttpContext = new DefaultHttpContext(); IActionResult response = await controller.Create(new ApiPersonServerRequestModel()); response.Should().BeOfType <CreatedResult>(); (response as CreatedResult).StatusCode.Should().Be((int)HttpStatusCode.Created); var createResponse = (response as CreatedResult).Value as CreateResponse <ApiPersonServerResponseModel>; createResponse.Record.Should().NotBeNull(); mock.ServiceMock.Verify(x => x.Create(It.IsAny <ApiPersonServerRequestModel>())); }
public void CreateTest() { var options = CreateNewContextOptions(); // Run the test against one instance of the context using (var context = new ModelDbContext(options)) { PersonViewModelSave PVmodel = new PersonViewModelSave(); PVmodel.PersonNummer = "12345"; PVmodel.ForNamn = "Per"; PVmodel.EfterNamn = "Nilsson"; PersonCode pc = new PersonCode(context); PersonCreateUpdateDeleteFake crudFake = new PersonCreateUpdateDeleteFake(); PersonController controller = new PersonController(context, crudFake); var response = controller.Create(PVmodel); Assert.True(response.success == "true"); } }
private PersonController GetControllerAndAssert(bool createIfNotFound) { PersonController controller; if(!ScenarioContext.Current.TryGetValue(PersonControllerKey, out controller) && createIfNotFound) { controller = new PersonController(); controller.Create(); ScenarioContext.Current[PersonControllerKey] = controller; } Assert.IsNotNull(controller, "Controller was not created successfully"); return controller; }
public void Should_render_edit_view_after_get_to_create() { _controller.Create().ShouldRenderView("Edit"); }
public void Should_render_edit_view_after_get_to_create() { _controller.Create().AssertViewRendered().ForView("Edit"); }