public void Unit_Test_Details() { #region Arrange Part Mock <IBusinessDataAccount> todoMock = new Mock <IBusinessDataAccount>(); List <ToDoModel> mockToDoModel = new List <ToDoModel>(); mockToDoModel.Add(new ToDoModel { ID = 1, TaskName = "Test Task 1", TaskDescription = "Test Task 1 Description", Username = "******", IsDone = false }); mockToDoModel.Add(new ToDoModel { ID = 2, TaskName = "Test Task 2", TaskDescription = "Test Task 2 Description", Username = "******", IsDone = false }); todoMock.Setup(m => m.Details("Test1")).Returns(mockToDoModel); ToDosController testController = new ToDosController(todoMock.Object); #endregion #region Act Part var actual = testController.Details() as ViewResult; #endregion #region Assert Part Assert.IsInstanceOfType(actual.Model, typeof(List <ToDoModel>)); #endregion }
public async Task ShouldHavePassWhenDeleteModelStateIsValidAndReturnOkAsync() { //arrange var controller = new ToDosController(_itemToDoRepository.Object); //actual var result = await controller.DeleteAsync(_firstItem.Id); //assert Assert.IsInstanceOf <OkResult>(result); }
public async Task ShouldHaveNotPassWhenGetIsInValidAndReturnNotFoundAsync() { //arrange var controller = new ToDosController(_itemToDoRepository.Object); //actual var result = await controller.GetAsync(Guid.Parse("74a1eedc-0719-408c-8c07-1bee8c2dd0b1")); //assert Assert.IsInstanceOf <NotFoundResult>(result); }
public async Task ShouldHaveNotPassWhenPostModelStateIsInValidAndReturnBadRequestAsync() { //arrange var controller = new ToDosController(_itemToDoRepository.Object); controller.ModelState.AddModelError("error", "some error"); //actual var result = await controller.PostAsync(null); //assert Assert.IsInstanceOf <BadRequestObjectResult>(result); }
public void Get() { // Arrange ToDosController controller = new ToDosController(); // Act var result = controller.GetToDos() as OkNegotiatedContentResult <List <ToDo> >; // Assert Assert.IsNotNull(result); Assert.IsNotNull(result.Content); Assert.IsTrue(result.Content.Count == 2); }
public void Unit_Test_CreateModal() { #region Arrange Part Mock <IBusinessDataAccount> todoMock = new Mock <IBusinessDataAccount>(); ToDosController testController = new ToDosController(todoMock.Object); #endregion #region Act Part var actual = (PartialViewResult)testController.CreateModal(); #endregion #region Assert Part Assert.AreEqual("_CreateTaskModal", actual.ViewName); #endregion }
public void Unit_Test_MarkAsCompleted() { #region Arrange Part Mock <IBusinessDataAccount> todoMock = new Mock <IBusinessDataAccount>(); todoMock.Setup(m => m.MarkAsCompleted(1, "Test1")).Returns(1); ToDosController testController = new ToDosController(todoMock.Object); #endregion #region Act Part var actual = testController.MarkAsCompleted(1) as EmptyResult; #endregion #region Assert Part Assert.IsInstanceOfType(actual, typeof(EmptyResult)); #endregion }
public void Post() { // Arrange ToDosController controller = new ToDosController(); var todo = new ToDo { Title = "Learn Testing", DueDate = DateTime.Now, Priority = 2, MinutesSpent = 10, }; // Act var createdTodo = controller.PostToDo(todo) as CreatedAtRouteNegotiatedContentResult <ToDo>; // Assert Assert.IsNotNull(createdTodo); Assert.IsNotNull(createdTodo.Content); Assert.IsTrue(createdTodo.Content.Id > 0); Assert.AreEqual(createdTodo.Content.Title, todo.Title); }
public async Task ShouldHavePassWhenPostModelStateIsValidAndReturnOkAsync() { //arrange var controller = new ToDosController(_itemToDoRepository.Object); var command = new CreateToDoCommand("Hello world!"); //actual var result = await controller.PostAsync(command); //assert Assert.IsInstanceOf <OkObjectResult>(result); var response = result as OkObjectResult; Assert.IsInstanceOf <CreateToDoCommand>(response.Value); var model = response.Value as CreateToDoCommand; Assert.AreEqual(command.Name, model.Name); }
public async Task ShouldHavePassWhenGetIsValidAndReturnOkAsync() { //arrange _itemToDoRepository.Setup(repo => repo.GetAsync(_firstItem.Id)) .ReturnsAsync(_items.FirstOrDefault(x => x.Id == _firstItem.Id)); var controller = new ToDosController(_itemToDoRepository.Object); //actual var result = await controller.GetAsync(_firstItem.Id); //assert Assert.IsInstanceOf <OkObjectResult>(result); var response = result as OkObjectResult; Assert.IsInstanceOf <ItemToDoModel>(response.Value); var model = response.Value as ItemToDoModel; Assert.AreEqual(_firstItem.Id, model.Id); }
public async Task ShouldHavePassWhenBrowsIsValidAndReturnOkAsync() { //arrange _itemToDoRepository.Setup(repo => repo.BrowsAsync()) .ReturnsAsync(_items); var controller = new ToDosController(_itemToDoRepository.Object); //actual var result = await controller.GetAsync(); //assert Assert.IsInstanceOf <OkObjectResult>(result); var response = result as OkObjectResult; Assert.IsInstanceOf <IEnumerable <ItemToDoModel> >(response.Value); var model = response.Value as IEnumerable <ItemToDoModel>; Assert.IsTrue(model.Any(x => _items.Select(m => m.Id).Contains(x.Id))); }
async Task Run() { todoCtrl = new ToDosController(); catCtrl = new CategoriesController(); Cli.DisplayLine("Todo Application"); var option = DisplayMenu(); while (option != 0) { switch (option) { case 1: await ListAllToDos(); break; case 2: await CreateToDo(); break; case 3: await UpdateTodo(); break; case 0: return; default: Cli.DisplayLine("Invalid menu option"); break; } option = DisplayMenu(); } }
public void Unit_Test_SaveNewTask() { #region Arrange Part Mock <IBusinessDataAccount> todoMock = new Mock <IBusinessDataAccount>(); ToDoModel mockToDoModel = new ToDoModel { TaskName = "Test Task 1", TaskDescription = "Test Task 1 Description", Username = "******" }; todoMock.Setup(m => m.SaveNewTask(mockToDoModel)).Returns(mockToDoModel); ToDosController testController = new ToDosController(todoMock.Object); #endregion #region Act Part var actual = testController.SaveNewTask(mockToDoModel) as PartialViewResult; #endregion #region Assert Part Assert.AreEqual("_SaveTask", actual.ViewName); #endregion }
public ToDoTest(ToDoDbContext context) { _todoRepo = new ToDosRepo(context); _todoController = new ToDosController(context); }