public void InsertUpdateDelete() { PositionController positionController = new PositionController(); //create new entity Position position = new Position(); position.positionId = Guid.NewGuid(); position.committeeId = Guid.NewGuid(); position.parentPositionId = Guid.NewGuid(); position.name = "Test Name"; position.jobDescription = "Test description"; position.entryDate = DateTime.Now; position.appUserId = Guid.NewGuid(); position.modifiedDate = DateTime.Now; position.remark = "Test Remark"; //insert var result1 = positionController.Post(position); //update var result2 = positionController.Post(position); //delete var result3 = positionController.Delete(position.positionId); //assert Assert.IsNotNull(result1); Assert.IsNotNull(result2); Assert.IsNotNull(result3); Assert.IsTrue(result1 is OkResult); Assert.IsTrue(result2 is OkResult); Assert.IsTrue(result3 is OkResult); }
public void CangetDeletePosition_ReturnPartialView() { positionService.Setup(c => c.GetPosition(It.IsAny <int>())) .Returns((int i) => ListPositions.FirstOrDefault(c => c.Id == i)); positionController = new PositionController(positionService.Object); var result = positionController.Delete(1) as PartialViewResult; Assert.IsNotNull(result); Assert.AreEqual(1, positionController.ViewBag.Id); }
public void DeleteGet_ValidPositionWithAssociatedDate_CannotDelete() { // Arrange - create the controller PositionController target = new PositionController(mock.Object); // Act - call the action method var result = target.Delete(4); // Assert - check the result Assert.AreEqual("CannotDelete", ((ViewResult)result).ViewName); Assert.IsInstanceOf(typeof(ViewResult), result); }
public void DeleteGet_InvalidPosition() { // Arrange - create the controller PositionController target = new PositionController(mock.Object); // Act - call the action method var result = target.Delete(150); Position position = mock.Object.Positions.Where(m => m.PositionID == 150).FirstOrDefault(); // Assert - check the result Assert.IsInstanceOf(typeof(HttpNotFoundResult), result); Assert.IsNull(position); Assert.AreEqual(404, ((HttpNotFoundResult)result).StatusCode); }
public void Delete_Removes_Position() { var PositionId = 1; var deletedPosition = new Position(1, "Name", "image"); var PositionList = new List <Position>() { deletedPosition, new Position(1, "Name", "image") }; PositionRepo.GetById(PositionId).Returns(deletedPosition); PositionRepo.When(d => d.Delete(deletedPosition)) .Do(d => PositionList.Remove(deletedPosition)); PositionRepo.GetAll().Returns(PositionList); var result = underTest.Delete(PositionId); Assert.DoesNotContain(deletedPosition, result); /*Does not work in all cases*/ //Assert.All(result, item => Assert.Contains("Second item", item.Name)); }